This class simulates a "Bernoulli trial", which is like a coin toss. More...
#include <Bernoulli.h>
Public Member Functions | |
Bernoulli (double p=0.5) | |
Creates a new Bernoulli random generator instance and sets the probability for the occurrence of the event to "p". | |
Bernoulli (double p, RNG &r) | |
Creates a new Bernoulli random generator instance by using the pseudo random number generator "r" for the determination of random values and sets the probability for the occurrence of the event to "p". | |
double | prob () const |
Returns the probability for the occurrence of an event. | |
void | prob (double newP) |
Sets the probability for the occurrence of an event to "newP". | |
bool | operator() (double p) |
Returns a Bernoulli random number, i.e. a "true" or "false" marking the occurrence and non-occurrence of an event respectively, when the probability for the occurrence is "p". | |
bool | operator() () |
Returns a Bernoulli random number, i.e. | |
double | p (const bool &) const |
Returns the probability for the occurrence of an event ("x = true") or for the non-occurrence ("x = false"). | |
Protected Attributes | |
double | pP |
The probability for the occurrence of the event (coin side). |
This class simulates a "Bernoulli trial", which is like a coin toss.
This class is derived from class RandomVar and the uniformally distributed pseudo random number values of the interval (0,1) are transformed to type "bool", because an event (side of a coin) can occur or can not occur.
Therefore a probability for the occurrence of the event (coin side) is defined. When using the equal probability of "0.5" for the occurrence and non-occurrence of the event (coin side), then the event (coin) is named "normal", otherwise it is named "abnormal".
Definition at line 76 of file Bernoulli.h.
Bernoulli::Bernoulli | ( | double | p = 0.5 |
) |
Creates a new Bernoulli random generator instance and sets the probability for the occurrence of the event to "p".
The occurrence probability for the event is set to p, the probability for the non-occurrence is then .
For this instance, the default pseudo random number generator as member of class RandomVar is used.
p | probability for the occurrence of the event |
Definition at line 72 of file Bernoulli.cpp.
References pP.
Bernoulli::Bernoulli | ( | double | p, | |
RNG & | r | |||
) |
Creates a new Bernoulli random generator instance by using the pseudo random number generator "r" for the determination of random values and sets the probability for the occurrence of the event to "p".
Creates a new Bernoulli random generator instance by using the pseudo random number generator "r" for the determination of random values and sets the probability for the occurrence of the event to "p".
Each instance of a Bernoulli 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 occurrence probability for the Bernoulli event is set to p, the probability for the non-occurrence is then .
p | probability for the occurrence of the event | |
r | the pseudo random number generator that is used |
Definition at line 109 of file Bernoulli.cpp.
bool Bernoulli::operator() | ( | ) | [virtual] |
Returns a Bernoulli random number, i.e.
Returns a Bernoulli random number, i.e. a "true" or "false" for the occurrence of an event when using the preset probability pP.
a "true" or "false" for the occurrence of an event when using the preset probability pP.
Implements RandomVar< bool >.
Definition at line 132 of file Bernoulli.cpp.
References pP.
bool Bernoulli::operator() | ( | double | p | ) | [inline] |
Returns a Bernoulli random number, i.e. a "true" or "false" marking the occurrence and non-occurrence of an event respectively, when the probability for the occurrence is "p".
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 Bernoulli distribution.
p | probability for the occurrence of the event |
Definition at line 162 of file Bernoulli.h.
References RandomVar< bool >::rng.
double Bernoulli::p | ( | const bool & | x | ) | const [virtual] |
Returns the probability for the occurrence of an event ("x = true") or for the non-occurrence ("x = false").
x | if x is "true" then the probability for the occurrence of the event is returned, otherwise the probability for the non-occurrence |
Implements RandomVar< bool >.
Definition at line 159 of file Bernoulli.cpp.
References pP.
void Bernoulli::prob | ( | double | newP | ) | [inline] |
Sets the probability for the occurrence of an event to "newP".
newP | the new probability for the occurrence pP of an event |
Definition at line 132 of file Bernoulli.h.
References pP.
double Bernoulli::prob | ( | ) | const [inline] |
Returns the probability for the occurrence of an event.
Definition at line 109 of file Bernoulli.h.
References pP.
double Bernoulli::pP [protected] |
The probability for the occurrence of the event (coin side).
The probability for the non-occurrence of the event is then given by .
Definition at line 183 of file Bernoulli.h.
Referenced by Bernoulli(), operator()(), p(), and prob().