Skip to main content

Distribution

Trait Distribution 

Source
pub trait Distribution {
    // Required methods
    fn mean(&self) -> f64;
    fn variance(&self) -> f64;
    fn cdf(&self, x: f64) -> f64;
    fn quantile(&self, p: f64) -> Result<f64>;

    // Provided methods
    fn std_dev(&self) -> f64 { ... }
    fn survival(&self, x: f64) -> f64 { ... }
    fn sample(&self, rng: &mut StreamRng, n: usize) -> Vec<f64> { ... }
    fn is_parallel_safe(&self) -> bool { ... }
}
Expand description

A univariate loss distribution.

Only operations that are exact for every representation live here; see docs/design/distributions.md for the representation-specific traits that will join it.

Required Methods§

Source

fn mean(&self) -> f64

Expected value.

Source

fn variance(&self) -> f64

Variance.

Source

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

P(X <= x).

Source

fn quantile(&self, p: f64) -> Result<f64>

Smallest x with cdf(x) >= p.

Fails with prospicio_core::Error::InvalidProbability unless p is in [0, 1].

Provided Methods§

Source

fn std_dev(&self) -> f64

Standard deviation.

Source

fn survival(&self, x: f64) -> f64

P(X > x). Representations with a direct form override the default 1 - cdf(x), which loses all precision far in the tail.

Source

fn sample(&self, rng: &mut StreamRng, n: usize) -> Vec<f64>

n draws from stream rng, by inverse transform unless the family overrides it (crate::Gamma draws by Marsaglia and Tsang).

Inverse transform keeps draws a pure function of (seed, stream) and preserves ordering under common random numbers. An override keeps the first but not the second; code that needs draws monotone in a uniform calls quantile itself.

Source

fn is_parallel_safe(&self) -> bool

Whether the distribution may be evaluated on several threads at once. True for every native family; false for a crate::Custom whose callbacks must stay on the calling thread (an R function), so the parallel simulations run single-threaded when they meet one.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: Distribution + ?Sized> Distribution for Box<T>

A boxed distribution (for example Box<dyn Distribution>) is one too, so trait objects fit generic models.

Source§

fn mean(&self) -> f64

Source§

fn variance(&self) -> f64

Source§

fn std_dev(&self) -> f64

Source§

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

Source§

fn survival(&self, x: f64) -> f64

Source§

fn quantile(&self, p: f64) -> Result<f64>

Source§

fn sample(&self, rng: &mut StreamRng, n: usize) -> Vec<f64>

Source§

fn is_parallel_safe(&self) -> bool

Implementors§