Random Variables

Detailed Description

Sampling or evaluating random variables for simulation.

This module implements the evaluation (also known as sampling) of random variables with various distributions. It specialises on restricted support PDFs, since this is required for the ProposingExecutor.

Random variables and their simulation is a highly involved topic and we give credit to the sources from which this module stems:

1) Implementation of a random number generator from Stave Park and Dave Geyer, which we use in original form up to minor cosmetic changes.

2)
Inverse gaussian CDF by rational approxomation coefficients, presumably by Peter J, Acjlam, which we use in its original form up to minor cosmetic changes.

3) Gaussian CDF by an aproximation that we found in "Handbook of Mathematical Functions" by Abromowitz and Stegun.

All sources were available freely and we did not find any restricting licensing terms. Thanks!


Regarding 1), from the header of rngs.c

This is an ANSI C library for multi-stream random number generation.
The use of this library is recommended as a replacement for the ANSI C rand() and srand() functions, particularly in simulation applications where the statistical 'goodness' of the random number generator is important. The library supplies 256 streams of random numbers; use SelectStream(s) to switch between streams indexed s = 0,1,...,255.

The streams must be initialized. The recommended way to do this is by using the function PlantSeeds(x) with the value of x used to initialize the default stream and all other streams initialized automatically with values dependent on the value of x. The following convention is used to initialize the default stream:
if x > 0 then x is the state
if x < 0 then the state is obtained from the system clock
if x = 0 then the state is to be supplied interactively.
The generator used in this library is a so-called 'Lehmer random number generator' which returns a pseudo-random number uniformly distributed 0.0 and 1.0. The period is (m - 1) where m = 2,147,483,647 and the smallest and largest possible values are (1 / m) and 1 - (1 / m) respectively. For more details see:

  "Random Number Generators: Good Ones Are Hard To Find"         \n
              Steve Park and Keith Miller                        \n
         Communications of the ACM, October 1988                 \n

Name : rngs.c (Random Number Generation - Multiple Streams)
Authors : Steve Park & Dave Geyer
Language : ANSI C
Latest Revision : 09-22-98


Regarding 2), from the header of rngs.c

This function returns an approximation of the inverse cumulative standard normal distribution function. I.e., given P, it returns an approximation to the X satisfying P = Pr{Z <= X} where Z is a random variable from the standard normal distribution.

The algorithm uses a minimax approximation by rational functions and the result has a relative error whose absolute value is less than 1.15e-9.

Author: Peter J. Acklam
Time-stamp: 2002-06-09 18:45:44 +0200
E-mail: jacklam at math dot uio dor no
WWW URL: http www dot math dot uio dot no /~jacklam
C implementation adapted from Peter's Perl version


Regarding 3) found as code example in Wikipedia


Functions

void faudes::ran_plant_seeds (long x)
 Use this function to set the state of all the random number generator streams by "planting" a sequence of states (seeds), one per stream, with all states dictated by the state of the default stream. More...
 
void faudes::ran_select_stream (int index)
 Use this function to set the current random number generator stream – that stream from which the next random number will come. More...
 
void faudes::ran_put_seed (long seed)
 Put a seed. More...
 
void faudes::ran_init (long seed)
 Initialize random generator. More...
 
double faudes::ran (void)
 Run random generator Random Number Generator (for more details see "Random Number Generators: Good Ones Are Hard To Find" Steve Park and Keith Miller Communications of the ACM, October 1988) More...
 
double faudes::ran_uniform (double a, double b)
 Sample a random variable uniformly on interval [a;b) Distribution: f(t) dt= {1/(b-a)} dt for t, a <=t< b, else 0. More...
 
long faudes::ran_uniform_int (long a, long b)
 Sample a discrete random variable uniformly on interval [a;b) Distribution: p(n) = 1/(b-a-1) More...
 
double faudes::ran_exponential (double mu)
 Sample a random variable exponentially Distribution: f(t) dt = 1/mu exp(-t/mu) dt for t>=0. More...
 
double faudes::ran_exponential (double mu, Time::Type tossLB, Time::Type tossUB)
 Sample a random variable exponentially on a restricted interval Distribution: f(t) dt = 1/mu exp(-t/mu) dt for t>=0. More...
 
double faudes::ran_gauss (double mu, double sigma, Time::Type tossLB, Time::Type tossUB)
 Sample a random variable gaussian distributed on a restricted interval Distribution: f(t) = 1 / sqrt(2 pi sigma^2) * exp( -1/2 ((t-mu)/sigma)^2) for t>=0. More...
 
double faudes::ran_gaussian_cdf_P (double x)
 Help function: calculate gaussian CDF using an approximation from Abromowitz and Stegun: Handbook of Mathematical Functions. More...
 

Function Documentation

◆ ran()

double faudes::ran ( void  )

Run random generator Random Number Generator (for more details see "Random Number Generators: Good Ones Are Hard To Find" Steve Park and Keith Miller Communications of the ACM, October 1988)

Returns
Random value in [0,1) ( excluding 1 (?))

Definition at line 75 of file sp_random.cpp.

◆ ran_exponential() [1/2]

double faudes::ran_exponential ( double  mu)

Sample a random variable exponentially Distribution: f(t) dt = 1/mu exp(-t/mu) dt for t>=0.

Parameters
mumu
Returns
Random variabe

Definition at line 107 of file sp_random.cpp.

◆ ran_exponential() [2/2]

double faudes::ran_exponential ( double  mu,
Time::Type  tossLB,
Time::Type  tossUB 
)

Sample a random variable exponentially on a restricted interval Distribution: f(t) dt = 1/mu exp(-t/mu) dt for t>=0.

Parameters
mumu
tossLBLower interval bound
tossUBUpper interval bound

Definition at line 116 of file sp_random.cpp.

◆ ran_gauss()

double faudes::ran_gauss ( double  mu,
double  sigma,
Time::Type  tossLB,
Time::Type  tossUB 
)

Sample a random variable gaussian distributed on a restricted interval Distribution: f(t) = 1 / sqrt(2 pi sigma^2) * exp( -1/2 ((t-mu)/sigma)^2) for t>=0.

Parameters
mumu
sigmasigma
tossLBLower interval bound
tossUBUpper interval bound

Definition at line 132 of file sp_random.cpp.

◆ ran_gaussian_cdf_P()

double faudes::ran_gaussian_cdf_P ( double  x)

Help function: calculate gaussian CDF using an approximation from Abromowitz and Stegun: Handbook of Mathematical Functions.

Parameters
x
Returns
CDF(x)

Definition at line 224 of file sp_random.cpp.

◆ ran_init()

void faudes::ran_init ( long  seed)

Initialize random generator.

Parameters
seedRandom generator seed

Definition at line 67 of file sp_random.cpp.

◆ ran_plant_seeds()

void faudes::ran_plant_seeds ( long  x)

Use this function to set the state of all the random number generator streams by "planting" a sequence of states (seeds), one per stream, with all states dictated by the state of the default stream.

The sequence of planted states is separated one from the next by 8,367,782 calls to ran().

Definition at line 35 of file sp_random.cpp.

◆ ran_put_seed()

void faudes::ran_put_seed ( long  seed)

Put a seed.

Parameters
seedRandom generator seed

Definition at line 55 of file sp_random.cpp.

◆ ran_select_stream()

void faudes::ran_select_stream ( int  index)

Use this function to set the current random number generator stream – that stream from which the next random number will come.

Definition at line 60 of file sp_random.cpp.

◆ ran_uniform()

double faudes::ran_uniform ( double  a,
double  b 
)

Sample a random variable uniformly on interval [a;b) Distribution: f(t) dt= {1/(b-a)} dt for t, a <=t< b, else 0.

Parameters
aLower bound
bUpper bound
Returns
Random value

Definition at line 91 of file sp_random.cpp.

◆ ran_uniform_int()

long faudes::ran_uniform_int ( long  a,
long  b 
)

Sample a discrete random variable uniformly on interval [a;b) Distribution: p(n) = 1/(b-a-1)

Parameters
aLower bound
bUpper bound
Returns
Random value

Definition at line 98 of file sp_random.cpp.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen