Beispiel #1
0
        public static Statistics CalculateStatistics(List<double> samples)
        {
            Statistics result = new Statistics();
            result.Mean = Mean(samples);
            double sumX2 = 0;
            double min = 0;
            double max = 0;
            
            //subtract the mean from each of the numbers
            foreach (double sample in samples)
            {
                double delta = result.Mean - sample;
                if (Math.Abs(sample) < min)
                    min = Math.Abs(sample);
                else if (Math.Abs(sample) > max)
                    max = Math.Abs(sample);

                sumX2 += delta * delta;
            }

            result.StdDeviation = Math.Sqrt(sumX2 / samples.Count);
            result.Min = min;
            result.Max = max;
            return result;
        }
Beispiel #2
0
 public void AddSample(double value)
 {
     _samples.Add(value);
     _statistics = null; // clear it
 }