コード例 #1
0
ファイル: MathUtils.cs プロジェクト: nhannd/Xian
        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;
        }
コード例 #2
0
 public void AddSample(double value)
 {
     _samples.Add(value);
     _statistics = null; // clear it
 }