#include <RandomVar.h>
Public Member Functions | |
virtual T | operator() ()=0 |
virtual double | p (const T &) const =0 |
virtual void | seed (long s) |
Initializes the pseudo random number generator with the seed value "s". | |
RandomVar & | operator= (const RandomVar &r) |
Assigns the pseudo random number generator instance "r" to the current random number generator instance. | |
virtual double | entropy () |
For a distribution "p" given by the currently used random number generator type, the entropy "H(p)" is calculated. | |
virtual double | KullbackLeibler (const RandomVar< T > &rv) |
Calculates the Kullback-Leibler distance for the two distributions given by the type of random number generator of the current instance and the generator given by "rv". | |
virtual double | logLikelihood (const std::vector< T > &x) const |
Calculate the log likelihood of the values in "x". | |
void | setMonteCarlo (unsigned N=10000) |
Sets the maximum number of trials for Monte Carlo simulations. | |
Protected Member Functions | |
RandomVar (RNG &r=RNG::globalRng) | |
Creates a new pseudo random generator instance, by using the generator "r" of class RNG and presets the number of Monte Carlo trials to "10000" (see setMonteCarlo). | |
Protected Attributes | |
RNG & | rng |
unsigned | monteCarloTrials |
Here the basic operations for all random number generators of library "Rng" are defined, especially for Monte Carlo simulations (see setMonteCarlo).
For the generation of random numbers the generator for uniformally distributed pseudo random numbers as defined in class RNG is used as member of this class.
RandomVar< T >::RandomVar | ( | RNG & | r = RNG::globalRng |
) | [inline, protected] |
Creates a new pseudo random generator instance, by using the generator "r" of class RNG and presets the number of Monte Carlo trials to "10000" (see setMonteCarlo).
Each instance of the template random number generator needs a pseudo random number generator as defined in class RNG. Normally this is only one single instance of RNG named RNG::globalRng. To use the base methods for Monte Carlo simulations (see setMonteCarlo), the number of Monte Carlo trials must be set, too.
r | the pseudo random number generator used for this instance, by default this is the global generator RNG::globalRng |
virtual T RandomVar< T >::operator() | ( | ) | [pure virtual] |
Returns a new random number of the distribution defined by the function in the derived class, i.e. normally the "inverse transformation" of the uniformally distributed pseudo random numbers of the interval (0,1) to the distribution of the derived class takes place here. So, this method is purely virtual and must be overloaded in the derived classes.
Implemented in Bernoulli, Binomial, Cauchy, DiffGeometric, DiscreteUniform, Erlang, Geometric, HyperGeometric, LogNormal, NegExponential, Normal, Poisson, Uniform, and Weibull.
virtual double RandomVar< T >::p | ( | const T & | ) | const [pure virtual] |
Returns the probability of the occurrence of the random number value given as parameter of this method.
This method is purely virtual and must be overloaded in the derived classes, because the probability of the parameter depends on the type of distribution given by the type of random number generator used.
Implemented in Bernoulli, Binomial, Cauchy, DiffGeometric, DiscreteUniform, Erlang, Geometric, HyperGeometric, LogNormal, NegExponential, Normal, Poisson, Uniform, and Weibull.
virtual void RandomVar< T >::seed | ( | long | s | ) | [inline, virtual] |
Initializes the pseudo random number generator with the seed value "s".
The pseudo random number generator as defined in class RNG is initialized by using the value s.
s | initialization (seed) value for the pseudo random number generator |
Reimplemented in Normal.
Assigns the pseudo random number generator instance "r" to the current random number generator instance.
r | pseudo random number generator instance that will be assigned to the current instance |
virtual double RandomVar< T >::entropy | ( | ) | [inline, virtual] |
For a distribution "p" given by the currently used random number generator type, the entropy "H(p)" is calculated.
Say the currently used random number generator gives a distribution , where the number of
is determined by the number of Monte Carlo trials preset by method setMonteCarlo. Then the entropy of
,
is given as
The entropy of a distribution can be thought of in some sense as the surprise index of a random variable associated with that distribution.
Another way to see it is to think about the entropy as the average number of yes/no questions needed to identify the outcome of a random experience.
virtual double RandomVar< T >::KullbackLeibler | ( | const RandomVar< T > & | rv | ) | [inline, virtual] |
Calculates the Kullback-Leibler distance for the two distributions given by the type of random number generator of the current instance and the generator given by "rv".
Say the currently used random number generator gives a distribution and rv gives the distribution
, where the number of
is determined by the number of Monte Carlo trials preset by method setMonteCarlo. Then the Kullback-Leibler distance between
and
, also known as divergence or relative entropy is given as
rv | the second random number generator used for the distribution ![]() |
virtual double RandomVar< T >::logLikelihood | ( | const std::vector< T > & | x | ) | const [inline, virtual] |
Calculate the log likelihood of the values in "x".
The log likelihood for a data vector
with length
is given as
where is the probability of the occurrence of
.
x | vector of data values for which the log likelihood will be calculated |
void RandomVar< T >::setMonteCarlo | ( | unsigned | N = 10000 |
) | [inline] |
Sets the maximum number of trials for Monte Carlo simulations.
The Monte Carlo simulation is an analytical method for the imitation of a real-life system when other analyses are too mathematically complex or too difficult to produce.
Therefore the Monte Carlo simulation randomly generates values for uncertain variables over and over to simulate a model.
The Monte Carlo simulation was named for Monte Carlo in Monaco where the primary attractions are casinos containing games of chance. The random behaviour in games of chance is similar to how Monte Carlo simulation selects variable values at random to simulate a model. In a casino you have the same situation as in a Monte Carlo simulation, where you have variables that have a known range of values but an uncertain value for any particular time or event.
For each uncertain variable you define the possible values with a probability distribution. This distributions are defined by the several types of random number generators defined in this library.
Given a certain distribution, the simulation will calculate multiple scenarios of a model by repeatedly sampling values from the probability distributions for the uncertain variables.
Setting the maximum number of Monte Carlo trials is used for the definition of a distribution for the calculation of the entropy and the calculation of the KullbackLeibler distance for two distributions, where one element of a distribution is chosen by the type of random number generator.
N | the maximum number of trials for the simulation, by default set to "10000". |
The pseudo random number generator taken from class RNG. This generator will produce uniformally distributed random numbers of the interval (0,1), that must be transformed to the distribution type of the derived class.
unsigned RandomVar< T >::monteCarloTrials [protected] |
The number of Monte Carlo Trials used for defining a distribution. For details see setMonteCarlo, entropy, KullbackLeibler.