pub struct MultivariateGaussianTensor<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
Implementations§
Source§impl<T: Real> MultivariateGaussianTensor<T>
impl<T: Real> MultivariateGaussianTensor<T>
Sourcepub fn new(
mean: Tensor<T, 1>,
covariance: Tensor<T, 2>,
) -> Result<MultivariateGaussianTensor<T>, Box<MultivariateGaussianError<T>>>
pub fn new( mean: Tensor<T, 1>, covariance: Tensor<T, 2>, ) -> Result<MultivariateGaussianTensor<T>, Box<MultivariateGaussianError<T>>>
Constructs a new multivariate Gaussian distribution from a N length 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.
Result::Err is returned if the covariance matrix is not square, or the mean vector is not the same length as the size of the covariance matrix. Does not currently panic if the covariance matrix is not symmetric, but this could be checked in the future.
The dimension names of the mean and covariance matrix are not used, and do not need to match.
Sourcepub fn covariance(&self) -> &Tensor<T, 2>
pub fn covariance(&self) -> &Tensor<T, 2>
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.
Source§impl<T: Real> MultivariateGaussianTensor<T>
impl<T: Real> MultivariateGaussianTensor<T>
Sourcepub fn draw<I>(
&self,
source: &mut I,
max_samples: usize,
samples: Dimension,
features: Dimension,
) -> Option<Tensor<T, 2>>where
I: Iterator<Item = T>,
pub fn draw<I>(
&self,
source: &mut I,
max_samples: usize,
samples: Dimension,
features: Dimension,
) -> Option<Tensor<T, 2>>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 with dimension names samples and features for M and N respectively.
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 MultivariateGaussianTensor<T>
impl<T: Clone + Real> Clone for MultivariateGaussianTensor<T>
Source§fn clone(&self) -> MultivariateGaussianTensor<T>
fn clone(&self) -> MultivariateGaussianTensor<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more