Skip to main content

NumericalInversePolynomial

Struct NumericalInversePolynomial 

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

Numerical inversion of a distribution function from the density alone, by polynomial interpolation of its inverse (SciPy’s NumericalInversePolynomial; Derflinger, Hörmann and Leydold’s PINV). The interval is split until, on every piece, the polynomial of degree order through order + 1 Chebyshev-Lobatto points of the piece, as a function of the probability mass, inverts the integral of the density to within u_resolution of the whole mass at three interior test points. The masses are integrals of the density (adaptive Gauss-Legendre), so the density needs neither normalising nor a distribution function.

Implementations§

Source§

impl<'a> NumericalInversePolynomial<'a>

Source

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

pdf (up to a constant) on domain; order is the degree of the polynomials (3 to 17, SciPy’s default is 5); infinite ends are cut where the mass of what is left is below u_resolution / 10 of the total. center is a point where the density is positive.

Source

pub fn n_intervals(&self) -> usize

The number of intervals.

Source

pub fn area(&self) -> f64

The integral of the density over the domain (the normalising constant).

Source

pub fn ppf(&self, u: f64) -> f64

The quantile function: x with F(x) = u.

Source

pub fn cdf(&self, x: f64) -> f64

The distribution function, by integrating the density from the start of the interval.

Source

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

Source

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

Source

pub fn qrvs_sobol(&self, n: usize) -> Vec<f64>

n variates by inversion of the (unscrambled, one-dimensional) Sobol sequence.

Source

pub fn u_error(&self, n: usize) -> f64

The largest |F(ppf(u)) − u| over n equally spaced values of u.

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.