- changed noise API

- noise initialized with help of clock()


git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@33 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2014-10-19 20:28:36 +00:00
parent d0243820d6
commit 0f38b78093
4 changed files with 15 additions and 14 deletions
+8 -7
View File
@@ -45,26 +45,28 @@ double ran0(long *idum)
// --------------------------------------------------------------
void Noise_Init(noise_gen_t *pObj, long seed)
{
pObj->state = seed;
pObj->state = seed ^ clock();
}
void Noise_Free(noise_gen_t *pObj)
{
}
double Noise_Uniform(noise_gen_t *pObj, double mu)
// 0 .. 1
double Noise_Uniform(noise_gen_t *pObj)
{
return ran0(&pObj->state) + mu -0.5;
return ran0(&pObj->state);
}
double Noise_Gaussian(noise_gen_t *pObj, double mu, double sigma)
double Noise_Gaussian(noise_gen_t *pObj)
{
double U1, U2, V1, V2, S, Y;
do
{
U1 = Noise_Uniform(pObj, 0.5); // U1=[0,1]
U2 = Noise_Uniform(pObj, 0.5); // U2=[0,1]
U1 = Noise_Uniform(pObj); // U1=[0,1]
U2 = Noise_Uniform(pObj); // U2=[0,1]
V1 = 2 * U1 - 1; // V1=[-1,1]
V2 = 2 * U2 - 1; // V2=[-1,1]
S = V1 * V1 + V2 * V2;
@@ -73,7 +75,6 @@ double Noise_Gaussian(noise_gen_t *pObj, double mu, double sigma)
// X = sqrt(-2 * log(S) / S) * V1;
Y = sqrt(-2 * log(S) / S) * V2;
Y = mu + sigma*Y;
return Y;
}