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§
Provided Methods§
Sourcefn survival(&self, x: f64) -> f64
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.
Sourcefn sample(&self, rng: &mut StreamRng, n: usize) -> Vec<f64>
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.
Sourcefn is_parallel_safe(&self) -> bool
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.
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.