|
Celeritas 0.7+972e6cd
|
Return whether a rejection loop needs to continue trying. More...
#include <RejectionSampler.hh>
Public Types | |
Type aliases | |
| using | real_type = RealType |
| using | result_type = bool |
Public Member Functions | |
| constexpr | RejectionSampler (real_type fmax) |
| Construct with acceptance probability and maximum probability. | |
| constexpr | RejectionSampler () |
| Construct when the distribution's maximum is normalized. | |
| template<class Generator > | |
| bool | operator() (real_type f, Generator &rng) const |
| template<class Generator > | |
| auto | operator() (real_type f, Generator &rng) const -> result_type |
| Reject with a given probability. | |
Static Public Member Functions | |
| static constexpr real_type | tolerance () |
| Allow a priori estimate of fmax to be slightly unconservative. | |
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 proposal distribution g(x) . Given a constant M such that \( f(x) < M g(x) \) 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)} \]
.
This rejection sampler is constructed with the maximum M and is invoked with the sampled ratio \( f(x)/g(x) \) and an RNG. It allows an underestimate of the constant M by \( 10 \epsilon_\textrm{mach} \) which may result in an imperceptible bias against selecting the peak of the PDF.
These invocations generate statistically equivalent results:
BernoulliDistribution(1 - p / pmax)(rng);!BernoulliDistribution(p / pmax)(rng);p < pmax * UniformDistribution{}(rng)RejectionSampler(pmax)(p, rng);