LibRan
0.1
Pseudo-random number distribution generator
|
auxillary program to perform the derivations necessary for computing the CDF and PDF for summing a number of uniform random variates. Can safely handle upto 12 uniform random variates without overflow. More...
#include <stdio.h>
#include <limits.h>
Go to the source code of this file.
Macros | |
#define | NINT 15 |
Typedefs | |
typedef long | LINT |
long integer type used for calculations. | |
Functions | |
LINT | igcd (LINT a, LINT b) |
LINT igcd(LINT a, LINT b) return Greatest Common Denominator of a & b. | |
LINT | ifac (int n) |
LINT ifac(LINT n) return the factorial of n (n!) | |
LINT | icomb (int n, int k) |
LINT icomb(LINT n, LINT k) return binomial factor n!/[k!*(n-k)!]. | |
void | iadd (LINT an, LINT ad, LINT bn, LINT bd, LINT x, LINT *on, LINT *od) |
void iadd(an,ad,bn,bd, x, *on, *od) return a + b*x where a,b are represented as rationals More... | |
void | imult (LINT an, LINT ad, LINT bn, LINT bd, LINT x, LINT *on, LINT *od) |
void imult(an,ad,bn,bd, x, *on, *od) return a*b*x where a,b are represented as rationals More... | |
void | showdf (char *DFstr, int order, LINT xn[][NINT], LINT xd[][NINT]) |
void showdf(DFstr, order, xn[][NINT], xd[][NINT]) display the rational values of 'x'. More... | |
void | writedf (char *DFstr, int order, LINT xn[][NINT]) |
void writedf(DFstr, order, xn[][NINT]) output array as a C declaration More... | |
void | newcdf (int nn) |
void newcdf(nn) calculate the new CDF of order nn More... | |
void | newpdf (int nn) |
void newpdf(nn) calculate the new PDF of order nn by differentiating the CDF. More... | |
void | transint (int nn, LINT xn[][NINT], LINT xd[][NINT]) |
void transint(nn, xn[][NINT], xd[]{NINT]) translate each interval to [0,1) More... | |
int | main () |
Variables | |
LINT | pn [NINT][NINT] |
PDF numerator. More... | |
LINT | pd [NINT][NINT] |
PDF denominator. More... | |
LINT | cn [NINT][NINT] |
CDF numerator. More... | |
LINT | cd [NINT][NINT] |
CDF denominator. More... | |
auxillary program to perform the derivations necessary for computing the CDF and PDF for summing a number of uniform random variates. Can safely handle upto 12 uniform random variates without overflow.
Adding two random variates will produce a new CDF which is the convolution of the two individual respective PDFs.
The uniform random variate has:
Look at page 22 of "Non-Uniform Random Variate Generation" by Luc Devroye.
The CDF of uniform random variates summed together is
This code will handle each of the intervals individually and expressly handle the polynomial coefficients for that interval as rational values (ratio of integers) and performing basic mathematic operations exactly . The result will be the new CDF and when differentiated the new PDF.
Finally, translate the polynomial coefficients to the local interval where to prevent inaccuracies and overflows when evaluating a large polynomial.
Finally the coefficients pairs are output into a format such the text could be included into C code with minimal editing. This was how the coefficients were generated for LRgsn.c
.
The invoking functions must initialize the floating point coefficients by calculating the ratio of coefficient pairs. This only needs to be done once if the floating point values are stored in an array.
Definition in file gsn.c.
void iadd(an,ad,bn,bd, x, *on, *od) return a + b*x where a,b are represented as rationals
LINT | an 'a' numerator |
LINT | ad 'a' denominator |
LINT | bn 'b' numerator |
LINT | bd 'b' denominator |
LINT | x multiplication factor |
LINT | *on output numerator |
LINT | *od output denominator |
void imult(an,ad,bn,bd, x, *on, *od) return a*b*x where a,b are represented as rationals
LINT | an 'a' numerator |
LINT | ad 'a' denominator |
LINT | bn 'b' numerator |
LINT | bd 'b' denominator |
LINT | x multiplication factor |
LINT | *on output numerator |
LINT | *od output denominator |
void newcdf | ( | int | nn | ) |
void newpdf | ( | int | nn | ) |
void transint(nn, xn[][NINT], xd[]{NINT]) translate each interval to [0,1)
This translates the polynomial coefficients from [i,i+1) ot [0,1) where the coefficients are represented by rational values.
int | nn order of gsn. |
LINT | xn[][NINT] input/output numerator |
LINT | xd[][NINT] input/output denominator |
void writedf | ( | char * | DFstr, |
int | order, | ||
LINT | xn[][NINT] | ||
) |
LINT cd[NINT][NINT] |
CDF denominator.
LINT cn[NINT][NINT] |
CDF numerator.
LINT pd[NINT][NINT] |
PDF denominator.
LINT pn[NINT][NINT] |
PDF numerator.