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

Protected Attributes

double pP


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

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

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

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


Member Function Documentation

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

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

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

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.

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

Implements RandomVar< bool >.

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

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


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


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

Generated on Thu Aug 28 18:34:37 2008 for Dolphin by  doxygen 1.5.6