Struct Mixture

Source
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§

Source§

impl<C: Distribution> Mixture<C>

Source

pub fn new(weights: Vec<f64>, components: Vec<C>) -> Result<Mixture<C>, Error>
where C::Support: Union,

Source

pub fn new_unchecked(weights: Vec<f64>, components: Vec<C>) -> Mixture<C>
where C::Support: Union,

Source

pub fn n_components(&self) -> usize

Trait Implementations§

Source§

impl<C: Clone + Distribution> Clone for Mixture<C>
where C::Support: Clone,

Source§

fn clone(&self) -> Mixture<C>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: ContinuousDistribution> ContinuousDistribution for Mixture<C>
where C::Support: Union + Clone,

Source§

fn pdf(&self, x: &<Self::Support as Space>::Value) -> f64

Evaluates the probability density function (PDF) at \(x\). Read more
Source§

fn log_pdf(&self, x: &Sample<Self>) -> f64

Evaluates the log PDF at \(x\).
Source§

impl<C: Debug + Distribution> Debug for Mixture<C>
where C::Support: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: Distribution> Distribution for Mixture<C>
where C::Support: Union + Clone,

Source§

type Support = <C as Distribution>::Support

Support of sample elements.
Source§

type Params = Params<<C as Distribution>::Params>

Parameter set uniquely defining the instance.
Source§

fn support(&self) -> Self::Support

Returns an instance of the support Space, Self::Support. Read more
Source§

fn params(&self) -> Params<C::Params>

Returns an instance of the distribution parameters, Self::Params. Read more
Source§

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

Draw a random value from the distribution support.
Source§

fn into_support(self) -> Self::Support

Converts self into an instance of Self::Support.
Source§

fn into_params(self) -> Self::Params

Converts self into an instance of Self::Params.
Source§

fn ccdf(&self, x: &Sample<Self>) -> Probability

Evaluates the complementary CDF at \(x\). Read more
Source§

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

Evaluates the log complementary CDF at \(x\), i.e. \(\ln{(1 - F(x))}\).
Source§

fn sample_n<R: Rng + ?Sized>(&self, rng: &mut R, n: usize) -> Vec<Sample<Self>>

Draw n random value from the distribution support.
Source§

fn sample_iter<'a, R: Rng + ?Sized>( &'a self, rng: &'a mut R, ) -> Sampler<'a, Self, R>

Draw an indefinite number of random values from the distribution support.
Source§

impl<C: UnivariateMoments> UnivariateMoments for Mixture<C>
where C::Support: Union + Clone,

Source§

fn mean(&self) -> f64

Computes the expected value of the distribution.
Source§

fn variance(&self) -> f64

Computes the variance of the distribution.
Source§

fn skewness(&self) -> f64

Computes the skewness of the distribution.
Source§

fn kurtosis(&self) -> f64

Computes the kurtosis of the distribution.
Source§

fn standard_deviation(&self) -> f64

Computes the standard deviation of the distribution.
Source§

fn excess_kurtosis(&self) -> f64

Computes the excess kurtosis of the distribution.

Auto Trait Implementations§

§

impl<C> Freeze for Mixture<C>
where <C as Distribution>::Support: Freeze,

§

impl<C> RefUnwindSafe for Mixture<C>

§

impl<C> Send for Mixture<C>
where <C as Distribution>::Support: Send, C: Send,

§

impl<C> Sync for Mixture<C>
where <C as Distribution>::Support: Sync, C: Sync,

§

impl<C> Unpin for Mixture<C>
where <C as Distribution>::Support: Unpin, C: Unpin,

§

impl<C> UnwindSafe for Mixture<C>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V