pub struct Mixture<C: Distribution> {
pub weights: SimplexVector,
pub components: Vec<C>,
/* private fields */
}
Expand description
Probability distribution derived from a linear sum of random variables.
§Examples
use rstat::{
Probability, Mixture,
univariate::{normal::Normal, Moments}
};
let gmm = Mixture::new(
vec![0.2, 0.5, 0.3],
vec![
Normal::new(-2.0, 1.2_f64.powi(2))?,
Normal::new(0.0, 1.0_f64.powi(2))?,
Normal::new(3.0, 2.5_f64.powi(2))?,
],
)?;
assert!((gmm.mean() - 0.5).abs() < 1e-7);
assert!((gmm.variance() - 5.913).abs() < 1e-7);
assert!((gmm.standard_deviation() - gmm.variance().sqrt()).abs() < 1e-7);
Fields§
§weights: SimplexVector
The weights of the linear sum.
components: Vec<C>
The distribution components of the linear sum.
Implementations§
Trait Implementations§
Source§impl<C: ContinuousDistribution> ContinuousDistribution for Mixture<C>
impl<C: ContinuousDistribution> ContinuousDistribution for Mixture<C>
Source§impl<C: Distribution> Distribution for Mixture<C>
impl<C: Distribution> Distribution for Mixture<C>
Source§type Support = <C as Distribution>::Support
type Support = <C as Distribution>::Support
Support of sample elements.
Source§type Params = Params<<C as Distribution>::Params>
type Params = Params<<C as Distribution>::Params>
Parameter set uniquely defining the instance.
Source§fn params(&self) -> Params<C::Params>
fn params(&self) -> Params<C::Params>
Returns an instance of the distribution parameters,
Self::Params
. Read moreSource§fn cdf(&self, x: &<Self::Support as Space>::Value) -> Probability
fn cdf(&self, x: &<Self::Support as Space>::Value) -> Probability
Evaluates the cumulative distribution function (CDF) at \(x\). Read more
Source§fn sample<R: Rng + ?Sized>(
&self,
rng: &mut R,
) -> <Self::Support as Space>::Value
fn sample<R: Rng + ?Sized>( &self, rng: &mut R, ) -> <Self::Support as Space>::Value
Draw a random value from the distribution support.
Source§fn into_support(self) -> Self::Support
fn into_support(self) -> Self::Support
Converts
self
into an instance of Self::Support
.Source§fn into_params(self) -> Self::Params
fn into_params(self) -> Self::Params
Converts
self
into an instance of Self::Params
.Source§fn ccdf(&self, x: &Sample<Self>) -> Probability
fn ccdf(&self, x: &Sample<Self>) -> Probability
Evaluates the complementary CDF at \(x\). Read more
Source§fn log_cdf(&self, x: &Sample<Self>) -> f64
fn log_cdf(&self, x: &Sample<Self>) -> f64
Evaluates the log CDF at \(x\), i.e. \(\ln{F(x)}\).
Source§fn 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))}\).
Source§impl<C: UnivariateMoments> UnivariateMoments for Mixture<C>
impl<C: UnivariateMoments> UnivariateMoments for Mixture<C>
Source§fn standard_deviation(&self) -> f64
fn standard_deviation(&self) -> f64
Computes the standard deviation of the distribution.
Source§fn excess_kurtosis(&self) -> f64
fn excess_kurtosis(&self) -> f64
Computes the excess kurtosis of the distribution.
Auto Trait Implementations§
impl<C> Freeze for Mixture<C>
impl<C> RefUnwindSafe for Mixture<C>
impl<C> Send for Mixture<C>
impl<C> Sync for Mixture<C>
impl<C> Unpin for Mixture<C>
impl<C> UnwindSafe for Mixture<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more