#include <HyperGeometric.h>
Public Member Functions | |
HyperGeometric (double mean=0, double variance=1) | |
Creates a new Hyper Geometric random generator instance and initializes the mean value and the variance of the distribution. | |
HyperGeometric (double mean, double variance, RNG &r) | |
Creates a new Hyper Geometric 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() () |
Returns a Hyper Geometric random number for the distribution with a probability ![]() | |
double | p (const double &) const |
Just a dummy method to allow instantiation of the class. | |
Protected Attributes | |
double | pMean |
double | pVariance |
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 Hyper Geometric distribution.
The Hyper Geometric distribution is used, when you have two types of events. Guess, the number of events of type is
and the number of events of type
is
, so we have a total number
of events. Guess also, that we define the probability
as the relation of the number of events of type
to the total number of events (
). Then the distribution is given by
with and
being always integer values.
calculates the probability, that you have
events of type
in a sample of size
.
In contrast to the Binomial distribution, the Hyper Geometric distribution takes into account, that probability changes after each of the
trials.
Taking the "urn model", the Hyper Geometric distribution simulates the drawing of balls from the urn without returning the drawn balls to the urn.
HyperGeometric::HyperGeometric | ( | double | mean = 0 , |
|
double | variance = 1 | |||
) |
Creates a new Hyper Geometric random generator instance and initializes the mean value and the variance of the distribution.
Creates a new Hyper Geometric random generator instance and initializes the mean value and the variance of the distribution.
The distribution's mean value , that is stored in pMean is initialized by mean and the distribution's variance
, that is stored in pVariance is initialized by variance.
Then the mean value and the variance are used to calculate the probability by
.
will always be a value
.
If you are calling this constructor with the default values mean = 0 and variance = 1, then the probability will be the default value
.
For this instance, the default pseudo random number generator as member of class RandomVar is used.
mean | the initial value for the distribution's mean value ![]() ![]() ![]() | |
variance | the initial value for the distribution's variance ![]() ![]() |
HyperGeometric::HyperGeometric | ( | double | mean, | |
double | variance, | |||
RNG & | r | |||
) |
Creates a new Hyper Geometric 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 Hyper Geometric 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 a Hyper Geometric 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, that is stored in pMean is initialized by mean and the distribution's variance , that is stored in pVariance is initialized by variance.
Then the mean value and the variance are used to calculate the probability by
.
will always be a value
.
mean | the initial value for the distribution's mean value ![]() ![]() ![]() | |
variance | the initial value for the distribution's variance ![]() ![]() | |
r | the pseudo random number generator that is used |
double HyperGeometric::mean | ( | ) | const [inline] |
double HyperGeometric::variance | ( | ) | const [inline] |
void HyperGeometric::mean | ( | double | newMean | ) |
Sets the current mean value of the distribution as stored in pMean to the new value "newMean".
Sets the current mean value of the distribution as stored in pMean to the new value "newMean".
The distribution's mean value is set to newMean and then the probability
is recalculated by
, where
is the distribution's variance as stored in pVariance.
newMean | the new value for the distribution's mean value ![]() |
void HyperGeometric::variance | ( | double | newVariance | ) |
Sets the current variance of the distribution as stored in pVariance to the new value "newVar".
Sets the current variance of the distribution as stored in pVariance to the new value "newVar".
The distribution's variance is set to newVar and then the probability
is recalculated by
, where
is the distribution's mean value as stored in pMean.
newVariance | the new value for the distribution's variance ![]() |
double HyperGeometric::operator() | ( | ) | [virtual] |
Returns a Hyper Geometric random number for the distribution with a probability that is calculated from the preset mean value pMean and variance pVariance.
Returns a Hyper Geometric random number for the distribution with a probability that is calculated from the preset mean value pMean and variance pVariance.
The mean value as stored in pMean and the variance
as stored in pVariance are used to calculate the probability
by
.
will always be a value
.
If you are calling this operator with a preset mean value , then the probability
will be the default value
.
Implements RandomVar< double >.
double HyperGeometric::p | ( | const double & | x | ) | const [virtual] |
Just a dummy method to allow instantiation of the class.
This method, defined as purely virtual in class RandomVar has to be implemented to allow the instantiation of class HyperGeometric.
x | has no function here |
Implements RandomVar< double >.
double HyperGeometric::pMean [protected] |
The distribution's mean value , that is used to calculate the probability
by
, where
is the distribution's variance as stored in pVariance.
double HyperGeometric::pVariance [protected] |
The distribution's variance , that is used to calculate probability
by
, where
is the distribution's mean value as stored in pMean.