HyperGeometric Class Reference

This class simulates a "Hyper %Geometric distribution". More...

#include <HyperGeometric.h>

Inheritance diagram for HyperGeometric:

RandomVar< double >

List of all members.

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 $p = \frac{N_1}{N}$ that is calculated from the preset mean value pMean and variance pVariance.
double p (const double &) const
 Just a dummy method to allow instantiation of the class.

Protected Attributes

double pMean
double pVariance


Detailed Description

This class simulates a "Hyper %Geometric 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 Hyper Geometric distribution.
The Hyper Geometric distribution is used, when you have two types of events. Guess, the number of events of type $T_1$ is $N_1$ and the number of events of type $T_2$ is $N_2$, so we have a total number $N = N_1 + N_2$ of events. Guess also, that we define the probability $p$ as the relation of the number of events of type $T_1$ to the total number of events ($p = \frac{N_1}{N}$). Then the distribution is given by

$ P(k) = {pN \choose k} {N(1 - p) \choose n - k} / {N \choose k} $

with $p \cdot N$ and $N \cdot (1 - p)$ being always integer values. $P(k)$ calculates the probability, that you have $k$ events of type $T_1$ in a sample of size $n \leq N$.
In contrast to the Binomial distribution, the Hyper Geometric distribution takes into account, that probability $p$ changes after each of the $n$ 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.

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

Constructor & Destructor Documentation

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 $\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 probability $p = \frac{N_1}{N}$ by $p = \frac{1}{2} \cdot (1 - \sqrt{\frac{\sigma^2 / \mu^2 - 1}{\sigma^2 / \mu^2 + 1}})$.
$p$ will always be a value $\geq 0$.
If you are calling this constructor with the default values mean = 0 and variance = 1, then the probability $p$ will be the default value $p = 0.$.
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 probability $p$ is calculated. The default mean value is zero. If you use a mean value less than or equal to zero, the probability $p$ will be set to "0."
variance the initial value for the distribution's variance $\sigma^2$ from which the probability $p$ is calculated. The default variance is "1"
Returns:
none
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

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 $\sigma^2$, that is stored in pVariance is initialized by variance.
Then the mean value and the variance are used to calculate the probability $p = \frac{N_1}{N}$ by $p = \frac{1}{2} \cdot (1 - \sqrt{\frac{\sigma^2 / \mu^2 - 1}{\sigma^2 / \mu^2 + 1}})$.
$p$ will always be a value $\geq 0$.

Parameters:
mean the initial value for the distribution's mean value $\mu$ from which the probability $p$ is calculated. If you use a mean value less than or equal to zero, the probability $p$ will be set to "0."
variance the initial value for the distribution's variance $\sigma^2$ from which the probability $p$ 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

double HyperGeometric::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 HyperGeometric::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 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 $\mu$ is set to newMean and then the probability $p = \frac{N_1}{N}$ is recalculated by $p = \frac{1}{2} \cdot (1 - \sqrt{\frac{\sigma^2 / \mu^2 - 1}{\sigma^2 / \mu^2 + 1}})$, where $\sigma^2$ is the distribution's variance as stored in pVariance.

Parameters:
newMean the new value for the distribution's mean value $\mu$ (pMean)
Returns:
none
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

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 $\sigma^2$ is set to newVar and then the probability $p = \frac{N_1}{N}$ is recalculated by $p = \frac{1}{2} \cdot (1 - \sqrt{\frac{\sigma^2 / \mu^2 - 1}{\sigma^2 / \mu^2 + 1}})$, where $\mu$ is the distribution's mean value as stored in pMean.

Parameters:
newVariance 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 HyperGeometric::operator() (  )  [virtual]

Returns a Hyper Geometric random number for the distribution with a probability $p = \frac{N_1}{N}$ that is calculated from the preset mean value pMean and variance pVariance.

Returns a Hyper Geometric random number for the distribution with a probability $p = \frac{N_1}{N}$ that is 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 probability $p = \frac{N_1}{N}$ by $p = \frac{1}{2} \cdot (1 - \sqrt{\frac{\sigma^2 / \mu^2 - 1}{\sigma^2 / \mu^2 + 1}})$.
$p$ will always be a value $\geq 0$.
If you are calling this operator with a preset mean value $\mu \leq 0$, then the probability $p$ will be the default value $p = 0.$.

Returns:
a random number for the Hyper Geometric distribution with a probability $p$ based on pMean and pVariance
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

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.

Parameters:
x has no function here
Returns:
always "0."
Author:
M. Kreutz
Date:
1995-01-01
Changes
none
Status
stable

Implements RandomVar< double >.


Member Data Documentation

double HyperGeometric::pMean [protected]

The distribution's mean value $\mu$, that is used to calculate the probability $p = \frac{N_1}{N}$ by $p = \frac{1}{2} \cdot (1 - \sqrt{\frac{\sigma^2 / \mu^2 - 1}{\sigma^2 / \mu^2 + 1}})$, where $\sigma^2$ is the distribution's variance as stored in pVariance.

double HyperGeometric::pVariance [protected]

The distribution's variance $\sigma^2$, that is used to calculate probability $p = \frac{N_1}{N}$ by $p = \frac{1}{2} \cdot (1 - \sqrt{\frac{\sigma^2 / \mu^2 - 1}{\sigma^2 / \mu^2 + 1}})$, where $\mu$ is the distribution's mean value as stored in pMean.


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

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