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§
Source§impl MultivariateNormal
impl MultivariateNormal
Sourcepub fn new(mean: Vec<f64>, cov: Vec<f64>) -> Result<Self>
pub fn new(mean: Vec<f64>, cov: Vec<f64>) -> Result<Self>
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
pub fn mu(&self) -> &DVector<f64>
pub fn cov(&self) -> &DMatrix<f64>
pub fn precision(&self) -> &DMatrix<f64>
pub fn pdf_const(&self) -> f64
Trait Implementations§
Source§impl Clone for MultivariateNormal
impl Clone for MultivariateNormal
Source§fn clone(&self) -> MultivariateNormal
fn clone(&self) -> MultivariateNormal
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Continuous<&'a Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>, f64> for MultivariateNormal
impl<'a> Continuous<&'a Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>, f64> for MultivariateNormal
Source§fn pdf(&self, x: &'a DVector<f64>) -> f64
fn pdf(&self, x: &'a DVector<f64>) -> f64
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
Source§impl Debug for MultivariateNormal
impl Debug for MultivariateNormal
Source§impl Distribution<Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>> for MultivariateNormal
impl Distribution<Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>> for MultivariateNormal
Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> DVector<f64>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> DVector<f64>
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
Source§fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
Create an iterator that generates random values of
T, using rng as
the source of randomness. Read moreSource§impl Max<Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>> for MultivariateNormal
impl Max<Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>> for MultivariateNormal
Source§impl MeanN<Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>> for MultivariateNormal
impl MeanN<Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>> for MultivariateNormal
Source§impl Min<Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>> for MultivariateNormal
impl Min<Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>> for MultivariateNormal
Source§impl Mode<Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>> for MultivariateNormal
impl Mode<Matrix<f64, Dynamic, Const<1>, VecStorage<f64, Dynamic, Const<1>>>> for MultivariateNormal
Source§impl PartialEq for MultivariateNormal
impl PartialEq for MultivariateNormal
Source§impl VarianceN<Matrix<f64, Dynamic, Dynamic, VecStorage<f64, Dynamic, Dynamic>>> for MultivariateNormal
impl VarianceN<Matrix<f64, Dynamic, Dynamic, VecStorage<f64, Dynamic, Dynamic>>> for MultivariateNormal
impl StructuralPartialEq for MultivariateNormal
Auto Trait Implementations§
impl Freeze for MultivariateNormal
impl RefUnwindSafe for MultivariateNormal
impl Send for MultivariateNormal
impl Sync for MultivariateNormal
impl Unpin for MultivariateNormal
impl UnwindSafe for MultivariateNormal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.