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>
impl<'a> SimpleRatioUniforms<'a>
Sourcepub fn new(
pdf: impl Fn(f64) -> f64 + 'a,
mode: f64,
domain: (f64, f64),
) -> Result<Self, ErrorsJSL>
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.
Sourcepub fn acceptance_rate(&self) -> f64
pub fn acceptance_rate(&self) -> f64
The fraction of the points drawn so far that were kept.
pub fn rvs_one<G: UniformGenerator>(&mut self, rng: &mut G) -> f64
pub fn rvs<G: UniformGenerator>(&mut self, n: usize, rng: &mut G) -> Vec<f64>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for SimpleRatioUniforms<'a>
impl<'a> !Send for SimpleRatioUniforms<'a>
impl<'a> !Sync for SimpleRatioUniforms<'a>
impl<'a> !UnwindSafe for SimpleRatioUniforms<'a>
impl<'a> Freeze for SimpleRatioUniforms<'a>
impl<'a> Unpin for SimpleRatioUniforms<'a>
impl<'a> UnsafeUnpin for SimpleRatioUniforms<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more