LibRan  0.1
Pseudo-random number distribution generator
Functions | Variables
LRgsn.c File Reference

The gaussian-like distributions based on the Central Limit Theorem. More...

#include <math.h>
#include "libran.h"
Include dependency graph for LRgsn.c:

Go to the source code of this file.

Functions

double LRd_gsn2_RAN (LR_obj *o)
 LRd_gsn2_RAN(LR_obj *o) - double random g2 gaussian-like (saw tooth) distribution. More...
 
double LRd_gsn2_PDF (LR_obj *o, double x)
 LRd_gsn2_PDF(LR_obj *o, double x) - double gaussian-like (saw tooth) probablity distribution function. More...
 
double LRd_gsn2_CDF (LR_obj *o, double x)
 LRd_gsn2_CDF(LR_obj *o, double x) - double gaussian-like (saw tooth) cumulative distribution function. More...
 
float LRf_gsn2_RAN (LR_obj *o)
 LRf_gsn2_RAN(LR_obj *o) - float random g2 gaussian-like (saw tooth) distribution. More...
 
float LRf_gsn2_PDF (LR_obj *o, float x)
 LRf_gsn2_PDF(LR_obj *o, float x) - float gaussian-like (saw tooth) probablity distribution function. More...
 
float LRf_gsn2_CDF (LR_obj *o, float x)
 LRf_gsn2_CDF(LR_obj *o, float x) - float gaussian-like (saw tooth) cumulative distribution function. More...
 
int gs4initd (void)
 
int gs4initf (void)
 
double LRd_gsn4_RAN (LR_obj *o)
 LRd_gsn4_RAN(LR_obj *o) - double random g4 gaussian-like (simple bell curve) distribution. More...
 
double LRd_gsn4_PDF (LR_obj *o, double x)
 LRd_gsn4_PDF(LR_obj *o, double x) - double gaussian-like (simple bell curve) probablity distribution function. More...
 
double LRd_gsn4_CDF (LR_obj *o, double x)
 LRd_gsn4_CDF(LR_obj *o, double x) - double gaussian-like (saw tooth) cumulative distribution function. More...
 
float LRf_gsn4_RAN (LR_obj *o)
 LRf_gsn4_RAN(LR_obj *o) - float random g4 gaussian-like (simple bell curve) distribution. More...
 
float LRf_gsn4_PDF (LR_obj *o, float x)
 LRf_gsn4_PDF(LR_obj *o, float x) - float gaussian-like (simple bell curve) probablity distribution function. More...
 
float LRf_gsn4_CDF (LR_obj *o, float x)
 LRf_gsn4_CDF(LR_obj *o, float x) - float gaussian-like (saw tooth) cumulative distribution function. More...
 
int gs12initd (void)
 
int gs12initf (void)
 
double LRd_gsn12_RAN (LR_obj *o)
 LRd_gsn12_RAN(LR_obj *o) - double random g12 gaussian-like distribution closely matches a Gaussian/Normal distribution using the sum of 12 uniform random variates. More...
 
double LRd_gsn12_PDF (LR_obj *o, double x)
 LRd_gsn12_PDF(LR_obj *o, double x) - double gaussian-like (simple bell curve) probablity distribution function. More...
 
double LRd_gsn12_CDF (LR_obj *o, double x)
 LRd_gsn12_CDF(LR_obj *o, double x) - double gaussian-like (simple bell curve) cumulative distribution function. More...
 
float LRf_gsn12_RAN (LR_obj *o)
 LRf_gsn12_RAN(LR_obj *o) - float random g12 gaussian-like distribution closely matches a Gaussian/Normal distribution using the sum of 12 uniform random variates. More...
 
float LRf_gsn12_PDF (LR_obj *o, float x)
 LRf_gsn12_PDF(LR_obj *o, float x) - float gaussian-like (simple bell curve) probablity distribution function. More...
 
float LRf_gsn12_CDF (LR_obj *o, float x)
 LRf_gsn12_CDF(LR_obj *o, float x) - float gaussian-like (simple bell curve) cumulative distribution function. More...
 

Variables

int gscdfn4 [5][5]
 
int gscdfd4 [5][5]
 
int gspdfn4 [5][5]
 
int gspdfd4 [5][5]
 
double gspdf4d [5][5]
 
double gscdf4d [5][5]
 
float gspdf4f [5][5]
 
float gscdf4f [5][5]
 
long gscdfn12 [13][13]
 
long gscdfd12 [13][13]
 
long gspdfn12 [13][13]
 
long gspdfd12 [13][13]
 
double gspdf12d [13][13]
 
double gscdf12d [13][13]
 
float gspdf12f [13][13]
 
float gscdf12f [13][13]
 

Detailed Description

The gaussian-like distributions based on the Central Limit Theorem.

Adding two random variates will produce a new CDF which is the convolution of the two individual respective PDFs.

Here we sum some number of uniformly distributed random variates where the uniform random variate has:

\begin{eqnarray*} \mbox{PDF } u(x) &= \left\{ \begin{array}{ll} 0, & x < 0 \mbox{ or } x \ge 1, \\ 1, & 0 \le x < 1 . \end{array} \right. \\ \mbox{CDF } U(x) &= \left\{ \begin{array}{ll} 0, & x < 0 , \\ x, & 0 \le x < 1 , \\ 1, & x \ge 1 . \end{array} \right. \end{eqnarray*}

A more detailed derivation can be found at page 22 of "Non-Uniform Random Variate Generation" by Luc Devroye.

The CDF of $ n $ uniform random variates summed together is

\[ F(x) = \frac{1}{n!} \left[H(x)^n - \left(\begin{array}{c} {n} \\ {1} \end{array}\right) H(x-1)^n + \left(\begin{array}{c} {n} \\ {2} \end{array}\right) H(x-2)^n - \cdots \right] \]

\[ \mbox{where } H(x) = \left\{ \begin{array}{ll} 0, & x < 0 \\ x, & 0 \le x . \end{array} \right. \]

\[ \mbox{and the combination or binomial factor } \left(\begin{array}{c} {n} \\ {m} \end{array}\right) = \frac{n!}{m!(n-m)!} \]

The set of distributions here are by default symmetric and centered on $ x = 0 $ and on an interval $ -n/2 \le x \le n/2 $, where $ n $ is the order or number of summed random variates.

The pseudo-random numbers are distributed from some lower bound "a" upto "b" (on the interval [a,b) ). The medium m = (a+b)/2, and width s = (b - a)/2

The default depends on the distribution.

See also
aux/gsn.c

GSN2

The $ n=2 $ Gaussian-like random variate is just the sum of two uniformly distributed random variates. The resulting PDF is also just a saw tooth in form.

The default values are $ a = -1 $, and $ b = 1 $.

\begin{eqnarray*} \mbox{PDF gsn2}(x) &= \left\{ \begin{array}{ll} 0, & x < -1 \mbox{ or } x \ge 1 , \\ 1 + x, & -1 \le x < 0 , \\ 1 - x, & 0 \le x < 1 . \end{array} \right. \\ \mbox{CDF GSN2}(x) &= \left\{ \begin{array}{ll} 0, & x < -1 , \\ \frac{1}{2}(x+1)^2, & -1 \le x < 0 , \\ -\frac{1}{2}x^2 + x + \frac{1}{2}, & 0 \le x < 1 , \\ 1, & x \ge 1 . \end{array} \right. \end{eqnarray*}

GSN4

The $ n=4 $ Gaussian-like random variate is just the sum of four uniformly distributed random variates. However, the resulting PDF exhibits the behavior of a bell curve with each segment comprised of cubic polynomials and the end points of each segment match the adjacent segments endpoints and are continuous through the second derivative ... just like cubic splines.

The CDF are quartic polynomials where the adjacent segments are continuous through the third derivative.

The default values are $ a = -2 $, and $ b = 2 $.

GSN12

The $ n=12 $ Gaussian-like random variate is of special note. It's the sum of twelve uniformly distributed random variates. This distribution closely approximates the Gaussian or Normal distribution. The variance of the distribution is equal to 1 just like the standard normal distribution, but has definite upper and lower bounds.

The PDF are segments of 11th order polynomials. The CDF are segments of 12th order polynomials. Each of the distribution functions are continuous upto the highest derivative. These distribution functions exactly represent the gsn12 random variate distribution and are not approximations.

The default values are $ m = 0 $ and $ s = 1 $. Note that this distribution uses the mean and deviation to identify the distribution characteristics. It is understood that the lower bound is $ m - s $ and the upper bound is $ m + s $.

See also
LRgaus.c

Definition in file LRgsn.c.

Function Documentation

◆ LRd_gsn12_CDF()

double LRd_gsn12_CDF ( LR_obj o,
double  x 
)

LRd_gsn12_CDF(LR_obj *o, double x) - double gaussian-like (simple bell curve) cumulative distribution function.

Parameters
oLR_obj object
xvalue
Returns
double CDF at x

Definition at line 688 of file LRgsn.c.

◆ LRd_gsn12_PDF()

double LRd_gsn12_PDF ( LR_obj o,
double  x 
)

LRd_gsn12_PDF(LR_obj *o, double x) - double gaussian-like (simple bell curve) probablity distribution function.

Parameters
oLR_obj object
xvalue
Returns
double PDF at x

Definition at line 659 of file LRgsn.c.

◆ LRd_gsn12_RAN()

double LRd_gsn12_RAN ( LR_obj o)

LRd_gsn12_RAN(LR_obj *o) - double random g12 gaussian-like distribution closely matches a Gaussian/Normal distribution using the sum of 12 uniform random variates.

Default: mean m = 0, std.deviation s = 1

Parameters
oLR_obj object
Returns
double

Definition at line 639 of file LRgsn.c.

◆ LRd_gsn2_CDF()

double LRd_gsn2_CDF ( LR_obj o,
double  x 
)

LRd_gsn2_CDF(LR_obj *o, double x) - double gaussian-like (saw tooth) cumulative distribution function.

Parameters
oLR_obj object
xvalue
Returns
double CDF at x

Definition at line 206 of file LRgsn.c.

◆ LRd_gsn2_PDF()

double LRd_gsn2_PDF ( LR_obj o,
double  x 
)

LRd_gsn2_PDF(LR_obj *o, double x) - double gaussian-like (saw tooth) probablity distribution function.

Parameters
oLR_obj object
xvalue
Returns
double PDF at x

Definition at line 183 of file LRgsn.c.

◆ LRd_gsn2_RAN()

double LRd_gsn2_RAN ( LR_obj o)

LRd_gsn2_RAN(LR_obj *o) - double random g2 gaussian-like (saw tooth) distribution.

Default range: [a,b) = [-1,1)

Parameters
oLR_obj object
Returns
double

Definition at line 169 of file LRgsn.c.

◆ LRd_gsn4_CDF()

double LRd_gsn4_CDF ( LR_obj o,
double  x 
)

LRd_gsn4_CDF(LR_obj *o, double x) - double gaussian-like (saw tooth) cumulative distribution function.

Parameters
oLR_obj object
xvalue
Returns
double CDF at x

Definition at line 418 of file LRgsn.c.

◆ LRd_gsn4_PDF()

double LRd_gsn4_PDF ( LR_obj o,
double  x 
)

LRd_gsn4_PDF(LR_obj *o, double x) - double gaussian-like (simple bell curve) probablity distribution function.

Parameters
oLR_obj object
xvalue
Returns
double PDF at x

Definition at line 388 of file LRgsn.c.

◆ LRd_gsn4_RAN()

double LRd_gsn4_RAN ( LR_obj o)

LRd_gsn4_RAN(LR_obj *o) - double random g4 gaussian-like (simple bell curve) distribution.

Default range: [a,b) = [-2,2)

Parameters
oLR_obj object
Returns
double

Definition at line 373 of file LRgsn.c.

◆ LRf_gsn12_CDF()

float LRf_gsn12_CDF ( LR_obj o,
float  x 
)

LRf_gsn12_CDF(LR_obj *o, float x) - float gaussian-like (simple bell curve) cumulative distribution function.

Parameters
oLR_obj object
xvalue
Returns
float CDF at x

Definition at line 770 of file LRgsn.c.

◆ LRf_gsn12_PDF()

float LRf_gsn12_PDF ( LR_obj o,
float  x 
)

LRf_gsn12_PDF(LR_obj *o, float x) - float gaussian-like (simple bell curve) probablity distribution function.

Parameters
oLR_obj object
xvalue
Returns
float PDF at x

Definition at line 741 of file LRgsn.c.

◆ LRf_gsn12_RAN()

float LRf_gsn12_RAN ( LR_obj o)

LRf_gsn12_RAN(LR_obj *o) - float random g12 gaussian-like distribution closely matches a Gaussian/Normal distribution using the sum of 12 uniform random variates.

Default: mean m = 0, std.deviation s = 1

Parameters
oLR_obj object
Returns
float

Definition at line 721 of file LRgsn.c.

◆ LRf_gsn2_CDF()

float LRf_gsn2_CDF ( LR_obj o,
float  x 
)

LRf_gsn2_CDF(LR_obj *o, float x) - float gaussian-like (saw tooth) cumulative distribution function.

Parameters
oLR_obj object
xvalue
Returns
float CDF at x

Definition at line 271 of file LRgsn.c.

◆ LRf_gsn2_PDF()

float LRf_gsn2_PDF ( LR_obj o,
float  x 
)

LRf_gsn2_PDF(LR_obj *o, float x) - float gaussian-like (saw tooth) probablity distribution function.

Parameters
oLR_obj object
xvalue
Returns
float PDF at x

Definition at line 248 of file LRgsn.c.

◆ LRf_gsn2_RAN()

float LRf_gsn2_RAN ( LR_obj o)

LRf_gsn2_RAN(LR_obj *o) - float random g2 gaussian-like (saw tooth) distribution.

Default range: [a,b) = [-1,1)

Parameters
oLR_obj object
Returns
float

Definition at line 234 of file LRgsn.c.

◆ LRf_gsn4_CDF()

float LRf_gsn4_CDF ( LR_obj o,
float  x 
)

LRf_gsn4_CDF(LR_obj *o, float x) - float gaussian-like (saw tooth) cumulative distribution function.

Parameters
oLR_obj object
xvalue
Returns
float CDF at x

Definition at line 496 of file LRgsn.c.

◆ LRf_gsn4_PDF()

float LRf_gsn4_PDF ( LR_obj o,
float  x 
)

LRf_gsn4_PDF(LR_obj *o, float x) - float gaussian-like (simple bell curve) probablity distribution function.

Parameters
oLR_obj object
xvalue
Returns
float PDF at x

Definition at line 466 of file LRgsn.c.

◆ LRf_gsn4_RAN()

float LRf_gsn4_RAN ( LR_obj o)

LRf_gsn4_RAN(LR_obj *o) - float random g4 gaussian-like (simple bell curve) distribution.

Default range: [a,b) = [-2,2)

Parameters
oLR_obj object
Returns
float

Definition at line 451 of file LRgsn.c.

Variable Documentation

◆ gscdf12d

double gscdf12d[13][13]
Initial value:
= {
NAN
}

Definition at line 594 of file LRgsn.c.

◆ gscdf12f

float gscdf12f[13][13]
Initial value:
= {
NAN
}

Definition at line 602 of file LRgsn.c.

◆ gscdf4d

double gscdf4d[5][5]
Initial value:
= {
NAN
}

Definition at line 329 of file LRgsn.c.

◆ gscdf4f

float gscdf4f[5][5]
Initial value:
= {
NAN
}

Definition at line 337 of file LRgsn.c.

◆ gscdfd12

long gscdfd12[13][13]
Initial value:
= {
{1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,479001600l},
{479001600l,39916800l,7257600l,2177280l,967680l,604800l,518400l,604800l,967680l,2177280l,7257600l,39916800l,43545600l},
{119750400l,9979200l,1814400l,108864l,241920l,151200l,129600l,30240l,241920l,544320l,907200l,3991680l,8709120l},
{394240l,13305600l,806400l,145152l,21504l,201600l,19200l,8064l,21504l,725760l,268800l,887040l,2903040l},
{1330560l,19800l,302400l,1134l,8064l,6300l,800l,1l,8064l,45360l,151200l,332640l,1451520l},
{79833600l,6652800l,57600l,384l,23040l,14400l,86400l,20160l,7680l,17280l,172800l,190080l,1036800l},
{2l,1663200l,1l,12960l,1l,3600l,1l,25200l,1l,12960l,1l,158400l,1036800l},
{79833600l,6652800l,57600l,384l,23040l,14400l,86400l,20160l,7680l,17280l,172800l,190080l,1451520l},
{1330560l,19800l,302400l,1134l,8064l,6300l,800l,1l,8064l,45360l,151200l,332640l,2903040l},
{394240l,13305600l,806400l,145152l,21504l,201600l,19200l,8064l,21504l,725760l,268800l,887040l,8709120l},
{119750400l,9979200l,1814400l,108864l,241920l,151200l,129600l,30240l,241920l,544320l,907200l,3991680l,43545600l},
{479001600l,39916800l,7257600l,2177280l,967680l,604800l,518400l,604800l,967680l,2177280l,7257600l,39916800l,479001600l},
{1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l}
}

Definition at line 538 of file LRgsn.c.

◆ gscdfd4

int gscdfd4[5][5]
Initial value:
= {
{1,1,1,1,24},
{24,6,4,6,8},
{2,3,1,3,8},
{24,6,4,6,24},
{1,1,1,1,1}
}

Definition at line 300 of file LRgsn.c.

◆ gscdfn12

long gscdfn12[13][13]
Initial value:
= {
{0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,1l},
{1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,-1l},
{1021l,509l,253l,25l,61l,29l,13l,1l,1l,-1l,-1l,-1l,1l},
{397l,50879l,5203l,907l,79l,239l,1l,-1l,-1l,-1l,1l,1l,-1l},
{29639l,1093l,16973l,31l,29l,-17l,-1l,0l,1l,1l,-1l,-1l,1l},
{12831419l,1623019l,6787l,-1l,-443l,-43l,167l,11l,-1l,-1l,1l,1l,-1l},
{1l,655177l,0l,-809l,0l,31l,0l,-23l,0l,1l,0l,-1l,1l},
{67002181l,1623019l,-6787l,-1l,443l,-43l,-167l,11l,1l,-1l,-1l,1l,-1l},
{1300921l,1093l,-16973l,31l,-29l,-17l,1l,0l,-1l,1l,1l,-1l,1l},
{393843l,50879l,-5203l,907l,-79l,239l,-1l,-1l,1l,-1l,-1l,1l,-1l},
{119749379l,509l,-253l,25l,-61l,29l,-13l,1l,-1l,-1l,1l,-1l,1l},
{479001599l,1l,-1l,1l,-1l,1l,-1l,1l,-1l,1l,-1l,1l,-1l},
{1l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l}
}

Definition at line 521 of file LRgsn.c.

◆ gscdfn4

int gscdfn4[5][5]
Initial value:
= {
{0,0,0,0,1},
{1,1,1,1,-1},
{1,2,0,-1,1},
{23,1,-1,1,-1},
{1,0,0,0,0}
}

Definition at line 292 of file LRgsn.c.

◆ gspdf12d

double gspdf12d[13][13]
Initial value:
= {
NAN
}

Definition at line 590 of file LRgsn.c.

◆ gspdf12f

float gspdf12f[13][13]
Initial value:
= {
NAN
}

Definition at line 598 of file LRgsn.c.

◆ gspdf4d

double gspdf4d[5][5]
Initial value:
= {
NAN
}

Definition at line 325 of file LRgsn.c.

◆ gspdf4f

float gspdf4f[5][5]
Initial value:
= {
NAN
}

Definition at line 333 of file LRgsn.c.

◆ gspdfd12

long gspdfd12[13][13]
Initial value:
= {
{1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,39916800l,1l},
{39916800l,3628800l,725760l,241920l,120960l,86400l,86400l,120960l,241920l,725760l,3628800l,3628800l,1l},
{9979200l,907200l,36288l,60480l,30240l,21600l,4320l,30240l,60480l,90720l,362880l,725760l,1l},
{13305600l,403200l,48384l,5376l,40320l,3200l,1152l,2688l,80640l,26880l,80640l,241920l,1l},
{19800l,151200l,378l,2016l,1260l,400l,1l,1008l,5040l,15120l,30240l,120960l,1l},
{6652800l,28800l,128l,5760l,2880l,14400l,2880l,960l,1920l,17280l,17280l,86400l,1l},
{1663200l,1l,4320l,1l,720l,1l,3600l,1l,1440l,1l,14400l,86400l,1l},
{6652800l,28800l,128l,5760l,2880l,14400l,2880l,960l,1920l,17280l,17280l,120960l,1l},
{19800l,151200l,378l,2016l,1260l,400l,1l,1008l,5040l,15120l,30240l,241920l,1l},
{13305600l,403200l,48384l,5376l,40320l,3200l,1152l,2688l,80640l,26880l,80640l,725760l,1l},
{9979200l,907200l,36288l,60480l,30240l,21600l,4320l,30240l,60480l,90720l,362880l,3628800l,1l},
{39916800l,3628800l,725760l,241920l,120960l,86400l,86400l,120960l,241920l,725760l,3628800l,39916800l,1l},
{1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l}
}

Definition at line 572 of file LRgsn.c.

◆ gspdfd4

int gspdfd4[5][5]
Initial value:
= {
{1,1,1,6,1},
{6,2,2,2,1},
{3,1,1,2,1},
{6,2,2,6,1},
{1,1,1,1,1}
}

Definition at line 316 of file LRgsn.c.

◆ gspdfn12

long gspdfn12[13][13]
Initial value:
= {
{0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,1l,0l},
{1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,1l,-1l,0l},
{509l,253l,25l,61l,29l,13l,1l,1l,-1l,-1l,-1l,1l,0l},
{50879l,5203l,907l,79l,239l,1l,-1l,-1l,-1l,1l,1l,-1l,0l},
{1093l,16973l,31l,29l,-17l,-3l,0l,1l,1l,-1l,-1l,1l,0l},
{1623019l,6787l,-1l,-443l,-43l,167l,11l,-1l,-1l,1l,1l,-1l,0l},
{655177l,0l,-809l,0l,31l,0l,-23l,0l,1l,0l,-1l,1l,0l},
{1623019l,-6787l,-1l,443l,-43l,-167l,11l,1l,-1l,-1l,1l,-1l,0l},
{1093l,-16973l,31l,-29l,-17l,3l,0l,-1l,1l,1l,-1l,1l,0l},
{50879l,-5203l,907l,-79l,239l,-1l,-1l,1l,-1l,-1l,1l,-1l,0l},
{509l,-253l,25l,-61l,29l,-13l,1l,-1l,-1l,1l,-1l,1l,0l},
{1l,-1l,1l,-1l,1l,-1l,1l,-1l,1l,-1l,1l,-1l,0l},
{0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l}
}

Definition at line 555 of file LRgsn.c.

◆ gspdfn4

int gspdfn4[5][5]
Initial value:
= {
{0,0,0,1,0},
{1,1,1,-1,0},
{2,0,-1,1,0},
{1,-1,1,-1,0},
{0,0,0,0,0}
}

Definition at line 308 of file LRgsn.c.