Struct MultivariateStudent

Source
pub struct MultivariateStudent<D>
where D: Dim, DefaultAllocator: Allocator<D> + Allocator<D, D>,
{ /* private fields */ }
Available on crate feature 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>

Source

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

pub fn dim(&self) -> usize

Returns the dimension of the distribution.

Source§

impl<D> MultivariateStudent<D>
where D: DimMin<D, Output = D>, DefaultAllocator: Allocator<D> + Allocator<D, D>,

Source

pub fn new_from_nalgebra( location: OVector<f64, D>, scale: OMatrix<f64, D, D>, freedom: f64, ) -> Result<Self, MultivariateStudentError>

Source

pub fn scale_chol_decomp(&self) -> &OMatrix<f64, D, D>

Returns the cholesky decomposiiton matrix of the scale matrix.

Returns A where Σ = AAᵀ.

Source

pub fn location(&self) -> &OVector<f64, D>

Returns the location of the distribution.

Source

pub fn scale(&self) -> &OMatrix<f64, D, D>

Returns the scale matrix of the distribution.

Source

pub fn freedom(&self) -> f64

Returns the degrees of freedom of the distribution.

Source

pub fn precision(&self) -> &OMatrix<f64, D, D>

Returns the inverse of the cholesky decomposition matrix.

Source

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>
where D: Dim + Clone, DefaultAllocator: Allocator<D> + Allocator<D, D>,

Source§

fn clone(&self) -> MultivariateStudent<D>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D> Continuous<&Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>, f64> for MultivariateStudent<D>
where D: Dim + DimMin<D, Output = D>, DefaultAllocator: Allocator<D> + Allocator<D, D>,

Source§

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, and
  • k is the dimension of the distribution.
Source§

fn ln_pdf(&self, x: &OVector<f64, D>) -> f64

Calculates the log probability density function for the multivariate student distribution at x. Equivalent to pdf(x).ln().

Source§

impl<D> Debug for MultivariateStudent<D>
where D: Dim + Debug, DefaultAllocator: Allocator<D> + Allocator<D, D>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<D> Distribution<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
where D: Dim, DefaultAllocator: Allocator<D> + Allocator<D, D>,

Available on crate feature rand only.
Source§

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>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

fn map<F, S>(self, func: F) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
Source§

impl<D> Max<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
where D: Dim, DefaultAllocator: Allocator<D> + Allocator<D, D>,

Source§

fn max(&self) -> OVector<f64, D>

Returns the minimum value in the domain of the multivariate normal distribution represented by a real vector

Source§

impl<D> MeanN<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
where D: Dim, DefaultAllocator: Allocator<D> + Allocator<D, D>,

Source§

fn mean(&self) -> Option<OVector<f64, D>>

Returns the mean of the student distribution.

§Remarks

This is the same mean used to construct the distribution if the degrees of freedom is larger than 1.

Source§

impl<D> Min<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
where D: Dim, DefaultAllocator: Allocator<D> + Allocator<D, D>,

Source§

fn min(&self) -> OVector<f64, D>

Returns the minimum value in the domain of the multivariate normal distribution represented by a real vector

Source§

impl<D> Mode<Matrix<f64, D, Const<1>, <DefaultAllocator as Allocator<D>>::Buffer<f64>>> for MultivariateStudent<D>
where D: Dim, DefaultAllocator: Allocator<D> + Allocator<D, D>,

Source§

fn mode(&self) -> OVector<f64, D>

Returns the mode of the multivariate student distribution.

§Formula
μ

where μ is the location.

Source§

impl<D> PartialEq for MultivariateStudent<D>

Source§

fn eq(&self, other: &MultivariateStudent<D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<D> VarianceN<Matrix<f64, D, D, <DefaultAllocator as Allocator<D, D>>::Buffer<f64>>> for MultivariateStudent<D>
where D: Dim, DefaultAllocator: Allocator<D> + Allocator<D, D>,

Source§

fn variance(&self) -> Option<OMatrix<f64, D, D>>

Returns the covariance matrix of the multivariate student distribution.

§Formula
Σ ⋅ ν / (ν - 2)

where Σ is the scale matrix and ν is the degrees of freedom. Only defined if freedom is larger than 2.

Source§

impl<D> StructuralPartialEq for MultivariateStudent<D>
where D: Dim, DefaultAllocator: Allocator<D> + Allocator<D, D>,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,