Skip to main content

SimpleRatioUniforms

Struct SimpleRatioUniforms 

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

The simple ratio-of-uniforms method (SciPy’s SimpleRatioUniforms; Leydold’s SROU) for a unimodal density with a known mode: the region 0 < u ≤ √f(x), v = (x − mode) u, lies inside the rectangle [0, √f(mode)] × [v₋, v₊] with v₊ = sup_{x>mode} (x − mode) √f(x) and v₋ = inf_{x<mode} (x − mode) √f(x). The two suprema are found numerically at construction (a scan over geometrically spaced points, then golden-section refinement), so the density need not be normalised and no derivative is needed.

Implementations§

Source§

impl<'a> SimpleRatioUniforms<'a>

Source

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

pdf (up to a constant) on domain, with its mode.

Source

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

The bounding rectangle (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) -> f64

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.