Skip to main content

MultivariateNormal

Struct MultivariateNormal 

Source
pub struct MultivariateNormal {
    pub mean: Vec<f64>,
    pub cov: Vec<Vec<f64>>,
    /* private fields */
}
Expand description

The multivariate normal distribution N(μ, Σ) (SciPy’s multivariate_normal), for a positive definite Σ: log f(x) = −½ (d log 2π + log|Σ| + (x − μ)ᵀ Σ⁻¹ (x − μ)), with the quadratic form computed as ‖L⁻¹(x − μ)‖² from the Cholesky factor Σ = L Lᵀ.

Fields§

§mean: Vec<f64>§cov: Vec<Vec<f64>>

Implementations§

Source§

impl MultivariateNormal

Source

pub fn new(mean: Vec<f64>, cov: Vec<Vec<f64>>) -> Result<Self, ErrorsJSL>

Source

pub fn new_allow_singular( mean: Vec<f64>, cov: Vec<Vec<f64>>, ) -> Result<Self, ErrorsJSL>

A normal distribution whose covariance may be singular (SciPy’s multivariate_normal(mean, cov, allow_singular=True)). The covariance’s eigenvalues above ε = 10⁶ ε_mach max|λ| define its rank r and range; the density is the r- dimensional one on the affine support μ + range(Σ), with the pseudo-determinant and pseudo-inverse, and zero off it.

Source

pub fn dim(&self) -> usize

Source

pub fn rank(&self) -> usize

The rank of the covariance (d unless singular).

Source

pub fn mahalanobis_sq(&self, x: &[f64]) -> f64

The squared Mahalanobis distance (x − μ)ᵀ Σ⁺ (x − μ) (with the pseudo-inverse when the covariance is singular).

Source

pub fn logpdf(&self, x: &[f64]) -> f64

Source

pub fn pdf(&self, x: &[f64]) -> f64

Source

pub fn entropy(&self) -> f64

½ log((2πe)^r |Σ|₊) (the pseudo-determinant when singular).

Source

pub fn sample<U: UniformGenerator>(&self, rng: &mut U) -> Vec<f64>

μ + L z for standard normal z (L a square root of Σ).

Source§

impl MultivariateNormal

Source

pub fn cdf_between<U: UniformGenerator>( &self, lower: Option<&[f64]>, upper: &[f64], options: MvCdfOptions, rng: &mut U, ) -> Result<(f64, f64), ErrorsJSL>

P(lower < X ≤ upper) (SciPy’s multivariate_normal.cdf(upper, lower_limit=lower); lower = None for −∞), with the error estimate. One and two dimensions are exact; in more, Genz’s method: reorder the variables so the most constrained comes first, factor Σ = L Lᵀ, and write the probability as an integral over the unit cube of a product of one-dimensional normal probabilities whose limits depend on the earlier variables, then integrate it with randomised rank-1 lattice rules until the error is below abseps.

Source

pub fn cdf<U: UniformGenerator>( &self, x: &[f64], rng: &mut U, ) -> Result<f64, ErrorsJSL>

P(X ≤ x) (SciPy’s multivariate_normal.cdf).

Trait Implementations§

Source§

impl Clone for MultivariateNormal

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MultivariateNormal

Source§

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

Formats the value using the given formatter. Read more

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.