Hello
Just done some googling and couldn't find any in pascal. Therefore, I ported a code from Java found here:
http://www.cs.princeton.edu/courses/archive/fall12/cos126/assignments/StdGaussian.java.htmlThis is how the ported code looks like:
// returns a random gaussivan value. This implementation is inspired on:
//http://www.cs.princeton.edu/courses/archive/fall12/cos126/assignments/StdGaussian.java.html
function TVolume.RandomGaussianValue: TNeuralFloat;
var
r, x, y: TNeuralFloat;
begin
r := 0;
// loop executed 4 / pi = 1.273.. times on average
while ( (r > 1) or (r = 0) ) do
begin
// find a uniform random point (x, y) inside unit circle
x := 2.0 * Random() - 1.0;
y := 2.0 * Random() - 1.0;
r := x*x + y*y;
end;
RandomGaussianValue := x * Sqrt(-2.0 * Ln(r) / r);
end;
procedure TVolume.RandomizeGaussian(pMul: TNeuralFloat = 1.0);
var
I: integer;
vHigh: integer;
begin
vHigh := High(FData);
for I := 0 to vHigh do
FData[I] := RandomGaussianValue() * pMul;
end;
procedure TVolume.AddGaussianNoise(pMul: TNeuralFloat);
var
I: integer;
vHigh: integer;
begin
vHigh := High(FData);
for I := 0 to vHigh do
FData[I] += RandomGaussianValue() * pMul;
end;
This is how it can be tested:
T2 := TNNetVolume.Create(550,1,1);
T2.RandomizeGaussian();
WriteLn('Gaussian Avg:',T2.GetAvg());
WriteLn('Gaussian Variance:',T2.GetVariance());
The source code is maintained here:
https://sourceforge.net/p/cai/svncode/HEAD/tree/trunk/lazarus/libs/uvolume.pas Wish everyone happy coding