#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 &rng) | |
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. a "true" or "false" for the occurrence of an event when using the preset probability pP. | |
double | p (const bool &) const |
Returns the probability ![]() ![]() | |
Protected Attributes | |
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 "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".
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".
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 |
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 |
double Bernoulli::prob | ( | ) | const [inline] |
Returns the probability for the occurrence of an event.
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 |
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 |
bool Bernoulli::operator() | ( | ) | [virtual] |
Returns a Bernoulli random number, i.e. a "true" or "false" for the occurrence of an event when using the preset probability pP.
Returns a Bernoulli random number, i.e. a "true" or "false" for the occurrence of an event when using the preset probability pP.
Implements RandomVar< bool >.
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").
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 ![]() ![]() |
Implements RandomVar< bool >.
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
.