Skip to main content

MultivariateRatioUniforms

Struct MultivariateRatioUniforms 

Source
pub struct MultivariateRatioUniforms<'a> { /* private fields */ }
Expand description

The multivariate ratio-of-uniforms method (Wakefield, Gelfand and Smith 1991; the idea of UNU.RAN’s VNROU) for a unimodal density f on ℝᵈ known up to a constant, with its mode m: if (u, v) is uniform on {(u, v): 0 < u ≤ f(m + v/u)^{1/(d+1)}}, then m + v/u has density ∝ f. The region lies in the box [0, f(m)^{1/(d+1)}] × ∏ᵢ [vᵢ⁻, vᵢ⁺] with vᵢ⁺ = sup (xᵢ − mᵢ) f(x)^{1/(d+1)} and vᵢ⁻ = inf, found at construction by a derivative-free search from several starting points, with a 1 % margin, or given. Points of the box are drawn and kept if they fall in the region. The method is exact when the box contains the region, and its acceptance rate falls with d (about 27 % for the normal density at d = 3, 7 % at d = 5).

Implementations§

Source§

impl<'a> MultivariateRatioUniforms<'a>

Source

pub fn new( pdf: impl Fn(&[f64]) -> f64 + 'a, mode: &[f64], ) -> Result<Self, ErrorsJSL>

pdf (up to a constant) with its mode; the box is found numerically.

Source

pub fn with_bounds( pdf: impl Fn(&[f64]) -> f64 + 'a, mode: &[f64], vmin: Vec<f64>, vmax: Vec<f64>, ) -> Result<Self, ErrorsJSL>

With the box given: vmin[i] ≤ 0 ≤ vmax[i] must contain (xᵢ − mᵢ) f(x)^{1/(d+1)} for every x.

Source

pub fn bounds(&self) -> (f64, &[f64], &[f64])

The box (umax, vmin, vmax).

Source

pub fn acceptance_rate(&self) -> f64

The fraction of the points drawn so far that were kept.

Source

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

Source

pub fn rvs<G: UniformGenerator>( &mut self, n: usize, rng: &mut G, ) -> Vec<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.