[][src]Struct rv::dist::Mixture

pub struct Mixture<Fx: ApiReady> {
    pub weights: Vec<f64>,
    pub components: Vec<Fx>,
}

Mixture distribution Σ wi f(x|θi)

A mixture distribution is a convex combination of distributions.

Example

A bimodal Gaussian mixture model

use rv::prelude::*;

let g1 = Gaussian::new(-2.5, 1.0).unwrap();
let g2 = Gaussian::new(2.0, 2.1).unwrap();

// f(x) = 0.6 * N(-2.5, 1.0) + 0.4 * N(2.0, 2.1)
let mm = Mixture::new(vec![0.6, 0.4], vec![g1, g2]).unwrap();

Fields

weights: Vec<f64>

The weights for each component distribution. All entries must be positive and sum to 1.

components: Vec<Fx>

The component distributions.

Methods

impl<Fx: ApiReady> Mixture<Fx>[src]

pub fn new(weights: Vec<f64>, components: Vec<Fx>) -> Result<Self>[src]

pub fn uniform(components: Vec<Fx>) -> Result<Self>[src]

Assume uniform component weights

Given a n-length vector of components, automatically sets the component weights to 1/n.

pub fn combine(mixtures: Vec<Mixture<Fx>>) -> Result<Self>[src]

Combines many mixtures into one big mixture

pub fn k(&self) -> usize[src]

Number of components

Trait Implementations

impl<X, Fx> Rv<X> for Mixture<Fx> where
    Fx: Rv<X> + ApiReady
[src]

impl<X, Fx> Support<X> for Mixture<Fx> where
    Fx: Rv<X> + Support<X> + ApiReady
[src]

impl<X, Fx> ContinuousDistr<X> for Mixture<Fx> where
    Fx: Rv<X> + ContinuousDistr<X> + ApiReady
[src]

impl<X, Fx> Cdf<X> for Mixture<Fx> where
    Fx: Rv<X> + Cdf<X> + ApiReady
[src]

fn sf(&self, x: &X) -> f64[src]

Survival function, 1 - CDF(x)

impl<X, Fx> DiscreteDistr<X> for Mixture<Fx> where
    Fx: Rv<X> + DiscreteDistr<X> + ApiReady
[src]

impl<Fx> Mean<f32> for Mixture<Fx> where
    Fx: ContinuousDistr<f32> + Mean<f32> + ApiReady
[src]

impl<Fx> Mean<f64> for Mixture<Fx> where
    Fx: ContinuousDistr<f64> + Mean<f64> + ApiReady
[src]

impl<Fx> Variance<f32> for Mixture<Fx> where
    Fx: ContinuousDistr<f32> + Mean<f32> + Variance<f32> + ApiReady
[src]

impl<Fx> Variance<f64> for Mixture<Fx> where
    Fx: ContinuousDistr<f64> + Mean<f64> + Variance<f64> + ApiReady
[src]

impl Entropy for Mixture<Categorical>[src]

impl Entropy for Mixture<Mixture<Categorical>>[src]

impl Entropy for Mixture<Gaussian>[src]

impl Entropy for Mixture<Mixture<Gaussian>>[src]

impl<Fx: PartialOrd + ApiReady> PartialOrd<Mixture<Fx>> for Mixture<Fx>[src]

impl<Fx: PartialEq + ApiReady> PartialEq<Mixture<Fx>> for Mixture<Fx>[src]

impl<Fx: Clone + ApiReady> Clone for Mixture<Fx>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<Fx: Debug + ApiReady> Debug for Mixture<Fx>[src]

Auto Trait Implementations

impl<Fx> Send for Mixture<Fx> where
    Fx: Send

impl<Fx> Sync for Mixture<Fx> where
    Fx: Sync

Blanket Implementations

impl<T> ApiReady for T where
    T: Clone + Debug + PartialOrd<T> + PartialEq<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>,