From 9104c3b789354816b36d77557e1a2b2774008629 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sat, 29 Jun 2013 00:36:52 +0200 Subject: [PATCH] Statistics: do not use term 'samples' in population statistics --- src/Numerics/Statistics/ArrayStatistics.cs | 24 ++++++++--------- .../Statistics/StreamingStatistics.cs | 26 +++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Numerics/Statistics/ArrayStatistics.cs b/src/Numerics/Statistics/ArrayStatistics.cs index 76e8856a..f338eb5e 100644 --- a/src/Numerics/Statistics/ArrayStatistics.cs +++ b/src/Numerics/Statistics/ArrayStatistics.cs @@ -202,24 +202,24 @@ namespace MathNet.Numerics.Statistics /// On a dataset of size N will use an N normalizer and would thus be biased if applied to a subset. /// Returns NaN if data is empty or if any entry is NaN. /// - /// First sample array. - /// Second sample array. - public static double PopulationCovariance(double[] samples1, double[] samples2) + /// First population array. + /// Second population array. + public static double PopulationCovariance(double[] population1, double[] population2) { - if (samples1 == null) throw new ArgumentNullException("samples1"); - if (samples2 == null) throw new ArgumentNullException("samples2"); - if (samples1.Length != samples2.Length) throw new ArgumentException(Resources.ArgumentVectorsSameLength); - if (samples1.Length == 0) return double.NaN; + if (population1 == null) throw new ArgumentNullException("population1"); + if (population2 == null) throw new ArgumentNullException("population2"); + if (population1.Length != population2.Length) throw new ArgumentException(Resources.ArgumentVectorsSameLength); + if (population1.Length == 0) return double.NaN; - var mean1 = Mean(samples1); - var mean2 = Mean(samples2); + var mean1 = Mean(population1); + var mean2 = Mean(population2); var covariance = 0.0; - for (int i = 0; i < samples1.Length; i++) + for (int i = 0; i < population1.Length; i++) { - covariance += (samples1[i] - mean1) * (samples2[i] - mean2); + covariance += (population1[i] - mean1) * (population2[i] - mean2); } - return covariance/samples1.Length; + return covariance/population1.Length; } /// diff --git a/src/Numerics/Statistics/StreamingStatistics.cs b/src/Numerics/Statistics/StreamingStatistics.cs index 23e87116..6be6d5cb 100644 --- a/src/Numerics/Statistics/StreamingStatistics.cs +++ b/src/Numerics/Statistics/StreamingStatistics.cs @@ -245,12 +245,12 @@ namespace MathNet.Numerics.Statistics /// On a dataset of size N will use an N normalizer and would thus be biased if applied to a subset. /// Returns NaN if data is empty or if any entry is NaN. /// - /// First sample stream. - /// Second sample stream. - public static double PopulationCovariance(IEnumerable samples1, IEnumerable samples2) + /// First population stream. + /// Second population stream. + public static double PopulationCovariance(IEnumerable population1, IEnumerable population2) { - if (samples1 == null) throw new ArgumentNullException("samples1"); - if (samples2 == null) throw new ArgumentNullException("samples2"); + if (population1 == null) throw new ArgumentNullException("population1"); + if (population2 == null) throw new ArgumentNullException("population2"); // https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance @@ -259,24 +259,24 @@ namespace MathNet.Numerics.Statistics var mean2 = 0.0; var comoment = 0.0; - using (var s1 = samples1.GetEnumerator()) - using (var s2 = samples2.GetEnumerator()) + using (var p1 = population1.GetEnumerator()) + using (var p2 = population2.GetEnumerator()) { - while (s1.MoveNext()) + while (p1.MoveNext()) { - if (!s2.MoveNext()) + if (!p2.MoveNext()) { throw new ArgumentException(Resources.ArgumentVectorsSameLength); } var mean2Prev = mean2; n++; - mean1 += (s1.Current - mean1) / n; - mean2 += (s2.Current - mean2) / n; - comoment += (s1.Current - mean1) * (s2.Current - mean2Prev); + mean1 += (p1.Current - mean1) / n; + mean2 += (p2.Current - mean2) / n; + comoment += (p1.Current - mean1) * (p2.Current - mean2Prev); } - if (s2.MoveNext()) + if (p2.MoveNext()) { throw new ArgumentException(Resources.ArgumentVectorsSameLength); }