diff --git a/src/distribution/multivariate_normal.rs b/src/distribution/multivariate_normal.rs index 20eb3e9f..7f5923c0 100644 --- a/src/distribution/multivariate_normal.rs +++ b/src/distribution/multivariate_normal.rs @@ -9,7 +9,7 @@ use std::f64::consts::{E, PI}; /// # Panics /// will panic on dimension mismatch #[inline] -pub(super) fn pdf_exponent_unchecked( +pub(super) fn pdf_exponent( mu: &OVector, precision: &OMatrix, x: &OVector, @@ -23,11 +23,11 @@ where -0.5 * (precision * &dv).dot(&dv) } -/// computes the argument of the normalization term in the normal distribution +/// computes normalization term in the normal distribution /// # Panics /// will panic on dimension mismatch #[inline] -pub(super) fn pdf_const_unchecked(mu: &OVector, cov: &OMatrix) -> f64 +pub(super) fn pdf_const(mu: &OVector, cov: &OMatrix) -> f64 where D: DimMin, nalgebra::DefaultAllocator: nalgebra::allocator::Allocator @@ -165,7 +165,7 @@ where cov_chol @ Some(_) => Ok(MultivariateNormal { precision: cov_chol.as_ref().map(|ll| ll.inverse()), cov_chol, - pdf_const: pdf_const_unchecked(&mean, &cov), + pdf_const: pdf_const(&mean, &cov), mu: mean, cov, }), @@ -400,13 +400,13 @@ where /// 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 fn pdf(&self, x: &OVector) -> f64 { - self.pdf_const * pdf_exponent_unchecked(&self.mu, self.precision.as_ref().unwrap(), x).exp() + self.pdf_const * pdf_exponent(&self.mu, self.precision.as_ref().unwrap(), x).exp() } /// Calculates the log probability density function for the multivariate /// normal distribution at `x`. Equivalent to pdf(x).ln(). fn ln_pdf(&self, x: &OVector) -> f64 { - self.pdf_const.ln() + pdf_exponent_unchecked(&self.mu, self.precision.as_ref().unwrap(), x) + self.pdf_const.ln() + pdf_exponent(&self.mu, self.precision.as_ref().unwrap(), x) } } diff --git a/src/distribution/multivariate_students_t.rs b/src/distribution/multivariate_students_t.rs index 96d3d277..2d290555 100644 --- a/src/distribution/multivariate_students_t.rs +++ b/src/distribution/multivariate_students_t.rs @@ -347,8 +347,8 @@ where fn pdf(&self, x: &'a OVector) -> f64 { if self.freedom.is_infinite() { use super::multivariate_normal as mvn; - let pdf_const = mvn::pdf_const_unchecked(&self.location, &self.scale); - let exp_arg = mvn::pdf_exponent_unchecked(&self.location, &self.precision, x); + let pdf_const = mvn::pdf_const(&self.location, &self.scale); + let exp_arg = mvn::pdf_exponent(&self.location, &self.precision, x); return pdf_const * exp_arg.exp(); } @@ -363,8 +363,8 @@ where fn ln_pdf(&self, x: &'a OVector) -> f64 { if self.freedom.is_infinite() { use super::multivariate_normal as mvn; - let pdf_const = mvn::pdf_const_unchecked(&self.location, &self.scale); - let exp_arg = mvn::pdf_exponent_unchecked(&self.location, &self.precision, x); + let pdf_const = mvn::pdf_const(&self.location, &self.scale); + let exp_arg = mvn::pdf_exponent(&self.location, &self.precision, x); return pdf_const.ln() + exp_arg; }