Struct easy_ml::distributions::MultivariateGaussian[][src]

pub struct MultivariateGaussian<T: Numeric + Real> {
    pub mean: Matrix<T>,
    pub covariance: Matrix<T>,
}

A multivariate Gaussian distribution with mean vector μ, and covariance matrix Σ.

See: https://en.wikipedia.org/wiki/Multivariate_normal_distribution

Invariants

The mean Matrix must always be a column vector, and must be the same length as the covariance matrix.

Fields

mean: Matrix<T>

The mean is a column vector of expected values in each dimension

covariance: Matrix<T>

The covariance matrix is a NxN matrix where N is the number of dimensions for this Gaussian. A covariance matrix must always be symmetric, that is C[i,j] = C[j,i].

The covariance matrix is a measure of how much values from each dimension vary from their expected value with respect to each other.

For a 2 dimensional multivariate Gaussian the covariance matrix could be the 2x2 identity matrix:

[
  1.0, 0.0
  0.0, 1.0
]

In which case the two dimensions are completely uncorrelated as C[0,1] = C[1,0] = 0.

Implementations

impl<T: Numeric + Real> MultivariateGaussian<T>[src]

pub fn new(mean: Matrix<T>, covariance: Matrix<T>) -> MultivariateGaussian<T>[src]

Constructs a new multivariate Gaussian distribution from a Nx1 column vector of means and a NxN covariance matrix

This function does not check that the provided covariance matrix is actually a covariance matrix. If a square matrix that is not symmetric is supplied the gaussian is not defined.

Panics

Panics if the covariance matrix is not square, or the column vector is not the same length as the covariance matrix size. Does not currently panic if the covariance matrix is symmetric, but this could be checked in the future.

impl<T: Numeric + Real> MultivariateGaussian<T> where
    &'a T: NumericRef<T> + RealRef<T>, 
[src]

pub fn draw<I>(&self, source: &mut I, max_samples: usize) -> Option<Matrix<T>> where
    I: Iterator<Item = T>, 
[src]

Draws samples from this multivariate distribution.

For max_samples of M, sufficient random numbers from the source iterator, and this Gaussian’s dimensionality of N, returns an MxN matrix of drawn values.

The source iterator must have at least MxN random values if N is even, and Mx(N+1) random values if N is odd, or None will be returned. If the cholesky decomposition cannot be taken on this Gaussian’s covariance matrix then None is also returned.

Example of generating and feeding random numbers

Trait Implementations

impl<T: Debug + Numeric + Real> Debug for MultivariateGaussian<T>[src]

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<T> RefUnwindSafe for MultivariateGaussian<T> where
    T: RefUnwindSafe

impl<T> Send for MultivariateGaussian<T> where
    T: Send

impl<T> Sync for MultivariateGaussian<T> where
    T: Sync

impl<T> Unpin for MultivariateGaussian<T> where
    T: Unpin

impl<T> UnwindSafe for MultivariateGaussian<T> where
    T: UnwindSafe

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.