#include <Binomial.h>

Public Member Functions | |
| Binomial (unsigned n=1, double p=0.5) | |
| Creates a new instance of the binomial random number generator and initializes values for the Bernoulli formula. | |
| Binomial (unsigned n, double p, RNG &r) | |
| Creates a new binomial random generator instance by using the pseudo random number generator "r" for the determination of random values and initializes values for the Bernoulli formula. | |
| double | pp () const |
| Returns the probability pP for a hit. | |
| void | pp (double newP) |
| Sets the probability pP for a hit to the new value "newP". | |
| unsigned | n () const |
| Returns the number of trials pN. | |
| void | n (unsigned newN) |
| Sets the number of trials pN to the new value "newN". | |
| long | operator() (unsigned n, double p) |
| Returns a binomial random number, i.e. | |
| long | operator() () |
| Returns a binomial random number, i.e. | |
| double | p (const long &) const |
| Just a dummy method that is needed for instantiation of class Binomial. | |
| double | p (const unsigned x) const |
| Returns the probability for "x" hits out of pN trials, when the probability for a single hit is pP. | |
| double | p (const unsigned n, const double p, const unsigned x) const |
| Returns the probability for "x" hits out of "n" trials, when the probability for a single hit is "p". | |
| unsigned | binominalCoefficient (const unsigned n, const unsigned x) const |
| Returns the binomial coefficient "n choose x". | |
| unsigned | factorial (const unsigned tt) const |
| Returns the factorial "tt!". | |
Protected Attributes | |
| unsigned | pN |
| The number of trials, i.e. | |
| double | pP |
| The probability for a "hit", i.e. | |
This class is derived from class RandomVar and the uniformally distributed pseudo random number values of the interval (0,1) are transformed to type "long", indicating the number of "hits" out of a given number of trials with a given probability for a single hit.
The probability for a special number
of hits can also be calculated by using the Bernoulli formula given as

where
is the probability for a single hit,
and
is the total number of trials.
Taking the "urn model", the Binomial distribution simulates the drawing of
balls from the urn with returning the drawn balls to the urn.
Below you can see the distribution for the parameter values
and
and
, respectively:
Definition at line 84 of file Binomial.h.
| Binomial::Binomial | ( | unsigned | n = 1, |
|
| double | p = 0.5 | |||
| ) |
Creates a new instance of the binomial random number generator and initializes values for the Bernoulli formula.
Creates a new instance of the binomial random number generator and initializes values for the Bernoulli formula.
The number of trials pN and the probability for a hit pP for the Bernoulli formula used by the random number generator are initialized.
For this instance, the default pseudo random number generator as member of class RandomVar is used.
| n | the number of trials pN, set to "1" by default | |
| p | the probability pP for a hit, set to "0.5" by default |
Definition at line 73 of file Binomial.cpp.
| Binomial::Binomial | ( | unsigned | n, | |
| double | p, | |||
| RNG & | r | |||
| ) |
Creates a new binomial random generator instance by using the pseudo random number generator "r" for the determination of random values and initializes values for the Bernoulli formula.
Creates a new binomial random generator instance by using the pseudo random number generator "r" for the determination of random values and initializes values for the Bernoulli formula.
Each instance of a binomial 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 number of trials pN and the probability for a hit pP for the Bernoulli formula used by the random number generator are initialized.
| n | the number of trials pN | |
| p | the probability pP for a hit | |
| r | the pseudo random number generator that is used |
Definition at line 110 of file Binomial.cpp.
| unsigned Binomial::binominalCoefficient | ( | const unsigned | n, | |
| const unsigned | x | |||
| ) | const |
Returns the binomial coefficient "n choose x".
The binomial coefficient is here defined as

| n | the value of in | |
| x | the value of in |

Definition at line 313 of file Binomial.cpp.
References factorial().
Referenced by p().
| unsigned Binomial::factorial | ( | const unsigned | tt | ) | const |
Returns the factorial "tt!".
The factorial of tt defined as

| tt | the value of which the factorial is calculated |

Definition at line 346 of file Binomial.cpp.
Referenced by binominalCoefficient().
| void Binomial::n | ( | unsigned | newN | ) | [inline] |
Sets the number of trials pN to the new value "newN".
| newN | the new value for the number of trials pN |
Definition at line 183 of file Binomial.h.
References pN.
| unsigned Binomial::n | ( | ) | const [inline] |
Returns the number of trials pN.
Definition at line 160 of file Binomial.h.
References pN.
| long Binomial::operator() | ( | ) | [virtual] |
Returns a binomial random number, i.e.
Returns a binomial random number, i.e. the number of hits in pN trials, with a probability of pP for a single hit.
the number of hits in pN trials, with a probability of pP for a single hit.
Implements RandomVar< long >.
Definition at line 167 of file Binomial.cpp.
| long Binomial::operator() | ( | unsigned | n, | |
| double | p | |||
| ) |
Returns a binomial random number, i.e.
Returns a binomial random number, i.e. the number of hits in "n" trials, with a probability of "p" for a single hit.
the number of hits in "n" trials, with a probability of "p" for a single hit.
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 binomial distribution.
| n | the number of trials | |
| p | the probability for a single hit |
Definition at line 139 of file Binomial.cpp.
References RandomVar< long >::rng.
| double Binomial::p | ( | const unsigned | n, | |
| const double | p, | |||
| const unsigned | x | |||
| ) | const |
Returns the probability for "x" hits out of "n" trials, when the probability for a single hit is "p".
Returns the probability for "x" hits out of "n" trials, when the probability for a single hit is "p".
The Bernoulli formula, that calculates the probability for x hits out of n trials is here defined as

| n | the number of trials, i.e. the value of in the Bernoulli formula | |
| p | the probability for a single hit, i.e. the value of ( ) in the Bernoulli formula | |
| x | the number of hits, i.e. the value of in the Bernoulli formula |

Definition at line 265 of file Binomial.cpp.
References binominalCoefficient().
| double Binomial::p | ( | const unsigned | x | ) | const |
Returns the probability for "x" hits out of pN trials, when the probability for a single hit is pP.
Returns the probability for "x" hits out of pN trials, when the probability for a single hit is pP.
The Bernoulli formula, that calculates the probability for x hits out of n trials is here defined as

Here, for
and
, the values of pN and pP are used.
| x | the number of hits, i.e. the value of in the Bernoulli formula |

Definition at line 229 of file Binomial.cpp.
| double Binomial::p | ( | const long & | x | ) | const |
Just a dummy method that is needed for instantiation of class Binomial.
Just a dummy method that is needed for instantiation of class Binomial.
To instantiate this class, this dummy method that is declared as purely virtual in class RandomVar, has to be implemented.
| x | not used |
Definition at line 194 of file Binomial.cpp.
Referenced by p().
| void Binomial::pp | ( | double | newP | ) | [inline] |
Sets the probability pP for a hit to the new value "newP".
| newP | the new value for the probability pP |
Definition at line 138 of file Binomial.h.
References pP.
| double Binomial::pp | ( | ) | const [inline] |
Returns the probability pP for a hit.
Definition at line 115 of file Binomial.h.
References pP.
unsigned Binomial::pN [protected] |
The number of trials, i.e.
the value
in the Bernoulli formula
.
Definition at line 219 of file Binomial.h.
Referenced by n(), operator()(), and p().
double Binomial::pP [protected] |
The probability for a "hit", i.e.
the value
in the Bernoulli formula
.
Definition at line 224 of file Binomial.h.
Referenced by operator()(), p(), and pp().