Struct statrs::distribution::MultivariateNormal
source · [−]pub struct MultivariateNormal { /* private fields */ }
Expand description
Implements the Multivariate Normal distribution using the “nalgebra” crate for matrix operations
Examples
use statrs::distribution::{MultivariateNormal, Continuous};
use nalgebra::{DVector, DMatrix};
use statrs::statistics::{MeanN, VarianceN};
let mvn = MultivariateNormal::new(vec![0., 0.], vec![1., 0., 0., 1.]).unwrap();
assert_eq!(mvn.mean().unwrap(), DVector::from_vec(vec![0., 0.]));
assert_eq!(mvn.variance().unwrap(), DMatrix::from_vec(2, 2, vec![1., 0., 0., 1.]));
assert_eq!(mvn.pdf(&DVector::from_vec(vec![1., 1.])), 0.05854983152431917);
Implementations
Constructs a new multivariate normal distribution with a mean of mean
and covariance matrix cov
Errors
Returns an error if the given covariance matrix is not symmetric or positive-definite
Trait Implementations
impl<'a> Continuous<&'a Matrix<f64, Dynamic, Const<1_usize>, VecStorage<f64, Dynamic, Const<1_usize>>>, f64> for MultivariateNormal
impl<'a> Continuous<&'a Matrix<f64, Dynamic, Const<1_usize>, VecStorage<f64, Dynamic, Const<1_usize>>>, f64> for MultivariateNormal
Calculates the probability density function for the multivariate
normal distribution at x
Formula
(2 * π) ^ (-k / 2) * det(Σ) ^ (1 / 2) * e ^ ( -(1 / 2) * transpose(x - μ) * inv(Σ) * (x - μ))
where μ
is the mean, inv(Σ)
is the precision matrix, det(Σ)
is the determinant
of the covariance matrix, and k
is the dimension of the distribution
impl Distribution<Matrix<f64, Dynamic, Const<1_usize>, VecStorage<f64, Dynamic, Const<1_usize>>>> for MultivariateNormal
impl Distribution<Matrix<f64, Dynamic, Const<1_usize>, VecStorage<f64, Dynamic, Const<1_usize>>>> for MultivariateNormal
Samples from the multivariate normal distribution
Formula
L * Z + μ
where L
is the Cholesky decomposition of the covariance matrix,
Z
is a vector of normally distributed random variables, and
μ
is the mean vector
Create an iterator that generates random values of T
, using rng
as
the source of randomness. Read more
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for MultivariateNormal
impl Send for MultivariateNormal
impl Sync for MultivariateNormal
impl Unpin for MultivariateNormal
impl UnwindSafe for MultivariateNormal
Blanket Implementations
Mutably borrows from an owned value. Read more
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
Checks if self
is actually part of its subset T
(and can be converted to it).
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
The inclusion map: converts self
to the equivalent element of its superset.