RandomVar< T > Class Template Reference

Template class used as base for all random number generators of library "#Rng". More...

#include <RandomVar.h>

List of all members.

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".
RandomVaroperator= (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

RNGrng
unsigned monteCarloTrials


Detailed Description

template<class T>
class RandomVar< T >

Template class used as base for all random number generators of library "#Rng".

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.

Author:
M. Kreutz
Date:
1998-08-17
Changes:
none
Status:
stable
See also:
setMonteCarlo

Constructor & Destructor Documentation

template<class T>
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.

Parameters:
r the pseudo random number generator used for this instance, by default this is the global generator RNG::globalRng
Returns:
none
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable
See also:
entropy, KullbackLeibler


Member Function Documentation

template<class T>
virtual T RandomVar< T >::operator() (  )  [pure virtual]

Returns a new random number of the distribution defined by the function $F(X)$ 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.

template<class T>
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.

template<class T>
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.

Parameters:
s initialization (seed) value for the pseudo random number generator
Returns:
none
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

Reimplemented in Normal.

template<class T>
RandomVar& RandomVar< T >::operator= ( const RandomVar< T > &  r  )  [inline]

Assigns the pseudo random number generator instance "r" to the current random number generator instance.

Parameters:
r pseudo random number generator instance that will be assigned to the current instance
Returns:
reference to the current pseudo random number generator instance after the assignment
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

template<class T>
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 $p = \{p(x): x \in \chi\}$, where the number of $x$ is determined by the number of Monte Carlo trials preset by method setMonteCarlo. Then the entropy of $p$, $H(p)$ is given as

$ H(p) = - \sum_{x \in \chi} p(x) \cdot \log {p(x)} = E_p [- \log {p(X)}] $

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.

Returns:
the entropy of the given distribution, $H(p)$
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable
See also:
setMonteCarlo

template<class T>
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 $p = \{p(x): x \in \chi\}$ and rv gives the distribution $q = \{q(x): x \in \chi\}$, where the number of $x$ is determined by the number of Monte Carlo trials preset by method setMonteCarlo. Then the Kullback-Leibler distance between $p$ and $q$, also known as divergence or relative entropy is given as

$ D(p,q) = \sum_{x \in \chi} p(x) \cdot \log {\frac{p(x)}{q(x)}} = E_p \big[ \log {\frac{p(X)}{q(X)}}\big] = E_p [ \mbox{log likelihood ratio} ] $

Parameters:
rv the second random number generator used for the distribution $q$.
Returns:
the Kullback-Leibler distance between $p$ and $q$
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable
See also:
setMonteCarlo

template<class T>
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 $l$ for a data vector $x$ with length $k$ is given as

$ l = \sum_{i=1}^k \log {P( x_i )} $

where $P( x_i )$ is the probability of the occurrence of $x_i$.

Parameters:
x vector of data values for which the log likelihood will be calculated
Returns:
the log likelihood of the data vector x
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

template<class T>
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.

Parameters:
N the maximum number of trials for the simulation, by default set to "10000".
Returns:
none
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable
See also:
entropy, KullbackLeibler


Member Data Documentation

template<class T>
RNG& RandomVar< T >::rng [protected]

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.

template<class T>
unsigned RandomVar< T >::monteCarloTrials [protected]

The number of Monte Carlo Trials used for defining a distribution. For details see setMonteCarlo, entropy, KullbackLeibler.


The documentation for this class was generated from the following file:

Generated on Thu Aug 28 18:34:50 2008 for Dolphin by  doxygen 1.5.6