pub struct MultivariateStudent<D>{ /* private fields */ }
nalgebra
only.Expand description
Implements the Multivariate Student’s t-distribution distribution using the “nalgebra” crate for matrix operations.
Assumes all the marginal distributions have the same degree of freedom, ν.
§Examples
use statrs::distribution::{MultivariateStudent, Continuous};
use nalgebra::{DVector, DMatrix};
use statrs::statistics::{MeanN, VarianceN};
let mvs = MultivariateStudent::new(vec![0., 0.], vec![1., 0., 0., 1.], 4.).unwrap();
assert_eq!(mvs.mean().unwrap(), DVector::from_vec(vec![0., 0.]));
assert_eq!(mvs.variance().unwrap(), DMatrix::from_vec(2, 2, vec![2., 0., 0., 2.]));
assert_eq!(mvs.pdf(&DVector::from_vec(vec![1., 1.])), 0.04715702017537655);
Implementations§
Source§impl MultivariateStudent<Dyn>
impl MultivariateStudent<Dyn>
Sourcepub fn new(
location: Vec<f64>,
scale: Vec<f64>,
freedom: f64,
) -> Result<Self, MultivariateStudentError>
pub fn new( location: Vec<f64>, scale: Vec<f64>, freedom: f64, ) -> Result<Self, MultivariateStudentError>
Constructs a new multivariate students t distribution with a location of location
,
scale matrix scale
and freedom
degrees of freedom.
§Errors
Returns StatsError::BadParams
if the scale matrix is not symmetric-positive
definite and StatsError::ArgMustBePositive
if freedom is non-positive.
Source§impl<D> MultivariateStudent<D>
impl<D> MultivariateStudent<D>
pub fn new_from_nalgebra( location: OVector<f64, D>, scale: OMatrix<f64, D, D>, freedom: f64, ) -> Result<Self, MultivariateStudentError>
Sourcepub fn scale_chol_decomp(&self) -> &OMatrix<f64, D, D>
pub fn scale_chol_decomp(&self) -> &OMatrix<f64, D, D>
Returns the cholesky decomposiiton matrix of the scale matrix.
Returns A where Σ = AAᵀ.
Sourcepub fn precision(&self) -> &OMatrix<f64, D, D>
pub fn precision(&self) -> &OMatrix<f64, D, D>
Returns the inverse of the cholesky decomposition matrix.
Sourcepub fn ln_pdf_const(&self) -> f64
pub fn ln_pdf_const(&self) -> f64
Returns the logarithmed constant part of the probability distribution function.
Trait Implementations§
Source§impl<D> Clone for MultivariateStudent<D>
impl<D> Clone for MultivariateStudent<D>
Source§fn clone(&self) -> MultivariateStudent<D>
fn clone(&self) -> MultivariateStudent<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 MultivariateStudent<D>
impl<D> Continuous<&Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>, f64> for MultivariateStudent<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.
student distribution at x
.
§Formula
[Γ(ν+p)/2] / [Γ(ν/2) ((ν * π)^p det(Σ))^(1 / 2)] * [1 + 1/ν (x - μ)ᵀ inv(Σ) (x - μ)]^(-(ν+p)/2)
where
ν
is the degrees of freedom,μ
is the mean,Γ
is the Gamma function,inv(Σ)
is the precision matrix,det(Σ)
is the determinant of the scale matrix, andk
is the dimension of the distribution.
Source§impl<D> Debug for MultivariateStudent<D>
impl<D> Debug for MultivariateStudent<D>
Source§impl<D> Distribution<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
Available on crate feature rand
only.
impl<D> Distribution<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
rand
only.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 student distribution
§Formula
W ⋅ L ⋅ Z + μ
where W
has √(ν/Sν) distribution, Sν has Chi-squared
distribution with ν degrees of freedom,
L
is the Cholesky decomposition of the scale matrix,
Z
is a vector of normally distributed random variables, and
μ
is the location 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 MultivariateStudent<D>
impl<D> Max<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
Source§impl<D> MeanN<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
impl<D> MeanN<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
Source§impl<D> Min<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
impl<D> Min<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
Source§impl<D> Mode<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
impl<D> Mode<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
Source§impl<D> PartialEq for MultivariateStudent<D>
impl<D> PartialEq for MultivariateStudent<D>
Source§impl<D> VarianceN<Matrix<f64, D, D, <DefaultAllocator as Allocator<D, D>>::Buffer<f64>>> for MultivariateStudent<D>
impl<D> VarianceN<Matrix<f64, D, D, <DefaultAllocator as Allocator<D, D>>::Buffer<f64>>> for MultivariateStudent<D>
impl<D> StructuralPartialEq for MultivariateStudent<D>
Auto Trait Implementations§
impl<D> !Freeze for MultivariateStudent<D>
impl<D> !RefUnwindSafe for MultivariateStudent<D>
impl<D> !Send for MultivariateStudent<D>
impl<D> !Sync for MultivariateStudent<D>
impl<D> !Unpin for MultivariateStudent<D>
impl<D> !UnwindSafe for MultivariateStudent<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.