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);
            Assert.AreEqual(values2.Length, target.Count);
        }
Exemple #2
0
 public void Add(double a)
 {
     if (a < minVal)
     {
         minVal = a;
     }
     if (a > maxVal)
     {
         maxVal = a;
     }
     stat.Push(a);
     ElementsSeen++;
 }
Exemple #3
0
 public void Add(double eval, double probabilityReturned)
 {
     if (eval < minVal)
     {
         minVal = eval;
     }
     if (eval > maxVal)
     {
         maxVal = eval;
     }
     stat.Push(eval);
     probReturnedWhenCorrect.Push(probabilityReturned);
     ElementsSeen++;
     ProbabilityUtilData = true;
 }
Exemple #4
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 = Tools.StandardDeviation(values);
            double actual   = target.StandardDeviation;

            Assert.AreEqual(expected, actual);
        }
        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 = values.Variance();
            double actual   = target.Variance;

            Assert.AreEqual(expected, actual);
        }
Exemple #6
0
        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);
            }
        }
Exemple #7
0
        public double Apply(double a)
        {
            if (maxVal == double.MinValue || minVal == double.MaxValue)
            {
                return(0);
            }
            if (a > maxVal || a < minVal)
            {
                return(0);
            }
            double range = maxVal - minVal;

            if (range == 0)
            {
                range = .0001;
            }
            //double distanceFromMean = Math.Abs(stat.Mean - a) / (maxVal - minVal);
            double distanceFromMean = Math.Abs(minVal + range / 2.0 - a) / (range);
            double prob             = Math.Abs(2 - distanceFromMean * 2) / range;

            probReturnedInGeneral.Push(prob);
            //Debug.Print(prob.ToString());
            return(prob);
        }