Bernoulli Class Reference

This class simulates a "Bernoulli trial", which is like a coin toss. More...

#include <Bernoulli.h>

Inheritance diagram for Bernoulli:
RandomVar< bool >

List of all members.

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 $p$ for the occurrence of an event ("x = true") or $1 - p$ for the non-occurrence ("x = false").

Protected Attributes

double pP
 The probability $p$ for the occurrence of the event (coin side).

Detailed Description

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".

Author:
M. Kreutz
Date:
1998-08-17
Changes:
none
Status:
stable

Definition at line 76 of file Bernoulli.h.


Constructor & Destructor Documentation

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 $1 - p$.
For this instance, the default pseudo random number generator as member of class RandomVar is used.

Parameters:
p probability for the occurrence of the event
Returns:
none
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

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 $1 - p$.

Parameters:
p probability for the occurrence of the event
r the pseudo random number generator that is used
Returns:
none
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

Definition at line 109 of file Bernoulli.cpp.


Member Function Documentation

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.

Returns:
"true", when the event occurred, "false" otherwise
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

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.

Parameters:
p probability for the occurrence of the event
Returns:
"true", when the event occurred, "false" otherwise
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

Definition at line 162 of file Bernoulli.h.

References RandomVar< bool >::rng.

double Bernoulli::p ( const bool &  x  )  const [virtual]

Returns the probability $p$ for the occurrence of an event ("x = true") or $1 - p$ for the non-occurrence ("x = false").

Parameters:
x if x is "true" then the probability $p$ for the occurrence of the event is returned, otherwise the probability $1 - p$ for the non-occurrence
Returns:
the probability for the (non-)occurrence of the event
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

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".

Parameters:
newP the new probability for the occurrence pP of an event
Returns:
none
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

Definition at line 132 of file Bernoulli.h.

References pP.

double Bernoulli::prob (  )  const [inline]

Returns the probability for the occurrence of an event.

Returns:
the probability pP for the occurrence of an event
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

Definition at line 109 of file Bernoulli.h.

References pP.


Member Data Documentation

double Bernoulli::pP [protected]

The probability $p$ for the occurrence of the event (coin side).

The probability for the non-occurrence of the event is then given by $1 - pP$.

Definition at line 183 of file Bernoulli.h.

Referenced by Bernoulli(), operator()(), p(), and prob().


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