[−][src]Struct rv::dist::Mixture
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();
Methods
impl<Fx> Mixture<Fx>
[src]
pub fn new(weights: Vec<f64>, components: Vec<Fx>) -> Result<Self, MixtureError>
[src]
Create a new micture distribution
Arguments
- weights: The weights for each component distribution. All entries must be positive and sum to 1.
- components: The componen distributions.
pub fn new_unchecked(weights: Vec<f64>, components: Vec<Fx>) -> Self
[src]
Creates a new Mixture without checking whether the parameters are valid.
pub fn uniform(components: Vec<Fx>) -> Result<Self, MixtureError>
[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>>) -> Self
[src]
Combines many mixtures into one big mixture
pub fn k(&self) -> usize
[src]
Number of components
pub fn weights(&self) -> &Vec<f64>
[src]
Get a reference to the component weights
pub fn components(&self) -> &Vec<Fx>
[src]
Get a reference to the components
pub fn set_weights(&mut self, weights: Vec<f64>) -> Result<(), MixtureError>
[src]
pub fn set_weights_unchecked(&mut self, weights: Vec<f64>)
[src]
pub fn set_components(
&mut self,
components: Vec<Fx>
) -> Result<(), MixtureError>
[src]
&mut self,
components: Vec<Fx>
) -> Result<(), MixtureError>
pub fn set_components_unchecked(&mut self, components: Vec<Fx>)
[src]
Trait Implementations
impl<X, Fx> Cdf<X> for Mixture<Fx> where
Fx: Rv<X> + Cdf<X>,
[src]
Fx: Rv<X> + Cdf<X>,
impl<Fx: Clone> Clone for Mixture<Fx>
[src]
impl<X, Fx> ContinuousDistr<X> for Mixture<Fx> where
Fx: Rv<X> + ContinuousDistr<X>,
[src]
Fx: Rv<X> + ContinuousDistr<X>,
impl<Fx: Debug> Debug for Mixture<Fx>
[src]
impl<X, Fx> DiscreteDistr<X> for Mixture<Fx> where
Fx: Rv<X> + DiscreteDistr<X>,
[src]
Fx: Rv<X> + DiscreteDistr<X>,
impl Entropy for Mixture<Categorical>
[src]
impl<'_> Entropy for Mixture<&'_ Categorical>
[src]
impl Entropy for Mixture<Gaussian>
[src]
impl<'_> Entropy for Mixture<&'_ Gaussian>
[src]
impl<Fx> Mean<f32> for Mixture<Fx> where
Fx: ContinuousDistr<f32> + Mean<f32>,
[src]
Fx: ContinuousDistr<f32> + Mean<f32>,
impl<Fx> Mean<f64> for Mixture<Fx> where
Fx: ContinuousDistr<f64> + Mean<f64>,
[src]
Fx: ContinuousDistr<f64> + Mean<f64>,
impl<Fx: PartialEq> PartialEq<Mixture<Fx>> for Mixture<Fx>
[src]
impl<Fx: PartialOrd> PartialOrd<Mixture<Fx>> for Mixture<Fx>
[src]
fn partial_cmp(&self, other: &Mixture<Fx>) -> Option<Ordering>
[src]
fn lt(&self, other: &Mixture<Fx>) -> bool
[src]
fn le(&self, other: &Mixture<Fx>) -> bool
[src]
fn gt(&self, other: &Mixture<Fx>) -> bool
[src]
fn ge(&self, other: &Mixture<Fx>) -> bool
[src]
impl QuadBounds for Mixture<Gaussian>
[src]
impl<'_> QuadBounds for Mixture<&'_ Gaussian>
[src]
impl<X, Fx> Rv<X> for Mixture<Fx> where
Fx: Rv<X>,
[src]
Fx: Rv<X>,
fn ln_f(&self, x: &X) -> f64
[src]
fn f(&self, x: &X) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> X
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
impl<Fx> StructuralPartialEq for Mixture<Fx>
[src]
impl<X, Fx> Support<X> for Mixture<Fx> where
Fx: Rv<X> + Support<X>,
[src]
Fx: Rv<X> + Support<X>,
impl<Fx> Variance<f32> for Mixture<Fx> where
Fx: ContinuousDistr<f32> + Mean<f32> + Variance<f32>,
[src]
Fx: ContinuousDistr<f32> + Mean<f32> + Variance<f32>,
impl<Fx> Variance<f64> for Mixture<Fx> where
Fx: ContinuousDistr<f64> + Mean<f64> + Variance<f64>,
[src]
Fx: ContinuousDistr<f64> + Mean<f64> + Variance<f64>,
Auto Trait Implementations
impl<Fx> RefUnwindSafe for Mixture<Fx> where
Fx: RefUnwindSafe,
Fx: RefUnwindSafe,
impl<Fx> Send for Mixture<Fx> where
Fx: Send,
Fx: Send,
impl<Fx> Sync for Mixture<Fx> where
Fx: Sync,
Fx: Sync,
impl<Fx> Unpin for Mixture<Fx> where
Fx: Unpin,
Fx: Unpin,
impl<Fx> UnwindSafe for Mixture<Fx> where
Fx: UnwindSafe,
Fx: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<Fx, X> Cdf<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Cdf<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Cdf<X>,
impl<Fx, X> ContinuousDistr<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: ContinuousDistr<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: ContinuousDistr<X>,
impl<Fx, X> DiscreteDistr<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: DiscreteDistr<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: DiscreteDistr<X>,
impl<Fx> Entropy for Fx where
Fx: Deref,
<Fx as Deref>::Target: Entropy,
[src]
Fx: Deref,
<Fx as Deref>::Target: Entropy,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<Fx, X> Mean<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Mean<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Mean<X>,
impl<Fx, X> Rv<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Rv<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Rv<X>,
fn ln_f(&Self, &X) -> f64
[src]
fn f(&Self, &X) -> f64
[src]
fn draw<R>(&Self, &mut R) -> X where
R: Rng,
[src]
R: Rng,
fn sample<R>(&Self, usize, &mut R) -> Vec<X> where
R: Rng,
[src]
R: Rng,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn is_in_subset(&self) -> bool
unsafe fn to_subset_unchecked(&self) -> SS
fn from_subset(element: &SS) -> SP
impl<Fx, X> Support<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Support<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Support<X>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<Fx, X> Variance<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Variance<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Variance<X>,