pub trait Distribution: From<Self::Params> {
type Support: Space;
type Params;
// Required methods
fn support(&self) -> Self::Support;
fn params(&self) -> Self::Params;
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Sample<Self>;
// Provided methods
fn into_support(self) -> Self::Support { ... }
fn into_params(self) -> Self::Params { ... }
fn cdf(&self, x: &Sample<Self>) -> Probability { ... }
fn ccdf(&self, x: &Sample<Self>) -> Probability { ... }
fn log_cdf(&self, x: &Sample<Self>) -> f64 { ... }
fn log_ccdf(&self, x: &Sample<Self>) -> f64 { ... }
fn sample_n<R: Rng + ?Sized>(
&self,
rng: &mut R,
n: usize,
) -> Vec<Sample<Self>> ⓘ { ... }
fn sample_iter<'a, R: Rng + ?Sized>(
&'a self,
rng: &'a mut R,
) -> Sampler<'a, Self, R> ⓘ { ... }
}
Expand description
Trait for probability distributions with a well-defined CDF.
Required Associated Types§
Required Methods§
Sourcefn support(&self) -> Self::Support
fn support(&self) -> Self::Support
Returns an instance of the support Space
, Self::Support
.
§Examples
let dist = univariate::beta::Beta::default();
let support = dist.support();
assert_eq!(support.dim(), Dim::Finite(1));
assert_eq!(support.inf().unwrap(), 0.0);
assert_eq!(support.sup().unwrap(), 1.0);
Provided Methods§
Sourcefn into_support(self) -> Self::Support
fn into_support(self) -> Self::Support
Converts self
into an instance of Self::Support
.
Sourcefn into_params(self) -> Self::Params
fn into_params(self) -> Self::Params
Converts self
into an instance of Self::Params
.
Sourcefn cdf(&self, x: &Sample<Self>) -> Probability
fn cdf(&self, x: &Sample<Self>) -> Probability
Evaluates the cumulative distribution function (CDF) at \(x\).
The CDF is defined as the probability that a random variable \(X\) takes on a value less than or equal to \(x\), i.e. \(F(x) = P(X \leq x)\).
§Examples
let dist = univariate::normal::Normal::standard();
assert_eq!(dist.cdf(&f64::NEG_INFINITY), Probability::zero());
assert_eq!(dist.cdf(&0.0), Probability::half());
assert_eq!(dist.cdf(&f64::INFINITY), Probability::one());
Sourcefn ccdf(&self, x: &Sample<Self>) -> Probability
fn ccdf(&self, x: &Sample<Self>) -> Probability
Evaluates the complementary CDF at \(x\).
The complementary CDF (also known as the survival function) is defined as the probability that a random variable \(X\) takes on a value strictly greater than \(x\), i.e. \(\bar{F}(x) = P(X > x) = 1 - F(x)\).
Sourcefn log_ccdf(&self, x: &Sample<Self>) -> f64
fn log_ccdf(&self, x: &Sample<Self>) -> f64
Evaluates the log complementary CDF at \(x\), i.e. \(\ln{(1 - F(x))}\).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.