RandomLib  1.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Public Member Functions | List of all members
RandomLib::ExponentialProb Class Reference

The exponential probability. More...

#include <RandomLib/ExponentialProb.hpp>

Public Member Functions

 ExponentialProb ()
 
template<typename RealType , class Random >
bool operator() (Random &r, RealType p) const
 

Detailed Description

The exponential probability.

Return true with probability exp(−p). Basic method taken from:
J. von Neumann,
Various Techniques used in Connection with Random Digits,
J. Res. Nat. Bur. Stand., Appl. Math. Ser. 12, 36–38 (1951),
reprinted in Collected Works, Vol. 5, 768–770 (Pergammon, 1963).
See also the references given for the ExactExponential class.

Here the method is extended to be exact by generating sufficient bits in the random numbers in the algorithm to allow the unambiguous comparisons to be made.

Here's one way of sampling from a normal distribution with zero mean and unit variance in the interval [−1,1] with reasonable accuracy:

double Normal(RandomLib::Random& r) {
double x;
do
x = r.FloatW();
while ( !e(r, - 0.5 * x * x) );
return x;
}

(Note that the ExactNormal class samples from the normal distribution exactly.)

This class uses a mutable private vector. So a single ExponentialProb object cannot safely be used by multiple threads. In a multi-processing environment, each thread should use a thread-specific ExponentialProb object.

Definition at line 61 of file ExponentialProb.hpp.

Constructor & Destructor Documentation

RandomLib::ExponentialProb::ExponentialProb ( )
inline

Definition at line 66 of file ExponentialProb.hpp.

Member Function Documentation

template<typename RealType , class Random >
bool RandomLib::ExponentialProb::operator() ( Random r,
RealType  p 
) const

Return true with probability exp(−p). Returns false if p ≤ 0. For in p (0,1], it requires about exp(p) random deviates. For p large, it requires about exp(1)/(1 − exp(−1)) random deviates.

Template Parameters
RealTypethe real type of the argument.
Randomthe type of the random generator.
Parameters
[in,out]ra random generator.
[in]pthe probability.
Returns
true with probability p.

Definition at line 99 of file ExponentialProb.hpp.

References STATIC_ASSERT.


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