Skip to main content

ContinuousSampler

Struct ContinuousSampler 

Source
pub struct ContinuousSampler<D> { /* private fields */ }
Expand description

Continuous distribution sampler.

Sampling uses SampleMethod (inverse transform or TDR). ppf and statistics always use numerical inverse CDF.

Implementations§

Source§

impl<P> ContinuousSampler<IntegratedPdf<P>>
where P: Pdf + HasSupport,

Source

pub fn from_pdf(pdf: P, opts: BuildOptions) -> Result<Self, BuildError>
where P: HasSupport,

Source

pub fn from_pdf_with_dpdf<DpdfT>( pdf: P, dpdf: DpdfT, opts: BuildOptions, ) -> Result<ContinuousSampler<IntegratedPdf<P>>, BuildError>
where P: HasSupport, DpdfT: Dpdf + HasSupport,

Source§

impl<C> ContinuousSampler<AffineCdf<C>>
where C: Cdf,

Source

pub fn from_cdf(cdf: C, opts: BuildOptions) -> Result<Self, BuildError>
where C: HasSupport,

Source§

impl<D> ContinuousSampler<D>
where D: CdfSource,

Source

pub fn set_hermite_table(&mut self, grid_size: usize)

Rebuild or replace the Hermite PPF table (inverse-transform path only).

Source

pub fn clear_hermite_table(&mut self)

Use bisection-only PPF (removes Hermite table).

Source

pub fn uses_hermite_table(&self) -> bool

Source

pub fn uses_tdr(&self) -> bool

Source

pub fn support(&self) -> Interval

Source

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

Source

pub fn pdf_at(&self, x: f64) -> Option<f64>

Source

pub fn has_pdf(&self) -> bool

Source

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

Source

pub fn sample(&self) -> Result<f64, SampleError>

Source

pub fn sample_with_rng<R: Rng + ?Sized>( &self, rng: &mut R, ) -> Result<f64, SampleError>

Source

pub fn sample_n(&self, n: usize) -> Result<Vec<f64>, SampleError>

Source

pub fn sample_n_with_rng<R: Rng + ?Sized>( &self, rng: &mut R, n: usize, ) -> Result<Vec<f64>, SampleError>

Source§

impl<D> ContinuousSampler<D>
where D: CdfSource,

Source

pub fn pdf(&self, x: f64) -> Option<f64>

Probability density at x (zero outside support). Requires an underlying PDF.

Source

pub fn logpdf(&self, x: f64) -> Option<f64>

Natural logarithm of the PDF; None if PDF unavailable or non-positive.

Source

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

Log of the CDF.

Source

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

Survival function sf(x) = 1 - cdf(x), stable for large cdf.

Source

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

Log survival function.

Source

pub fn isf(&self, q: f64) -> Result<f64, SampleError>

Inverse survival function isf(q) = ppf(1 - q).

Source

pub fn median(&self) -> Result<f64, SampleError>

Median ppf(0.5).

Source

pub fn mean(&self) -> Result<f64, SampleError>

Mean E[X] via expect(|x| x).

Source

pub fn var(&self) -> Result<f64, SampleError>

Variance Var[X].

Source

pub fn std(&self) -> Result<f64, SampleError>

Standard deviation.

Source

pub fn entropy(&self) -> Result<f64, SampleError>

Differential entropy H = -∫ f log f dx (nats).

Source

pub fn expect( &self, func: impl Fn(f64) -> f64, tol: f64, ) -> Result<f64, SampleError>

E[func(X)] on the support.

Source

pub fn interval(&self, confidence: f64) -> Result<(f64, f64), SampleError>

Equal-tailed confidence interval (ppf((1-p)/2), ppf(1-(1-p)/2)).

Trait Implementations§

Source§

impl<D> Distribution<f64> for ContinuousSampler<D>
where D: CdfSource,

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64

Generate a random value of T, using rng as the source of randomness.
Source§

fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

fn map<F, S>(self, func: F) -> Map<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Map sampled values to type S Read more

Auto Trait Implementations§

§

impl<D> Freeze for ContinuousSampler<D>
where D: Freeze,

§

impl<D> RefUnwindSafe for ContinuousSampler<D>
where D: RefUnwindSafe,

§

impl<D> Send for ContinuousSampler<D>
where D: Send,

§

impl<D> Sync for ContinuousSampler<D>
where D: Sync,

§

impl<D> Unpin for ContinuousSampler<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for ContinuousSampler<D>
where D: UnsafeUnpin,

§

impl<D> UnwindSafe for ContinuousSampler<D>
where D: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.