LibRan
0.1
Pseudo-random number distribution generator
|
Piecewise linear spline distribution. More...
Go to the source code of this file.
Functions | |
int | LR_lspl_new (LR_obj *o, int n) |
LR_lspl_new(LR_obj *o, int n) - create a new linear spline object. More... | |
int | LR_lspl_rm (LR_obj *o) |
LR_lspl_rm(LR_obj *o) - strip out the LR_lspl object part of LR_obj. More... | |
int | LR_lspl_set (LR_obj *o, double x, double p) |
LR_lspl_set(LR_obj *o, double x) - add interval boundary (will order internally). More... | |
int | LR_lspl_norm (LR_obj *o) |
LR_lspl_norm(LR_obj *o) - normalize the interval scale factors. More... | |
double | LRd_lspline_RAN (LR_obj *o) |
LRd_lspline_RAN(LR_obj *o) - double random linear spline distribution random variate. More... | |
double | LRd_lspline_PDF (LR_obj *o, double x) |
LRd_lspline_PDF(LR_obj *o, double x) - double linear spline probablity distribution function. More... | |
double | LRd_lspline_CDF (LR_obj *o, double x) |
LRd_lspline_CDF(LR_obj *o, double x) - double linear spline cumulative distribution function. More... | |
float | LRf_lspline_RAN (LR_obj *o) |
LRf_lspline_RAN(LR_obj *o) - float random linear spline distribution. More... | |
float | LRf_lspline_PDF (LR_obj *o, float x) |
LRf_lspline_PDF(LR_obj *o, float x) - float linear spline probablity distribution function. More... | |
float | LRf_lspline_CDF (LR_obj *o, float x) |
LRf_lspline_CDF(LR_obj *o, float x) - float linear spline cumulative distribution function. More... | |
Piecewise linear spline distribution.
The piecewise linear spline distribution is similar to the piecewise uniform distribution except that the probability distribution function looks like the trapezoidal rule for integration, where each segment is interpolated by a straight line (an affine function, i.e. a polynomial of degree 1).
The PDF is pinned to zero at the end points. So at least one point in between must be added with a non-zero value. If this is not done then an error will be raised.
Once the linear spline distribution object is created the set of trapezoidal blocks can be defined with the set of LR_lspl_*
() functions. (Note: the LR_aux_*
() functions are equivalent and generic procedures and can be used instead.)
This piecewise distribution borrows many of the similar methods as the piecewise uniform distribution (LRpiece.c) auxillary methods since the two have functional equivalency.
The probability and cumulative distribution functions as defined by the above code fragment looks like this:
Definition in file LRlspline.c.
int LR_lspl_new | ( | LR_obj * | o, |
int | n | ||
) |
LR_lspl_new(LR_obj *o, int n) - create a new linear spline object.
This routine must be called after the LR_obj
object is created and it allocates memory for the number of expected segments.
o | LR_obj object |
n | largest number of intervals |
Definition at line 88 of file LRlspline.c.
int LR_lspl_norm | ( | LR_obj * | o | ) |
LR_lspl_norm(LR_obj *o) - normalize the interval scale factors.
The LR_lspl_norm()
function is absolutely required to be called so the integrated probability density equals one. If this routine is not called subsequent calls to the CDF/PDF/RAN functions will raise an error (returning a NAN).
o | LR_obj object |
Definition at line 147 of file LRlspline.c.
int LR_lspl_rm | ( | LR_obj * | o | ) |
LR_lspl_rm(LR_obj *o) - strip out the LR_lspl object part of LR_obj.
Removes the allocated memory for the segment pieces.
o | LR_obj object address |
Definition at line 100 of file LRlspline.c.
int LR_lspl_set | ( | LR_obj * | o, |
double | x, | ||
double | p | ||
) |
LR_lspl_set(LR_obj *o, double x) - add interval boundary (will order internally).
The LR_lspl_set
function defines the set of segments for the probability density function. It adds a new boundary and the value of the probability density at that boundary.
Boundary values can be defined in any order and will be ordered internally by this method.
The outer boundaries are defined through the LR_set_all()
function and the probability density is pinned to zero at these endpoints.
The set of segments and the probability density is relatively defined with LR_lspl_set()
. Once all the segments are defined then the probability density must be normalized with LR_lspl_norm()
such that the total integrated value is equal to one!
o | LR_obj object |
x | interval boundary to add |
p | relative probablity for interval starting at x |
Definition at line 128 of file LRlspline.c.
double LRd_lspline_CDF | ( | LR_obj * | o, |
double | x | ||
) |
LRd_lspline_CDF(LR_obj *o, double x) - double linear spline cumulative distribution function.
o | LR_obj object |
x | value |
Definition at line 281 of file LRlspline.c.
double LRd_lspline_PDF | ( | LR_obj * | o, |
double | x | ||
) |
LRd_lspline_PDF(LR_obj *o, double x) - double linear spline probablity distribution function.
o | LR_obj object |
x | value |
Definition at line 247 of file LRlspline.c.
double LRd_lspline_RAN | ( | LR_obj * | o | ) |
LRd_lspline_RAN(LR_obj *o) - double random linear spline distribution random variate.
o | LR_obj object |
Definition at line 209 of file LRlspline.c.
float LRf_lspline_CDF | ( | LR_obj * | o, |
float | x | ||
) |
LRf_lspline_CDF(LR_obj *o, float x) - float linear spline cumulative distribution function.
o | LR_obj object |
x | value |
Definition at line 390 of file LRlspline.c.
float LRf_lspline_PDF | ( | LR_obj * | o, |
float | x | ||
) |
LRf_lspline_PDF(LR_obj *o, float x) - float linear spline probablity distribution function.
o | LR_obj object |
x | value |
Definition at line 356 of file LRlspline.c.
float LRf_lspline_RAN | ( | LR_obj * | o | ) |
LRf_lspline_RAN(LR_obj *o) - float random linear spline distribution.
o | LR_obj object |
Definition at line 318 of file LRlspline.c.