ddof
This commit is contained in:
parent
da03f66ecd
commit
0d2c1ccee7
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user