⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 randmaker.cpp

📁 神经网络中的无监督学习中的SOM学习算法
💻 CPP
字号:
#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>
#include <math.h>
#include "RandMaker.h"

#define PI 3.1415926535897932384626433832795

void RandMaker::RandInit()
{
    srand(GetTickCount());
}

double RandMaker::AverageRand(double min, double max)
{
    const double precise = 10000.0;
    int minInteger = (int)(min*precise);
    int maxInteger = (int)(max*precise);
    int randInteger = rand() * rand();
    int diffInteger = maxInteger - minInteger;
    int resultInteger = randInteger % diffInteger + minInteger;

    return resultInteger / precise;
}

static double Normal(double x, double miu, double sigma)
{
    return 1 / (sqrt(2 * PI) * sigma) * exp(-(x - miu) * (x - miu) / (2 * sigma * sigma));
}

/* the pfn means the density of the random number */
double RandMaker::NormalRand(double min, double max, double miu, double sigma)
{
    double x, y, dScope;

    do 
    {
        x = AverageRand(min, max);
        y = Normal(x, miu, sigma);
        dScope = AverageRand(0, Normal(miu, miu, sigma));
    } while(dScope > y);

    return x;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -