pub struct TransformedDensityRejection<'a> { /* private fields */ }Expand description
Transformed density rejection with the logarithm as the transformation (SciPy’s
TransformedDensityRejection; Gilks and Wild’s adaptive rejection sampling, Hörmann’s
formulation) for a log-concave density f on (a, b).
The tangents of log f at a set of construction points bound log f above by a concave
piecewise-linear function; its exponential is a hat made of exponential pieces, which can be
sampled by inversion. A point x from the hat is accepted if u · hat(x) ≤ f(x). Every
rejected point is added as a new construction point, so the hat tightens where it matters; the
variates stay exact whatever the number of points.
Implementations§
Source§impl<'a> TransformedDensityRejection<'a>
impl<'a> TransformedDensityRejection<'a>
Sourcepub fn new(
pdf: impl Fn(f64) -> f64 + 'a,
dpdf: impl Fn(f64) -> f64 + 'a,
domain: (f64, f64),
center: f64,
) -> Result<Self, ErrorsJSL>
pub fn new( pdf: impl Fn(f64) -> f64 + 'a, dpdf: impl Fn(f64) -> f64 + 'a, domain: (f64, f64), center: f64, ) -> Result<Self, ErrorsJSL>
pdf and its derivative dpdf on the interval domain (ends may be infinite);
center is a point near the mode where the construction starts (SciPy’s mode or
center). The density need not be normalised.
Sourcepub fn hat_area(&self) -> f64
pub fn hat_area(&self) -> f64
The area under the hat divided by the area under the density that it bounds: the expected
number of trials per variate is this ratio (f need only be proportional to the density,
so it is total / ∫f, estimated here by the ratio of the hat to its own squeeze: 1 if the
density is exactly exponential pieces). For a normalised density it is total.
Sourcepub fn rvs_one<G: UniformGenerator>(&mut self, rng: &mut G) -> f64
pub fn rvs_one<G: UniformGenerator>(&mut self, rng: &mut G) -> f64
One variate. Rejected points tighten the hat while there is room (at most 200 points).