shark::Bernoulli< RngType > Class Template Reference

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

#include <shark/Rng/Bernoulli.h>

+ Inheritance diagram for shark::Bernoulli< RngType >:

Public Member Functions

 Bernoulli (RngType &rng, double prob=0.5)
 
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". More...
 
double prob () const
 Returns the probability for the occurrence of an event. More...
 
void prob (double newP)
 Sets the probability for the occurrence of an event to "newP". More...
 
double p (bool x) const
 

Detailed Description

template<typename RngType = shark::DefaultRngType>
class shark::Bernoulli< RngType >

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

This class is a thin wrapper for the boost::bernoulli_distribution class. A bernoulli distribution simulates a generalized coin toss. 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
O.Krause
Date
2010-01-01
Changes:
none
Status:
testing

Definition at line 65 of file Bernoulli.h.

Constructor & Destructor Documentation

◆ Bernoulli()

template<typename RngType = shark::DefaultRngType>
shark::Bernoulli< RngType >::Bernoulli ( RngType &  rng,
double  prob = 0.5 
)
inline

Creates a new Bernoulli random generator using the global generator from instance and sets the probability for the occurrence of the event to "prob". Creates a new Bernoulli random generator instance by using the pseudo random number generator "rng" for the determination of random values and sets the probability for the occurrence of the event to "prob".

Definition at line 82 of file Bernoulli.h.

Member Function Documentation

◆ operator()()

template<typename RngType = shark::DefaultRngType>
bool shark::Bernoulli< RngType >::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".

Returns
a bernoulli distributed number

Definition at line 101 of file Bernoulli.h.

◆ p()

template<typename RngType = shark::DefaultRngType>
double shark::Bernoulli< RngType >::p ( bool  x) const
inline

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

Definition at line 129 of file Bernoulli.h.

References shark::Bernoulli< RngType >::prob().

◆ prob() [1/2]

template<typename RngType = shark::DefaultRngType>
double shark::Bernoulli< RngType >::prob ( ) const
inline

Returns the probability for the occurrence of an event.

Returns
the probability for the occurrence of an event

Definition at line 111 of file Bernoulli.h.

Referenced by shark::Bernoulli< RngType >::p().

◆ prob() [2/2]

template<typename RngType = shark::DefaultRngType>
void shark::Bernoulli< RngType >::prob ( double  newP)
inline

Sets the probability for the occurrence of an event to "newP".

Parameters
newPthe new probability for the occurrence of an event
Returns
none

Definition at line 121 of file Bernoulli.h.


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