From 0d2c1ccee7ec921281c325a84a143182a5d83560 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Mon, 2 Dec 2019 13:03:20 +0100 Subject: [PATCH] ddof --- src/moments/variance0.rs | 10 +++++----- src/moments/variance1.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/moments/variance0.rs b/src/moments/variance0.rs index 5913bad..0ea2ab7 100644 --- a/src/moments/variance0.rs +++ b/src/moments/variance0.rs @@ -1,4 +1,4 @@ -const ddof: f64 = 0.; +const ddof0: f64 = 0.; /// Estimate the arithmetic mean and the variance of a sequence of numbers /// ("population"). @@ -51,7 +51,7 @@ impl Variance0 { // See https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance. let n = f64::approx_from(self.avg.len()).unwrap(); self.avg.add_inner(delta_n); - self.sum_2 += delta_n * delta_n * n * (n - ddof); + self.sum_2 += delta_n * delta_n * n * (n - ddof0); } /// Determine whether the sample is empty. @@ -79,10 +79,10 @@ impl Variance0 { /// This is an unbiased estimator of the variance of the population. #[inline] pub fn sample_variance(&self) -> f64 { - if self.avg.len() < 1 + ddof as u64 { + if self.avg.len() < 1 + ddof0 as u64 { return 0.; } - self.sum_2 / f64::approx_from(self.avg.len() - ddof as u64).unwrap() + self.sum_2 / f64::approx_from(self.avg.len() - ddof0 as u64).unwrap() } /// Calculate the population variance of the sample. @@ -91,7 +91,7 @@ impl Variance0 { #[inline] pub fn population_variance(&self) -> f64 { let n = self.avg.len(); - if n < 1 + ddof as u64 { + if n < 1 + ddof0 as u64 { return 0.; } self.sum_2 / f64::approx_from(n).unwrap() diff --git a/src/moments/variance1.rs b/src/moments/variance1.rs index e401c30..67efdfb 100644 --- a/src/moments/variance1.rs +++ b/src/moments/variance1.rs @@ -1,4 +1,4 @@ -const ddof: f64 = 1.; +const ddof1: f64 = 1.; /// Estimate the arithmetic mean and the variance of a sequence of numbers /// ("population"). @@ -51,7 +51,7 @@ impl Variance1 { // See https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance. let n = f64::approx_from(self.avg.len()).unwrap(); self.avg.add_inner(delta_n); - self.sum_2 += delta_n * delta_n * n * (n - ddof); + self.sum_2 += delta_n * delta_n * n * (n - ddof1); } /// Determine whether the sample is empty. @@ -79,10 +79,10 @@ impl Variance1 { /// This is an unbiased estimator of the variance of the population. #[inline] pub fn sample_variance(&self) -> f64 { - if self.avg.len() < 1 + ddof as u64 { + if self.avg.len() < 1 + ddof1 as u64 { return 0.; } - self.sum_2 / f64::approx_from(self.avg.len() - ddof as u64).unwrap() + self.sum_2 / f64::approx_from(self.avg.len() - ddof1 as u64).unwrap() } /// Calculate the population variance of the sample. @@ -91,7 +91,7 @@ impl Variance1 { #[inline] pub fn population_variance(&self) -> f64 { let n = self.avg.len(); - if n < 1 + ddof as u64 { + if n < 1 + ddof1 as u64 { return 0.; } self.sum_2 / f64::approx_from(n).unwrap()