Beispiel #1
0
 public void Clear()
 {
     x_stats.Clear();
     y_stats.Clear();
     S_xy = 0.0;
     n    = 0;
 }
Beispiel #2
0
        public void TestMeanAndVariacneConsistency()
        {
            const int   numSamples = 100000;
            double      mean, stdev;
            RunningStat rs        = new RunningStat();
            Random      defaultrs = new Random();
            Poisson     poisson   = new Poisson();

            rs.Clear();
            mean           = 2000; stdev = Math.Sqrt(2000);
            poisson.Lambda = 2000;
            for (int i = 0; i < numSamples; ++i)
            {
                rs.Push(poisson.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("Poisson Discrete", mean, stdev * stdev, rs.Mean(), rs.Variance());
        }
Beispiel #3
0
        public void TestMeanAndVariacneConsistency()
        {
            const int   numSamples = 100000;
            double      mean, stdev;
            RunningStat rs        = new RunningStat();
            Random      defaultrs = new Random();
            Triangular  tri       = new Triangular();

            rs.Clear();
            var a = tri.LowerBound; var b = tri.UpperBound; var c = tri.Mode;

            mean = (a + b + c) / 3; stdev = Math.Sqrt((a * a + b * b + c * c - a * b - a * c - b * c) / 18);
            for (int i = 0; i < numSamples; ++i)
            {
                rs.Push(tri.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("Triangular", mean, stdev * stdev, rs.Mean(), rs.Variance());
        }
Beispiel #4
0
        public void TestMeanAndVariacneConsistency()
        {
            const int   numSamples = 100000;
            double      mean, stdev;
            RunningStat rs        = new RunningStat();
            Random      defaultrs = new Random();
            Gamma       gamma     = new Gamma();

            rs.Clear();
            mean = 2; stdev = 5;
            for (int i = 0; i < numSamples; ++i)
            {
                gamma.Mean = mean;
                gamma.StandardDeviation = stdev;
                rs.Push(gamma.Sample(defaultrs));                                                       //yy
            }
            PrintResult.CompareMeanAndVariance("gamma", mean, stdev * stdev, rs.Mean(), rs.Variance()); // TODO: result not consistent need to fix the bug
        }
Beispiel #5
0
        public void TestMeanAndVariacneConsistency_Std()
        {
            const int   numSamples = 100000;
            double      mean, stdev;
            RunningStat rs        = new RunningStat();
            Random      defaultrs = new Random();
            Normal      normal    = new Normal();

            rs.Clear();
            mean = 2; stdev = 5;
            for (int i = 0; i < numSamples; ++i)
            {
                normal.Mean = mean;
                normal.StandardDeviation = stdev;
                rs.Push(normal.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("normal", mean, stdev * stdev, rs.Mean(), rs.Variance());
        }
Beispiel #6
0
        public void TestMeanAndVariacneConsistency()
        {
            const int   numSamples = 100000;
            double      mean, stdev;
            RunningStat rs          = new RunningStat();
            Random      defaultrs   = new Random();
            Exponential exponential = new Exponential();

            rs.Clear();
            mean = 2; stdev = 2;
            for (int i = 0; i < numSamples; ++i)
            {
                exponential.StandardDeviation = 2;
                //exponential.Mean = mean;
                rs.Push(exponential.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("exponential", mean, stdev * stdev, rs.Mean(), rs.Variance());
        }
Beispiel #7
0
        public void TestMeanAndVariacneConsistency()
        {
            const int   numSamples = 100000;
            double      mean, stdev;
            RunningStat rs        = new RunningStat();
            Random      defaultrs = new Random();
            Uniform     uniform   = new Uniform();

            rs.Clear();
            var a = uniform.UpperBound;
            var b = uniform.LowerBound;

            mean = (a + b) / 2; stdev = Math.Sqrt((b - a) * (b - a) / 12);
            for (int i = 0; i < numSamples; ++i)
            {
                rs.Push(uniform.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("uniform", mean, stdev * stdev, rs.Mean(), rs.Variance());
        }
Beispiel #8
0
        public void TestMeanAndVariacneConsistency()
        {
            List <int> numList = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            const int     numSamples = 100000;
            double        mean, stdev;
            RunningStat   rs        = new RunningStat();
            Random        defaultrs = new Random();
            Uniform <int> uniform   = new Uniform <int>();

            uniform.Candidates = numList;
            rs.Clear();
            mean = 50; stdev = 0;
            for (int i = 0; i < numSamples; ++i)
            {
                rs.Push(uniform.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("uniform categorical", mean, stdev * stdev, rs.Mean(), rs.Variance());
        }
Beispiel #9
0
        public void TestMeanAndVariacneConsistency()
        {
            const int   numSamples = 100000;
            double      mean, stdev;
            RunningStat rs        = new RunningStat();
            Random      defaultrs = new Random();
            Uniform     uniform   = new Uniform();

            rs.Clear();
            var a = Convert.ToDouble(uniform.UpperBound);
            var b = Convert.ToDouble(uniform.LowerBound);

            mean = (a + b) / 2; stdev = Math.Sqrt(0.25);
            for (int i = 0; i < numSamples; ++i)
            {
                rs.Push(uniform.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("uniform", mean, stdev * stdev, rs.Mean(), rs.Variance());
            Assert.IsTrue(Math.Abs(mean - rs.Mean()) < 0.1);
            Assert.IsTrue(Math.Abs(stdev * stdev - rs.Variance()) < 0.1);
        }
Beispiel #10
0
        public void TestMeanAndVariacneConsistency_MuSigma()
        {
            const int   numSamples = 100000;
            double      mean, stdev;
            RunningStat rs        = new RunningStat();
            Random      defaultrs = new Random();
            LogNormal   logNormal = new LogNormal();

            rs.Clear();
            mean = 2; stdev = 5;
            var muTemp    = Math.Log(mean) - 0.5 * Math.Log(1 + stdev * stdev / mean / mean);
            var sigmaTemp = Math.Sqrt(Math.Log(1 + stdev * stdev / mean / mean));

            for (int i = 0; i < numSamples; ++i)
            {
                logNormal.Mu    = muTemp;
                logNormal.Sigma = sigmaTemp;

                rs.Push(logNormal.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("logNormal", mean, stdev * stdev, rs.Mean(), rs.Variance());
        }
Beispiel #11
0
        public void TestMeanAndVariacneConsistency_Mean()
        {
            const int numSamples = 100000;
            double    mean, variance;

            RunningStat rs        = new RunningStat();
            Random      defaultrs = new Random();
            Beta        beta      = new Beta();

            rs.Clear();
            //double a = 2, b = 70;

            //mean = a / (a + b);
            //variance = mean * (1 - mean) / (a + b + 1);
            mean = 0.1; variance = 0.1 * 0.1;
            for (int i = 0; i < numSamples; ++i)
            {
                beta.Mean = mean;
                beta.StandardDeviation = Math.Sqrt(variance);
                rs.Push(beta.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("Beta", mean, variance, rs.Mean(), rs.Variance());
        }