Erlang Class Reference

This class simulates an "%Erlang distribution". More...

#include <Erlang.h>

Inheritance diagram for Erlang:

RandomVar< double >

List of all members.

Public Member Functions

 Erlang (double mean=0, double variance=1)
 Creates a new Erlang random generator instance and initializes the mean value and the variance of the distribution.
 Erlang (double mean, double variance, RNG &r)
 Creates a new Erlang random generator instance by using the pseudo random number generator "r" for the determination of random values and initializes the mean value and the variance of the distribution.
double mean () const
 Returns the current mean value of the distribution as stored in pMean.
double variance () const
 Returns the current variance of the distribution as stored in pVariance.
void mean (double newMean)
 Sets the current mean value of the distribution as stored in pMean to the new value "newMean".
void variance (double newVar)
 Sets the current variance of the distribution as stored in pVariance to the new value "newVar".
double operator() (unsigned k, double a)
 Returns an Erlang random number for the distribution with order "k" and scale factor "a".
double operator() ()
 Returns an Erlang random number for the distribution with order and scale factor that are calculated from the preset mean value pMean and variance pVariance.
double p (const double &) const
 Returns the probability for the occurrence of random number "x" for the Erlang distribution with order and scale factor calculated from the preset mean value pMean and variance pVariance.

Protected Attributes

double pMean
double pVariance


Detailed Description

This class simulates an "%Erlang 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" of the Erlang distribution.
The Erlang distribution is more practical than the (Negative) Exponential distribution, taking into account, that many processes need a minimum time. For this, the Erlang distribution has an additional parameter $k = 1,2,3,...$, known as "the order" of the distribution. For every $k$ there is an Erlang distribution, with the orders $k=1,2,3$ being relevant in practice.
The greater $k$ the more improbable are short times and the less the standard deviation is.
For $k = 1$ the Erlang distribution is identical to the (Negative) Exponential distribution (see NegExponential).
The Erlang distribution is given by:

$ f(x) = (k \cdot \alpha)^k \cdot x^{(k - 1)} \cdot e^{-k \alpha x} $

for the scale $\alpha > 0$ and the order $k > 0$.
Below you can see the distribution for the parameter $\alpha = 0.5$ for the distributions with the orders $k = 1, 2, 3$:

erlang.png

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

Constructor & Destructor Documentation

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

Creates a new Erlang random generator instance and initializes the mean value and the variance of the distribution.

Creates a new Erlang random generator instance and initializes the mean value and the variance of the distribution.

The distribution's mean value $\mu$, that is stored in pMean is initialized by mean and the distribution's variance $\sigma^2$, that is stored in pVariance is initialized by variance.
Then the mean value and the variance are used to calculate the distribution's order $k$ by $k = \frac{\mu^2}{\sigma^2+0.5}$ and the distribution's scale factor $\alpha$ by $\alpha = \frac{k}{\mu}$.
$k$ will always be an integer value $\geq 1$ and $\alpha$ will always be a real number $> 0$.
If you are calling this constructor with the default values mean = 0 and variance = 1, then the distribution's order will be the default value $k = 1$ and the scale factor will be the default value $\alpha = 0.5$.
For this instance, the default pseudo random number generator as member of class RandomVar is used.

Parameters:
mean the initial value for the distribution's mean value $\mu$ from which the distribution's parameters $k$ and $\alpha$ are calculated. The default mean value is zero. If you use a mean value less than or equal to zero, the distribution's scale factor $\alpha$ will be set to "0.5"
variance the initial value for the distribution's variance $\sigma^2$ from which the distribution's parameters $k$ and $\alpha$ are calculated. The default variance is "1"
Returns:
none
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

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

Creates a new Erlang random generator instance by using the pseudo random number generator "r" for the determination of random values and initializes the mean value and the variance of the distribution.

Creates a new Erlang random generator instance by using the pseudo random number generator "r" for the determination of random values and initializes the mean value and the variance of the distribution.

Each instance of an Erlang 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 distribution's mean value $\mu$, that is stored in pMean is initialized by mean and the distribution's variance $\sigma^2$, that is stored in pVariance is initialized by variance.
Then the mean value and the variance are used to calculate the distribution's order $k$ by $k = \frac{\mu^2}{\sigma^2+0.5}$ and the distribution's scale factor $\alpha$ by $\alpha = \frac{k}{\mu}$.
$k$ will always be an integer value $\geq 1$ and $\alpha$ will always be a real number $> 0$.

Parameters:
mean the initial value for the distribution's mean value $\mu$ from which the distribution's parameters $k$ and $\alpha$ are calculated. If you use a mean value less than or equal to zero, the distribution's scale factor $\alpha$ will be set to "0.5"
variance the initial value for the distribution's variance $\sigma^2$ from which the distribution's parameters $k$ and $\alpha$ are 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

double Erlang::mean (  )  const [inline]

Returns the current mean value of the distribution as stored in pMean.

Returns:
the current mean value $\mu$ (pMean)
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

double Erlang::variance (  )  const [inline]

Returns the current variance of the distribution as stored in pVariance.

Returns:
the current variance $\sigma^2$ (pVariance)
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

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

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

The distribution's mean value $\mu$ is set to newMean and then the distribution's order $k$ and scale factor $\alpha$ are recalculated, because this calculation is based on the mean value.
The distribution's order $k$ is defined by $k = \frac{\mu^2}{\sigma^2+0.5}$, where $\sigma^2$ is the distribution's variance as stored in pVariance. The mean value is also used to calculate the scale factor $\alpha$ by $\alpha = \frac{k}{\mu}$.
$k$ will always be an integer value $\geq 1$ and $\alpha$ will always be a real number $> 0$.

Parameters:
newMean the new value for the distribution's mean value $\mu$ (pMean). If newMean is less than or equal to zero then the distribution's scale factor $\alpha$ is set to "0.5"
Returns:
none
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

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

Sets the current variance of the distribution as stored in pVariance to the new value "newVar".

The distribution's mean value $\sigma^2$ is set to newVar and then the distribution's order $k$ and scale factor $\alpha$ are recalculated, because this calculation is based on the variance.
The distribution's order $k$ is defined by $k = \frac{\mu^2}{\sigma^2+0.5}$, where $\mu$ is the distribution's mean value as stored in pMean. This order is then used to calculate the scale factor $\alpha$ by $\alpha = \frac{k}{\mu}$.
$k$ will always be an integer value $\geq 1$ and $\alpha$ will always be a real number $> 0$.

Parameters:
newVar the new value for the distribution's variance $\sigma^2$ (pVariance)
Returns:
none
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

double Erlang::operator() ( unsigned  k,
double  a 
)

Returns an Erlang random number for the distribution with order "k" and scale factor "a".

Returns an Erlang random number for the distribution with order "k" and scale factor "a".

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 Erlang distribution.

Parameters:
k the distribution's order. k must be greater than zero, otherwise "0." will be returned
a the distribution's scale $\alpha$. a must be greater than zero, otherwise "0." will be returned
Returns:
a random number for the Erlang distribution with order k and scale factor a
Author:
M. Kreutz
Date:
1995-01-01
Changes
2002-04-16, ra:
Now checks the distribution's parameters "k" and "a" for validity (both must be greater than zero) and returns zero if at least one parameter is not valid.
Status
stable

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

Returns an Erlang random number for the distribution with order and scale factor that are calculated from the preset mean value pMean and variance pVariance.

Returns an Erlang random number for the distribution with order and scale factor that are calculated from the preset mean value pMean and variance pVariance.

The mean value $\mu$as stored in pMean and the variance $\sigma^2$as stored in pVariance are used to calculate the distribution's order $k$ by $k = \frac{\mu^2}{\sigma^2+0.5}$ and the distribution's scale factor $\alpha$ by $\alpha = \frac{k}{\mu}$.
$k$ will always be an integer value $\geq 1$ and $\alpha$ will always be a real number $> 0$.
If you are calling this operator with a preset mean value $\mu \leq 0$, then the distribution's order will be the default value $k = 1$ and the scale factor will be the default value $\alpha = 0.5$.

Returns:
a random number for the Erlang distribution with order and scale factor based on pMean and pVariance
Author:
M. Kreutz
Date:
1995-01-01
Changes
2002-04-16, ra:
Now checks the distribution's parameters "k" and "a" for validity (both must be greater than zero) and returns zero if at least one parameter is not valid.
Status
stable

Implements RandomVar< double >.

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

Returns the probability for the occurrence of random number "x" for the Erlang distribution with order and scale factor calculated from the preset mean value pMean and variance pVariance.

Returns the probability for the occurrence of random number "x" for the Erlang distribution with order and scale factor calculated from the preset mean value pMean and variance pVariance.

The mean value $\mu$as stored in pMean and the variance $\sigma^2$ as stored in pVariance are used to calculate the distribution's order $k$ by $k = \frac{\mu^2}{\sigma^2+0.5}$ and the distribution's scale factor $\alpha$ by $\alpha = \frac{k}{\mu}$.
$k$ will always be an integer value $\geq 1$ and $\alpha$ will always be a real number $> 0$.
If you are calling this method with a preset mean value $\mu \leq 0$, then the distribution's order will be the default value $k = 1$ and the scale factor will be the default value $\alpha = 0.5$.
For the Erlang distribution with the calculated mean value and variance, the occurrence probability of random number x is then returned.

Returns:
x the random number for which the occurrence probability is returned. If x is less than zero the probability "0." will be returned
Author:
M. Kreutz
Date:
1995-01-01
Changes
2002-04-16, ra:
Was just a dummy method before. Now it really calculates the probability.
Status
stable

Implements RandomVar< double >.


Member Data Documentation

double Erlang::pMean [protected]

The distribution's mean value $\mu$, that is used to calculate the distribution's order $k$ by $k = \frac{\mu^2}{\sigma^2+0.5}$, where $\sigma^2$ is the distribution's variance as stored in pVariance. The mean value is also used to calculate the scale factor $\alpha$ by $\alpha = \frac{k}{\mu}$.

double Erlang::pVariance [protected]

The distribution's variance value $\sigma^2$, that is used to calculate the distribution's order $k$ by $k = \frac{\mu^2}{\sigma^2+0.5}$, where $\mu$ is the distribution's mean value as stored in pMean. Because the scale factor $\alpha$ is calculated by $\alpha = \frac{k}{\mu}$, the variance is also used for the calculation of this factor.


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

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