RandomLib
1.10
|
The exponential probability. More...
#include <RandomLib/ExponentialProb.hpp>
Public Member Functions | |
ExponentialProb () | |
template<typename RealType , class Random > | |
bool | operator() (Random &r, RealType p) const |
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:
(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.
|
inline |
Definition at line 66 of file ExponentialProb.hpp.
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.
RealType | the real type of the argument. |
Random | the type of the random generator. |
[in,out] | r | a random generator. |
[in] | p | the probability. |
Definition at line 99 of file ExponentialProb.hpp.
References STATIC_ASSERT.