#include <Normal.h>
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 ![]() | |
double | pStdDev |
The standard deviation ![]() |
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:
where is the mean value or peak of the distribution curve, stored in pMean and
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 and
.
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 and
:
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 .
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.
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 |
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.
mean | the mean value pMean of the gaussian distribution | |
variance | the variance of the gaussian distribution from which the standard deviation pStdDev as ![]() | |
r | the pseudo random number generator that is used |
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.
s | initialization value for the pseudo random number generator |
Reimplemented from RandomVar< double >.
double Normal::mean | ( | ) | const [inline] |
double Normal::variance | ( | ) | const [inline] |
void Normal::mean | ( | double | newMean | ) | [inline] |
void Normal::variance | ( | double | newVar | ) | [inline] |
Sets the current variance of the distribution to the new value "newVar".
The variance is set to the new value "newVar" and from this the new standard deviation
is calculated as
and stored in pStdDev.
newVar | the new variance of the distribution |
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.
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.
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.
x | the value for which the occurrence probability will be returned |
Implements RandomVar< double >.
Reimplemented in LogNormal.