MultivariateGaussian

Struct MultivariateGaussian 

Source
pub struct MultivariateGaussian<T: Real> { /* private fields */ }
Expand description

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.

Implementations§

Source§

impl<T: Real> MultivariateGaussian<T>

Source

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

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 not symmetric, but this could be checked in the future.

Source

pub fn mean(&self) -> &Matrix<T>

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

Source

pub fn covariance(&self) -> &Matrix<T>

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.

Source§

impl<T: Real> MultivariateGaussian<T>
where for<'a> &'a T: RealRef<T>,

Source

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

Draws samples from this multivariate distribution, provided that the covariance matrix is positive definite.

For max_samples of M, sufficient random numbers from the source iterator in the uniformly distributed range [0, 1] inclusive, 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.

Example of generating and feeding random numbers

If the covariance matrix is only positive semi definite, None is returned. You can check if a given covariance matrix is positive definite instead of just positive semi definite with the cholesky decomposition.

Trait Implementations§

Source§

impl<T: Clone + Real> Clone for MultivariateGaussian<T>

Source§

fn clone(&self) -> MultivariateGaussian<T>

Returns a duplicate 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<T: Debug + Real> Debug for MultivariateGaussian<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for MultivariateGaussian<T>

§

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§

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> 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.