CDF Class Reference
Generators for random variables from different common distributions.
More...
#include <cdf.h>
Routines
double |
erand
(uint64 *state M) |
uint64 |
eseed
(uint32 seedval) |
void |
Seed_CDF
(CDF *cdf, uint32 seedval) |
Detailed Description
Mylib uses its own version of the popular UNIX drand48 suite. In our
realization, a random number generator's state is modelled by a single uint64 integer.
Given a particular state, erand generates a uniform psuedo-random number in the interval
[0.,1.) and advances the supplied state. eseed produces a state with respect a 32-bit integer
seed value -- typically, this is the processor id number if one wants every run of a program
to produce a different pseudo-random sequence of numbers. drand and dseed are versions
of erand and eseed that consult a global private state. They are both thread-safe.
A CDF object is a random number generator that will produce a pseudo-random sequence of
numbers from a distribution that is specified when it is created. One can create CDF's
that generate numbers from normal, exponential, Poisson, geometric, uniform, binomial,
and Bernouilli distributions with the generators: Normal_CDF, Exponential_CDF,
Poisson_CDF, Geometric_CDF, Uniform_CDF, Binomial_CDF, and Bernouilli_CDF.
FairCoin_CDF generates an equal-weight Bernouilli distribution. Once a CDF has been
created, successive pseudo-random numbers can be drawn from it with successive calls
to Sample_CDF.
Each CDF object normally keeps its own state, so that its pseudo-random sequence is
independent of other CDF objects. This state can be seeded (just as for eseed) by
calling Seed_CDF. However, one may not want this semantics for a number of reasons.
For example, two CDF objects for the same distribution with the same parameters will
generate exactly the same pseudo-random sequence. To prevent this, one can call
Link_CDF(a,b) that will result in b sharing the same state as a, which can
already be sharing state with other CDFs. The situation is completely flexible, in
that at a later time, one can decouple b and return it to using its own private state
by calling Unlink_CDF(b).
If a CDF is written to a file, then its current state is also recorded and re-established
when it is subsequently read in. However, if it was sharing this state when written, it
will be given a private state when read in. It is the user's responsibility to re-establish
any sharing that was taking place.
A simple schema for having all CDFs share the same state is as follows:
CDF *master = FairCoin_CDF(1); // Won't use this CDF, just used as an aggregator
CDF *a = X_CDF(...);
Link_CDF(master,a);
CDF *b = Y_CDF(...);
Link_CDF(master,b);
CDF *c = Z_CDF(...);
Link_CDF(master,c);
...
Routine Documentation
double |
erand (uint64 *state M) |
Advances the supplied state and returns the next
pseudo-random number uniformily distributed in [0.,1.) determined by state.
uint64 |
eseed (uint32 seedval) |
Returns a generator state value derived from the supplied 32-bit integer.
Identical to erand save that a global private state variable is used. The routine
is thread-safe.
void |
dseed (uint32 seedval) |
Sets the private state variable of drand to the value returned by calling eseed(seedval).
CDF * |
Normal_CDFG (double mean, double stdev) |
Create a CDF object that models a normal distribution with mean mean and standard
deviation stdev.
CDF * |
Exponential_CDFG (double a) |
Create a CDF object that models an exponential distribution with arrival rate a > 0.
Pr(X = k) = ake-a/k! for k ≥ 0
CDF * |
Poisson_CDFG (double a) |
Create a CDF object that models a Poisson distribution with arrival rate a > 0.
Pr(X ≤ x) = 1-e-ax for x ≥ 0
CDF * |
Geometric_CDFG (double p) |
Create a CDF object that models a geometric distribution where the probability of an
event is p.
Pr(X = k) = (1-p)k-1p for k ≥ 1
CDF * |
Uniform_CDFG (double low, double hgh) |
Create a CDF object that models a uniform distribution over the interval [low,hgh].
Pr(X ≤ x) = (x-low)/(hgh-low) for x ∈ [low,hgh]
CDF * |
Binomial_CDFG (int n, double p) |
Create a CDF object that models a discrete Binomial distribution for n events
each with probability p.
Pr(X = k) = (n choose k)pk(1-p)n-k for k ∈ [0,n]
CDF * |
FairCoin_CDFG (int n) |
Create a CDF object that models a discrete Bernouilli distribution where each integer between
1 and n occurs with equal probability.
Pr(X = k) = 1/n for k ∈ [1,n]
CDF * |
Bernouilli_CDFG (int n, double *weight) |
Create a CDF object that models a Bernouilli distribution of n outcomes each weighted
according to weight.
Pr(X = k) = weight[k-1] / Σj weight[j] for k ∈ [1,n]
double |
Sample_CDF (CDF *cdf) |
Returns a pseudo-random number distributed according to cdf.
void |
Seed_CDF (CDF *cdf, uint32 seedval) |
Each CDF has its own state variable for random number generation. Calling this routine
is equivalent to seeding its state with the result of calling eseed(seedval).
void |
Link_CDF (CDF *ref, CDF *cdf) |
Alter cdf so that it will share the state variable being used by the CDF ref (and
any other CDFs with which it is linked). cdf must not be sharing its state with any
other CDF when the call is made.
void |
Unlink_CDF (CDF *cdf) |
Alter cdf so that it has its own private state variable for random number generation.
If it was sharing with other CDFs, then the private state variable will be initialized
to have the value of this shared state variable.
|