#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. the number of hits in "n" trials, with a probability of "p" for a single hit. | |
long | operator() () |
Returns a binomial random number, i.e. the number of hits in pN trials, with a probability of pP for a single hit. | |
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 |
double | pP |
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:
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 |
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 |
double Binomial::pp | ( | ) | const [inline] |
void Binomial::pp | ( | double | newP | ) | [inline] |
unsigned Binomial::n | ( | ) | const [inline] |
void Binomial::n | ( | unsigned | newN | ) | [inline] |
long Binomial::operator() | ( | unsigned | n, | |
double | p | |||
) |
Returns a binomial random number, i.e. the number of hits in "n" trials, with a probability of "p" for a single hit.
Returns a binomial random number, i.e. 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 |
long Binomial::operator() | ( | ) | [virtual] |
Returns a binomial random number, i.e. the number of hits in pN trials, with a probability of pP for a single hit.
Returns a binomial random number, i.e. the number of hits in pN trials, with a probability of pP for a single hit.
Implements RandomVar< long >.
double Binomial::p | ( | const long & | x | ) | const [virtual] |
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 |
Implements RandomVar< long >.
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 ![]() |
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 ![]() | |
p | the probability for a single hit, i.e. the value of ![]() ![]() | |
x | the number of hits, i.e. the value of ![]() |
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 ![]() ![]() | |
x | the value of ![]() ![]() |
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 |
unsigned Binomial::pN [protected] |
The number of trials, i.e. the value in the Bernoulli formula
.
double Binomial::pP [protected] |
The probability for a "hit", i.e. the value in the Bernoulli formula
.