pub struct MultivariateNormal<D>{ /* private fields */ }
Expand description
Implements the Multivariate Normal distribution using the “nalgebra” crate for matrix operations
§Examples
use statrs::distribution::{MultivariateNormal, Continuous};
use nalgebra::{matrix, vector};
use statrs::statistics::{MeanN, VarianceN};
let mvn = MultivariateNormal::new_from_nalgebra(vector![0., 0.], matrix![1., 0.; 0., 1.]).unwrap();
assert_eq!(mvn.mean().unwrap(), vector![0., 0.]);
assert_eq!(mvn.variance().unwrap(), matrix![1., 0.; 0., 1.]);
assert_eq!(mvn.pdf(&vector![1., 1.]), 0.05854983152431917);
Implementations§
Source§impl MultivariateNormal<Dyn>
impl MultivariateNormal<Dyn>
Source§impl<D> MultivariateNormal<D>
impl<D> MultivariateNormal<D>
Sourcepub fn new_from_nalgebra(
mean: OVector<f64, D>,
cov: OMatrix<f64, D, D>,
) -> Result<Self, MultivariateNormalError>
pub fn new_from_nalgebra( mean: OVector<f64, D>, cov: OMatrix<f64, D, D>, ) -> Result<Self, MultivariateNormalError>
Constructs a new multivariate normal distribution with a mean of mean
and covariance matrix cov
using nalgebra
OVector
and OMatrix
instead of Vec<f64>
§Errors
Returns an error if the given covariance matrix is not symmetric or positive-definite
Trait Implementations§
Source§impl<D> Clone for MultivariateNormal<D>
impl<D> Clone for MultivariateNormal<D>
Source§fn clone(&self) -> MultivariateNormal<D>
fn clone(&self) -> MultivariateNormal<D>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<D> Continuous<&Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>, f64> for MultivariateNormal<D>
impl<D> Continuous<&Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>, f64> for MultivariateNormal<D>
Source§fn pdf(&self, x: &OVector<f64, D>) -> f64
fn pdf(&self, x: &OVector<f64, D>) -> 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<D> Debug for MultivariateNormal<D>
impl<D> Debug for MultivariateNormal<D>
Source§impl<D> Display for MultivariateNormal<D>
impl<D> Display for MultivariateNormal<D>
Source§impl<D> Distribution<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateNormal<D>
impl<D> Distribution<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateNormal<D>
Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> OVector<f64, D>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> OVector<f64, D>
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>
T
, using rng
as
the source of randomness. Read moreSource§impl<D> Max<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateNormal<D>
impl<D> Max<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateNormal<D>
Source§impl<D> MeanN<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateNormal<D>
impl<D> MeanN<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateNormal<D>
Source§impl<D> Min<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateNormal<D>
impl<D> Min<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateNormal<D>
Source§impl<D> Mode<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateNormal<D>
impl<D> Mode<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateNormal<D>
Source§impl<D> PartialEq for MultivariateNormal<D>
impl<D> PartialEq for MultivariateNormal<D>
Source§impl<D> VarianceN<Matrix<f64, D, D, <DefaultAllocator as Allocator<D, D>>::Buffer<f64>>> for MultivariateNormal<D>
impl<D> VarianceN<Matrix<f64, D, D, <DefaultAllocator as Allocator<D, D>>::Buffer<f64>>> for MultivariateNormal<D>
impl<D> StructuralPartialEq for MultivariateNormal<D>
Auto Trait Implementations§
impl<D> !Freeze for MultivariateNormal<D>
impl<D> !RefUnwindSafe for MultivariateNormal<D>
impl<D> !Send for MultivariateNormal<D>
impl<D> !Sync for MultivariateNormal<D>
impl<D> !Unpin for MultivariateNormal<D>
impl<D> !UnwindSafe for MultivariateNormal<D>
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
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>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.