Running (normal) statistics.

This class computes the running variance using Welford’s method. Running statistics need only one pass over the data, and do not require all data to be available prior to computing.

References: John D. Cook. Accurately computing running variance. Available on: http://www.johndcook.com/standard_deviation.html Chan, Tony F.; Golub, Gene H.; LeVeque, Randall J. (1983). Algorithms for Computing the Sample Variance: Analysis and Recommendations. The American Statistician 37, 242-247. Ling, Robert F. (1974). Comparison of Several Algorithms for Computing Sample Means and Variances. Journal of the American Statistical Association, Vol. 69, No. 348, 859-866.

Inheritance: IRunningStatistics
コード例 #1
0
        public void StandardDeviationTest()
        {
            double[] values = { 0.5, -1.2, 0.7, 0.2, 1.1 };

            RunningNormalStatistics target = new RunningNormalStatistics();

            for (int i = 0; i < values.Length; i++)
                target.Push(values[i]);

            double expected = values.StandardDeviation();
            double actual = target.StandardDeviation;

            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void ClearTest()
        {
            double[] values = { 0.5, -1.2, 0.7, 0.2, 1.1 };

            RunningNormalStatistics target = new RunningNormalStatistics();

            for (int i = 0; i < values.Length; i++)
                target.Push(values[i]);

            target.Clear();

            double[] values2 = { 1.5, -5.2, 0.7, 1.2, 9.1 };

            for (int i = 0; i < values.Length; i++)
                target.Push(values2[i]);

            Assert.AreEqual(values2.Mean(), target.Mean, 1e-10);
            Assert.AreEqual(values2.StandardDeviation(), target.StandardDeviation, 1e-10);
            Assert.AreEqual(values2.Variance(), target.Variance, 1e-10);
        }
コード例 #3
0
        public void VarianceTest()
        {
            double[] values = { 0.5, -1.2, 0.7, 0.2, 1.1 };

            RunningNormalStatistics target = new RunningNormalStatistics();

            for (int i = 0; i < values.Length; i++)
                target.Push(values[i]);

            double expected = Tools.Variance(values);
            double actual = target.Variance;

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
 public void RunningNormalStatisticsConstructorTest()
 {
     RunningNormalStatistics target = new RunningNormalStatistics();
     Assert.AreEqual(0, target.Mean);
     Assert.AreEqual(0, target.StandardDeviation);
     Assert.AreEqual(0, target.Variance);
 }
コード例 #5
0
ファイル: Feature.cs プロジェクト: Amichai/DataAnalysis
 public double TestUtility()
 {
     RunningNormalStatistics utilityAve = new RunningNormalStatistics();
     int counter = 0;
     foreach (var a in stats) {
         if (a.Value.ElementsSeen > 20) {
             utilityAve.Push(a.Value.ProbabilisticUtility());
             counter++;
         }
     }
     if (counter > 8) {
         return utilityAve.Mean;
     } else {
         //Debug.Print(counter.ToString());
         return -1;
     }
 }