Normal Class Reference

This class simulates a "normal" distribution. More...

#include <Normal.h>

Inheritance diagram for Normal:

RandomVar< double > LogNormal

List of all members.

Public Member Functions

 Normal (double mean=0, double variance=1)
 Creates a new instance of the normal random number generator, initializes the range of the numbers and internal variables.
 Normal (double mean, double variance, RNG &r)
 Creates a new normal random generator instance by using the pseudo random number generator "r" for the determination of random values and initializes the range of the numbers and internal variables.
void seed (long s)
 Initializes the pseudo random number generator used by this class with value "s".
double mean () const
 Returns the current mean value pMean of the random numbers distribution.
double variance () const
 Returns the current variance of the random numbers distribution.
void mean (double newMean)
 Sets the current mean value pMean of the distribution to the new value "newMean".
void variance (double newVar)
 Sets the current variance of the distribution to the new value "newVar".
double operator() (double mean, double variance)
 Returns a normally distributed random number for the distribution with mean value "mean" and variance "variance".
double operator() ()
 Returns a normally distributed random number for the distribution with mean value and standard deviation given in pMean and pStdDev.
double p (const double &) const
 Returns the probability for the occurrence of "x" for a normal distribution with given mean value pMean and standard deviation pStdDev.

Protected Attributes

double pMean
 The mean value $\mu$ of the normal distribution.
double pStdDev
 The standard deviation $\sigma$ of the distribution.


Detailed Description

This class simulates a "normal" distribution.

This class is derived from class RandomVar and the uniformally distributed pseudo random number values of the interval (0,1) are transformed to type "double", simulating the normal or gaussian distribution with the equation:

$ f(x) = \frac{1}{\sqrt{2 \pi \sigma^2}} \cdot exp \left(- \frac{(x- \mu)^2}{2 \sigma^2}\right) $

where $\mu$ is the mean value or peak of the distribution curve, stored in pMean and $\sigma$ is the distribution's standard deviation, stored in pStdDev.
Because the used "real" random generator produces uniformally distributed numbers, the Box-Müller method is used to create two 2-dimensional standard normally distributed random numbers from two 2-dimensional uniformally distributed random numbers between $0$ and $1$.
One of the generated normally distributed numbers is then returned and the other one is stored for the next time.
For details about the Box-Müller method please refer to "Simulation, Modelling & Analysis" by Law & Kelton, pp. 259.
Below you can see the distribution for the standard normal distribution with $\mu = 0$ and $\sigma = 1$:

normal.png

Author:
M. Kreutz
Date:
1995-01-01
Changes:
none
Status:
stable

Constructor & Destructor Documentation

Normal::Normal ( double  mean = 0,
double  variance = 1 
)

Creates a new instance of the normal random number generator, initializes the range of the numbers and internal variables.

Creates a new instance of the normal random number generator, initializes the range of the numbers and internal variables.

The mean value pMean and the standard deviation pStdDev of the distribution are initialized, where $pStdDev = \sqrt{\mbox{variance}}$.
Internal variables are also initialized to allow proper working.
For this instance, the default pseudo random number generator as member of class RandomVar is used.

Parameters:
mean the mean value of the gaussian distribution, the default is "0" for the standard distribution
variance the variance of the gaussian distribution, the default is "1" for the standard distribution
Returns:
none
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

Normal::Normal ( double  mean,
double  variance,
RNG r 
)

Creates a new normal random generator instance by using the pseudo random number generator "r" for the determination of random values and initializes the range of the numbers and internal variables.

Creates a new normal random generator instance by using the pseudo random number generator "r" for the determination of random values and initializes the range of the numbers and internal variables.

Each instance of a normal random number generator is based on a generator, that is defined in class RNG and returns uniformally pseudo random numbers of the interval (0,1). By default, this is a global generator named RNG::globalRng and included as member in class RandomVar.
Here another pseudo random number generator r is used instead.
Additionally to defining the used pseudo random number generator, the mean value and the standard deviation of the distribution and internal variables are initialized.

Parameters:
mean the mean value pMean of the gaussian distribution
variance the variance of the gaussian distribution from which the standard deviation pStdDev as $pStdDev = \sqrt{\mbox{variance}}$ is calculated
r the pseudo random number generator that is used
Returns:
none
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable


Member Function Documentation

void Normal::seed ( long  s  )  [inline, virtual]

Initializes the pseudo random number generator used by this class with value "s".

The pseudo random number generator as defined in class RNG is initialized by using the seed value s.
Additionally, an internal variable is initialized to allow proper working.

Parameters:
s initialization value for the pseudo random number generator
Returns:
none
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable
See also:
RandomVar::seed

Reimplemented from RandomVar< double >.

double Normal::mean (  )  const [inline]

Returns the current mean value pMean of the random numbers distribution.

Returns:
the mean value $\mu$ as stored in pMean
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

Reimplemented in LogNormal.

double Normal::variance (  )  const [inline]

Returns the current variance of the random numbers distribution.

The variance $V(X)$ is calculated from the standard deviation $\sigma$ as stored in pStdDev by

$ V(X) = \sigma^2 $

Returns:
the variance $V(X)$
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

Reimplemented in LogNormal.

void Normal::mean ( double  newMean  )  [inline]

Sets the current mean value pMean of the distribution to the new value "newMean".

Parameters:
newMean the new mean value for the distribution
Returns:
none
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

Reimplemented in LogNormal.

void Normal::variance ( double  newVar  )  [inline]

Sets the current variance of the distribution to the new value "newVar".

The variance $V(X)$ is set to the new value "newVar" and from this the new standard deviation $\sigma$ is calculated as $\sigma = \sqrt{V(X)}$ and stored in pStdDev.

Parameters:
newVar the new variance of the distribution
Returns:
none
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

Reimplemented in LogNormal.

double Normal::operator() ( double  mean,
double  variance 
)

Returns a normally distributed random number for the distribution with mean value "mean" and variance "variance".

Returns a normally distributed random number for the distribution with mean value "mean" and variance "variance".

For the generation of the random number the Box-Müller method is used as described in the class description.
Besides the random number returned at once, a second random number is stored in an internal variable. The next time calling this method, this stored number is returned.

Returns:
the generated normally distributed random number
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

Reimplemented in LogNormal.

double Normal::operator() (  )  [virtual]

Returns a normally distributed random number for the distribution with mean value and standard deviation given in pMean and pStdDev.

Returns a normally distributed random number for the distribution with mean value and standard deviation given in pMean and pStdDev.

This method performs the inverse transformation of the original uniformally distributed random numbers of the interval (0,1) created by the used pseudo random number generator to the type of the normal distribution.
For the transformation of the random number the Box-Müller method is used as described in the class description.
Besides the random number returned at once, a second random number is stored in an internal variable. The next time calling this method, this stored number is returned.

Returns:
the generated normally distributed random number
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

Implements RandomVar< double >.

Reimplemented in LogNormal.

double Normal::p ( const double &  x  )  const [virtual]

Returns the probability for the occurrence of "x" for a normal distribution with given mean value pMean and standard deviation pStdDev.

Returns the probability for the occurrence of "x" for a normal distribution with given mean value pMean and standard deviation pStdDev.

Parameters:
x the value for which the occurrence probability will be returned
Returns:
the occurrence probability for x
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

Implements RandomVar< double >.

Reimplemented in LogNormal.


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

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