Skip to main content

TransformedDensityRejection

Struct TransformedDensityRejection 

Source
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>

Source

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.

Source

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.

Source

pub fn n_points(&self) -> usize

The number of construction points.

Source

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).

Source

pub fn rvs<G: UniformGenerator>(&mut self, n: usize, rng: &mut G) -> Vec<f64>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.