diff --git a/src/distribution/mod.rs b/src/distribution/mod.rs index 514132ff..e6a2fd92 100644 --- a/src/distribution/mod.rs +++ b/src/distribution/mod.rs @@ -290,9 +290,10 @@ pub trait ContinuousMultivariateCDF { /// /// ``` /// use statrs::distribution::{ContinuousMultivariateCDF, MultivariateNormal}; + /// use nalgebra::DVector; /// /// let mvn = MultivariateNormal::new(vec![0., 0.], vec![1., 0., 0., 1.]).unwrap(); - /// assert_eq!(0.25, mvn.cdf([0., 0.,])); + /// assert_eq!(0.25, mvn.cdf(DVector::from_vec(vec![0., 0.,]))); /// ``` fn cdf(&self, x: DVector) -> T; @@ -304,9 +305,10 @@ pub trait ContinuousMultivariateCDF { /// /// ``` /// use statrs::distribution::{ContinuousMultivariateCDF, MultivariateNormal}; + /// use nalgebra::DVector; /// /// let mvs = MultivariateNormal::new(vec![0., 0.], vec![1., 0., 0., 1.]).unwrap(); - /// assert_eq!(f64::NEG_INFINITY, mvs.sf([f64::INFINITY, f64::INFINITY])); + /// assert_eq!(0., mvs.sf(DVector::from_vec(vec![f64::INFINITY, f64::INFINITY]))); /// ``` fn sf(&self, x: DVector) -> T; } diff --git a/src/distribution/multivariate_normal.rs b/src/distribution/multivariate_normal.rs index 58a41c12..6cb2f52a 100644 --- a/src/distribution/multivariate_normal.rs +++ b/src/distribution/multivariate_normal.rs @@ -273,6 +273,7 @@ impl ContinuousMultivariateCDF for MultivariateNormal { /// multivariate normal distribution, using approximation with /// `N` points. fn sf(&self, x: DVector) -> f64 { + // Shift integration limit wrt. mean 1. - self.cdf(x) } } diff --git a/src/distribution/multivariate_uniform.rs b/src/distribution/multivariate_uniform.rs index 97921cba..c5946499 100644 --- a/src/distribution/multivariate_uniform.rs +++ b/src/distribution/multivariate_uniform.rs @@ -12,11 +12,12 @@ use std::f64; /// /// ``` /// use statrs::distribution::{MultivariateUniform, Continuous}; -/// use statrs::statistics::Distribution; +/// use statrs::statistics::{Distribution, MeanN}; +/// use nalgebra::DVector; /// /// let n = MultivariateUniform::new(vec![-1., 0.], vec![0., 1.]).unwrap(); -/// assert_eq!(n.mean().unwrap(), DVector::from_vec(vec![-0.5, 0.5]); -/// assert_eq!(n.pdf(DVector::from_vec(vec![-0.5, 0.5])), 1.); +/// assert_eq!(n.mean().unwrap(), DVector::from_vec(vec![-0.5, 0.5])); +/// assert_eq!(n.pdf(&DVector::from_vec(vec![-0.5, 0.5])), 1.); /// ``` #[derive(Debug, Clone, PartialEq)] pub struct MultivariateUniform { @@ -40,11 +41,12 @@ impl MultivariateUniform { /// use statrs::distribution::MultivariateUniform; /// use std::f64; /// - /// let mut result = Uniform::new(vec![-1., 0.], vec![0., 1.,]); + /// let mut result = MultivariateUniform::new(vec![-1., 0.], vec![0., 1.,]); /// assert!(result.is_ok()); /// - /// result = Uniform::new(f64::NAN, f64::NAN); - /// result = Uniform::new(vec![0., f64::NAN], vec![f64::NAN, 1.]); + /// result = MultivariateUniform::new(vec![f64::NAN], vec![f64::NAN]); + /// assert!(result.is_err()); + /// result = MultivariateUniform::new(vec![0., f64::NAN], vec![f64::NAN, 1.]); /// assert!(result.is_err()); /// ``` pub fn new(min: Vec, max: Vec) -> Result {