50 #include "urand/urand.h" 61 LR_obj *ptr = (
void *) NULL;
66 ptr->
aux = (
void *) NULL;
79 ptr->
a.
d = (double) 0.0;
80 ptr->
b.
d = (double) 1.0;
85 ptr->
a.
f = (float) 0.0;
86 ptr->
b.
f = (float) 1.0;
98 if (!(ptr->
aux = (
void *) calloc(
sizeof(
LR_pcs),1)))
106 ptr->
a.
d = (double) -1.0;
107 ptr->
b.
d = (double) 1.0;
108 ptr->
x.
d = (double) 1.0;
113 ptr->
a.
f = (float) -1.0;
114 ptr->
b.
f = (float) 1.0;
115 ptr->
x.
f = (float) 1.0;
127 ptr->
type =
"lspline";
128 if (!(ptr->
aux = (
void *) calloc(
sizeof(
LR_pcs),1)))
136 ptr->
a.
d = (double) -1.0;
137 ptr->
b.
d = (double) 1.0;
142 ptr->
a.
f = (float) -1.0;
143 ptr->
b.
f = (float) 1.0;
155 ptr->
type =
"uinvcdf";
186 ptr->
m.
d = (double) 1.0;
192 ptr->
m.
f = (float) 1.0;
203 ptr->
type =
"erlang";
206 ptr->
m.
d = (double) 1.0;
212 ptr->
m.
f = (float) 1.0;
223 ptr->
type =
"gausbm";
225 ptr->
m.
d = (double) 0.0;
226 ptr->
s.
d = (double) 1.0;
232 ptr->
m.
f = (float) 0.0;
233 ptr->
s.
f = (float) 1.0;
244 ptr->
type =
"gausmar";
246 ptr->
m.
d = (double) 0.0;
247 ptr->
s.
d = (double) 1.0;
253 ptr->
m.
f = (float) 0.0;
254 ptr->
s.
f = (float) 1.0;
267 ptr->
a.
d = (double) -1.0;
268 ptr->
b.
d = (double) 1.0;
269 ptr->
m.
d = (double) 0.0;
270 ptr->
s.
d = (double) 1.0;
275 ptr->
a.
f = (float) -1.0;
276 ptr->
b.
f = (float) 1.0;
277 ptr->
m.
f = (float) 0.0;
278 ptr->
s.
f = (float) 1.0;
290 ptr->
a.
d = (double) -2.0;
291 ptr->
b.
d = (double) 2.0;
292 ptr->
m.
d = (double) 0.0;
293 ptr->
s.
d = (double) 2.0;
298 ptr->
a.
f = (float) -2.0;
299 ptr->
b.
f = (float) 2.0;
300 ptr->
m.
f = (float) 0.0;
301 ptr->
s.
f = (float) 2.0;
313 ptr->
a.
d = (double) -6.0;
314 ptr->
b.
d = (double) 6.0;
315 ptr->
m.
d = (double) 0.0;
316 ptr->
s.
d = (double) 1.0;
321 ptr->
a.
f = (float) -6.0;
322 ptr->
b.
f = (float) 6.0;
323 ptr->
m.
f = (float) 0.0;
324 ptr->
s.
f = (float) 1.0;
334 ptr->
type =
"cauchy";
336 ptr->
m.
d = (double) 0.0;
337 ptr->
s.
d = (double) 1.0;
342 ptr->
m.
f = (float) 0.0;
343 ptr->
s.
f = (float) 1.0;
353 ptr->
type =
"cauchymar";
355 ptr->
m.
d = (double) 0.0;
356 ptr->
s.
d = (double) 1.0;
361 ptr->
m.
f = (float) 0.0;
362 ptr->
s.
f = (float) 1.0;
372 ptr->
type =
"poisson";
374 ptr->
p = (float) 1.0;
385 ptr->
type =
"geometric";
387 ptr->
p = (float) 0.5;
398 ptr->
type =
"binomial";
400 ptr->
p = (float) 0.5;
435 if (((*o)->t ==
piece)
437 free((
void *) (*o)->aux);
471 double td, dzero = 0.0;
472 float tf, fzero = 0.0;
474 if (o && o->
t && o->
d) {
483 if (o->
a.
d > o->
b.
d) {
487 }
else if (o->
a.
d == o->
b.
d) {
491 if (o->
a.
f > o->
b.
f) {
495 }
else if (o->
a.
d == o->
b.
d) {
507 if ((!isnan(o->
a.
d)) && (!isnan(o->
b.
d))) {
508 if (o->
a.
d > o->
b.
d) {
512 }
else if (o->
a.
d == o->
b.
d) {
516 if ((!isnan(o->
s.
d))) {
517 if (o->
s.
d < dzero) {
519 }
else if (o->
s.
d == dzero) {
524 if (isnan(o->
a.
d) && isnan(o->
b.
d)
525 && isnan(o->
m.
d) && isnan(o->
s.
d))
529 if ((!isnan(o->
a.
f)) && (!isnan(o->
b.
f))) {
530 if (o->
a.
f > o->
b.
f) {
534 }
else if (o->
a.
f == o->
b.
f) {
538 if ((!isnan(o->
s.
f))) {
539 if (o->
s.
f < fzero) {
541 }
else if (o->
s.
f == fzero) {
546 if (isnan(o->
a.
f) && isnan(o->
b.
f)
547 && isnan(o->
m.
f) && isnan(o->
s.
f))
563 if (o->
s.
d < dzero) {
565 }
else if (o->
s.
d == dzero) {
570 if (o->
s.
f < fzero) {
572 }
else if (o->
s.
f == fzero) {
584 if (o->
m.
d < dzero) {
586 }
else if (o->
m.
d == dzero) {
591 if (o->
m.
f < fzero) {
593 }
else if (o->
m.
f == fzero) {
606 }
else if (o->
k == 0) {
610 if (o->
m.
d < dzero) {
612 }
else if (o->
m.
d == dzero) {
617 if (o->
m.
f < fzero) {
619 }
else if (o->
m.
f == fzero) {
632 }
else if (o->
p == 0) {
641 if (o->
p == 0 || o->
p > 1) {
653 if (o->
n < 1 || o->
p == 0 || o->
p > 1) {
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...
LR_data_type
an enum of allowed value types
double LRd_nexp_RAN(LR_obj *o)
LRd_nexp_RAN(LR_obj *o) - double random negative exponential distribution using the inversion method...
double LRd_unif_RAN(LR_obj *o)
LRd_unif_RAN(LR_obj *o) - double random uniform distribution.
float(* cdff)(LR_obj *, float)
double LRd_unif_PDF(LR_obj *o, double x)
LRd_unif_PDF(LR_obj *o, double x) - double uniform probablity distribution function.
double LRd_nexp_PDF(LR_obj *o, double x)
LRd_nexp_PDF(LR_obj *o, double x) - double negative exponential probablity distribution function...
float(* pdff)(LR_obj *, float)
float LRf_cauchymar_RAN(LR_obj *o)
LRf_cauchymar_RAN(LR_obj *o) - float random Cauchy/Lorentz distribution using the polar method and th...
double LR_drand(LR_obj *)
LR_drand(LR_obj *) - returns double in range [0.0,1.0)
float LRf_lspline_CDF(LR_obj *o, float x)
LRf_lspline_CDF(LR_obj *o, float x) - float linear spline cumulative distribution function...
float LRi_poisson_CDF(LR_obj *o, int x)
LRi_poisson_CDF(LR_obj *o, int x) - Poisson distribution cumulative distribution function.
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...
int LR_rm(LR_obj **o)
LR_rm(LR_obj **o) - destroy the LR object and release allocated memory.
float LRf_erlang_PDF(LR_obj *o, float x)
LRf_erlang_PDF(LR_obj *o, float x) - Erlang distribution probablity distribution function.
double LRd_piece_PDF(LR_obj *o, double x)
LRd_piece_PDF(LR_obj *o, double x) - double piecewise uniform probablity distribution function...
double LRd_erlang_CDF(LR_obj *o, double x)
LRd_erlang_CDF(LR_obj *o, double x) - Erlang distribution cumulative distribution function...
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...
int LR_pcs_norm(LR_obj *o)
LR_pcs_norm(LR_obj *o) - normalize the interval scale factors.
int LRi_binomial_RAN(LR_obj *o)
LRi_binomial_RAN(LR_obj *o) - int Binomial distributed variate. Default values: probability of succes...
int LR_check(LR_obj *o)
LR_check(LR_obj *o) - check and fix the LR object parameters if possible.
double LRd_gsn4_RAN(LR_obj *o)
LRd_gsn4_RAN(LR_obj *o) - double random g4 gaussian-like (simple bell curve) distribution.
float LRf_piece_RAN(LR_obj *o)
LRf_piece_RAN(LR_obj *o) - float random piecewise uniform distribution.
LR_type
an enum of allowed random variate distribution types
int LRi_poisson_RAN(LR_obj *o)
LRi_poisson_RAN(LR_obj *o) - int Poisson distributed variate. Default values: scale m = 1...
int LR_irand(LR_obj *)
LR_irand(LR_obj *) - returns int in range [0,LR_IRAND_IMAX].
LR_obj * LR_new(LR_type t, LR_data_type d)
LR_new(LR_type t, LR_data_type d) - create the LR object and preset some default parameter values...
float LRf_gausmar_RAN(LR_obj *o)
LRf_gausmar_RAN(LR_obj *o) - float random Gaussian/Normal distribution using the Marsaglia method wit...
int LR_pcs_set(LR_obj *o, double x, double p)
LR_pcs_set(LR_obj *o, double x) - add interval boundary (will order internally).
float LRf_cauchy_CDF(LR_obj *o, float x)
LRf_cauchy_CDF(LR_obj *o, float x) - float Cauchy/Lorentz cumulative distribution function...
#define LRerr_UnmetPreconditions
float LRf_lspline_PDF(LR_obj *o, float x)
LRf_lspline_PDF(LR_obj *o, float x) - float linear spline probablity distribution function...
A special object for defining some of the random variate distributions.
double LRd_lspline_CDF(LR_obj *o, double x)
LRd_lspline_CDF(LR_obj *o, double x) - double linear spline cumulative distribution function...
float LRf_nexp_CDF(LR_obj *o, float x)
LRf_nexp_CDF(LR_obj *o, float x) - float negative exponential cumulative distribution function...
float LRf_unif_CDF(LR_obj *o, float x)
LRf_unif_CDF(LR_obj *o, float x) - float uniform cumulative distribution function.
double LRd_gausbm_RAN(LR_obj *o)
LRd_gausbm_RAN(LR_obj *o) - double random Gaussian/Normal distribution using the Box-Muller method...
float LRf_unif_RAN(LR_obj *o)
LRf_unif_RAN(LR_obj *o) - float random uniform distribution.
#define LRerr_InvalidRange
long LR_lrand(LR_obj *)
LR_lrand(LR_obj *) - returns long in range [0,LR_IRAND_LMAX].
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...
float LRi_geometric_PDF(LR_obj *o, int x)
LRi_geometric_PDF(LR_obj *o, int x) - Geometric probablity (or mass) distribution function...
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...
int(* set)(LR_obj *o, double x, double p)
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...
float LRf_gaus_PDF(LR_obj *o, float x)
LRf_gaus_PDF(LR_obj *o, float x) - float Gaussian/Normal probablity distribution function.
double(* cdfd)(LR_obj *, double)
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 f...
#define LRerr_BadDataType
int LRi_geometric_RAN(LR_obj *o)
LRi_geometric_RAN(LR_obj *o) - int Geometric distributed variate. Default values: probability of succ...
float LRf_uinvcdf_CDF(LR_obj *o, float x)
LRf_uinvcdf_CDF(LR_obj *o, float x) - float User supplied cumulative distribution function...
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 f...
float LRf_lspline_RAN(LR_obj *o)
LRf_lspline_RAN(LR_obj *o) - float random linear spline distribution.
float LRf_cauchy_PDF(LR_obj *o, float x)
LRf_cauchy_PDF(LR_obj *o, float x) - float Cauchy/Lorentz probablity distribution function...
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...
double LRd_cauchy_CDF(LR_obj *o, double x)
LRd_cauchy_CDF(LR_obj *o, double x) - double Cauchy/Lorentz cumulative distribution function...
float LR_frand(LR_obj *)
LR_frand(LR_obj *) - returns float in range [0.0,1.0)
float LRf_uinvcdf_PDF(LR_obj *o, float x)
LRf_uinvcdf_PDF(LR_obj *o, float x) - float probability distribution function approximated from the u...
double LRd_gsn2_RAN(LR_obj *o)
LRd_gsn2_RAN(LR_obj *o) - double random g2 gaussian-like (saw tooth) distribution.
int LR_pcs_rm(LR_obj *o)
LR_pcs_rm(LR_obj *o) - strip out the LR_pcs object part of LR_obj.
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 ...
float LRf_gsn12_RAN(LR_obj *o)
LRf_gsn12_RAN(LR_obj *o) - float random g12 gaussian-like distribution closely matches a Gaussian/Nor...
double LRd_gsn12_RAN(LR_obj *o)
LRd_gsn12_RAN(LR_obj *o) - double random g12 gaussian-like distribution closely matches a Gaussian/No...
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 fu...
float LRf_erlang_CDF(LR_obj *o, float x)
LRf_erlang_CDF(LR_obj *o, float x) - Erlang distribution cumulative distribution function.
A special object for using a user defined CDF.
float LRf_gaus_CDF(LR_obj *o, float x)
LRf_gaus_CDF(LR_obj *o, float x) - float Gaussian/Normal cumulative distribution function.
int(* normalize)(LR_obj *o)
float LRf_gausbm_RAN(LR_obj *o)
LRf_gausbm_RAN(LR_obj *o) - float random Gaussian/Normal distribution using the Box-Muller method...
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...
double LRd_piece_CDF(LR_obj *o, double x)
LRd_piece_CDF(LR_obj *o, double x) - double piecewise uniform cumulative distribution function...
double LRd_lspline_RAN(LR_obj *o)
LRd_lspline_RAN(LR_obj *o) - double random linear spline distribution random variate.
double LRd_uinvcdf_RAN(LR_obj *o)
LRd_uinvcdf_RAN(LR_obj *o) - double random variate via inverse method of the UserCDF() fn...
double LRd_piece_RAN(LR_obj *o)
LRd_piece_RAN(LR_obj *o) - double random piecewise uniform distribution random variate.
double(* pdfd)(LR_obj *, double)
int LR_lspl_new(LR_obj *o, int n)
LR_lspl_new(LR_obj *o, int n) - create a new linear spline object.
float LRi_binomial_PDF(LR_obj *o, int x)
LRi_binomial_PDF(LR_obj *o, int k) - Binomial probablity (or mass) distribution function.
float(* cdfi)(LR_obj *, int)
double LRd_gaus_PDF(LR_obj *o, double x)
LRd_gaus_PDF(LR_obj *o, double x) - double Gaussian/Normal probablity distribution function...
double LRd_cauchymar_RAN(LR_obj *o)
LRd_cauchymar_RAN(LR_obj *o) - double random Cauchy/Lorentz distribution using the polar method and t...
float LRf_uinvcdf_RAN(LR_obj *o)
LRf_uinvcdf_RAN(LR_obj *o) - float random variate via inverse method of the UserCDF() fn...
float LRf_unif_PDF(LR_obj *o, float x)
LRf_unif_PDF(LR_obj *o, float x) - float uniform probablity distribution function.
int LR_lspl_rm(LR_obj *o)
LR_lspl_rm(LR_obj *o) - strip out the LR_lspl object part of LR_obj.
float LRf_piece_PDF(LR_obj *o, float x)
LRf_piece_PDF(LR_obj *o, float x) - float piecewise uniform probablity distribution function...
float LRi_geometric_CDF(LR_obj *o, int x)
LRi_geometric_CDF(LR_obj *o, int x) - Geometric distribution cumulative distribution function...
float LRf_piece_CDF(LR_obj *o, float x)
LRf_piece_CDF(LR_obj *o, float x) - float piecewise uniform cumulative distribution function...
double LRd_cauchy_PDF(LR_obj *o, double x)
LRd_cauchy_PDF(LR_obj *o, double x) - double Cauchy/Lorentz probablity distribution function...
double LRd_erlang_PDF(LR_obj *o, double x)
LRd_erlang_PDF(LR_obj *o, double x) - Erlang distribution probablity distribution function...
double LRd_unif_CDF(LR_obj *o, double x)
LRd_unif_CDF(LR_obj *o, double x) - double uniform cumulative distribution function.
float LRf_nexp_PDF(LR_obj *o, float x)
LRf_nexp_PDF(LR_obj *o, float x) - float negative exponential probablity distribution function...
double LRd_cauchy_RAN(LR_obj *o)
LRd_cauchy_RAN(LR_obj *o) - double random Cauchy/Lorentz distribution using the inversion method on t...
float LRf_nexp_RAN(LR_obj *o)
LRf_nexp_RAN(LR_obj *o) - float random negative exponential distribution using the inversion method...
The LibRan common header file.
#define LRerr_Unspecified
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). ...
double LRd_uinvcdf_PDF(LR_obj *o, double x)
LRd_uinvcdf_PDF(LR_obj *o, double x) - double probability distribution function approximated from the...
int LR_pcs_new(LR_obj *o, int n)
LR_pcs_new(LR_obj *o, int n) - create a new piecewise uniform object set of segments.
double LRd_gaus_CDF(LR_obj *o, double x)
LRd_gaus_CDF(LR_obj *o, double x) - double Gaussian/Normal cumulative distribution function...
#define LRerr_InvalidInputValue
double LRd_gausmar_RAN(LR_obj *o)
LRd_gausmar_RAN(LR_obj *o) - double random Gaussian/Normal distribution using the Marsaglia method wi...
float LRf_erlang_RAN(LR_obj *o)
LRf_erlang_RAN(LR_obj *o) - float random negative exponential distribution using the inversion method...
float LRf_cauchy_RAN(LR_obj *o)
LRf_cauchy_RAN(LR_obj *o) - float random Cauchy/Lorentz distribution using the inversion method...
the fundamental LibRan random variate distribution object
float LRf_gsn4_RAN(LR_obj *o)
LRf_gsn4_RAN(LR_obj *o) - float random g4 gaussian-like (simple bell curve) distribution.
double LRd_erlang_RAN(LR_obj *o)
LRd_erlang_RAN(LR_obj *o) - double random negative exponential distribution using the inversion metho...
double LRd_uinvcdf_CDF(LR_obj *o, double x)
LRd_uinvcdf_CDF(LR_obj *o, double x) - double User supplied cumulative distribution function...
double LRd_lspline_PDF(LR_obj *o, double x)
LRd_lspline_PDF(LR_obj *o, double x) - double linear spline probablity distribution function...
float LRi_binomial_CDF(LR_obj *o, int x)
LRi_binomial_CDF(LR_obj *o, int k) - Binomial distribution cumulative distribution function...
int LR_lspl_norm(LR_obj *o)
LR_lspl_norm(LR_obj *o) - normalize the interval scale factors.
float LRi_poisson_PDF(LR_obj *o, int x)
LRi_poisson_PDF(LR_obj *o, int x) - Poisson probablity (or mass) distribution function.
float(* pdfi)(LR_obj *, int)
double LRd_nexp_CDF(LR_obj *o, double x)
LRd_nexp_CDF(LR_obj *o, double x) - double negative exponential cumulative distribution function...
float LRf_gsn2_RAN(LR_obj *o)
LRf_gsn2_RAN(LR_obj *o) - float random g2 gaussian-like (saw tooth) distribution. ...
int(* new)(LR_obj *o, int n)