Celeritas
0.5.0-56+6b053cd
|
Return whether a rejection loop needs to continue trying. More...
#include <RejectionSampler.hh>
Public Types | |
Type aliases | |
using | real_type = RealType |
using | result_type = real_type |
Public Member Functions | |
CELER_FUNCTION | RejectionSampler (real_type f, real_type fmax) |
Construct with acceptance probability and maximum probability. | |
CELER_FUNCTION | RejectionSampler (real_type f) |
Construct when the distribution's maximum is normalized. | |
template<class Generator > | |
CELER_FUNCTION result_type | operator() (Generator &rng) |
template<class Generator > | |
CELER_FUNCTION auto | operator() (Generator &rng) -> result_type |
Sample a random number according to the distribution. | |
Return whether a rejection loop needs to continue trying.
A common implementation of sampling from a "difficult" (non-analytically invertible) probability distribution function is to bound the difficult distribution f(x) with another easily sampled function g(x) . Given a maximum value M over the x interval being sampled, it is equivalent to sampling f(x) by instead sampling from g(x) and rejecting with probability
\[ \frac{f(x)}{M g(x)} \]
These invocations generate statistically equivalent results:
BernoulliDistribution(1 - p / pmax)(rng);
!BernoulliDistribution(p / pmax)(rng);
p < pmax * UniformDistribution{}(rng)
RejectionSampler(p, pmax)(rng);
This is meant for rejection sampling, e.g., on cross section: