Esempio n. 1
0
        private void GammaEstimator(double shape, double rate)
        {
            Rand.Restart(12347);
            Gamma                g   = Gamma.FromShapeAndRate(shape, rate);
            Estimator <Gamma>    ge  = EstimatorFactory.Instance.CreateEstimator <Gamma, double>(Gamma.Uniform());
            Accumulator <double> gea = ge as Accumulator <double>;

            for (int i = 0; i < 10000; i++)
            {
                double d = g.Sample();
                gea.Add(d);
            }

            Gamma gest = Gamma.Uniform();

            gest = ge.GetDistribution(gest);

            double expectedMean  = g.GetMean();
            double expectedSDev  = System.Math.Sqrt(g.GetVariance());
            double estimatedMean = gest.GetMean();
            double estimatedSDev = System.Math.Sqrt(gest.GetVariance());

            Assert.True(System.Math.Abs(expectedMean - estimatedMean) < 0.02);
            Assert.True(System.Math.Abs(expectedSDev - estimatedSDev) < 0.02);
        }
Esempio n. 2
0
        private void GaussianEstimator(double mean, double precision)
        {
            Rand.Restart(12347);
            Gaussian             g   = Gaussian.FromMeanAndPrecision(mean, precision);
            Estimator <Gaussian> ge  = EstimatorFactory.Instance.CreateEstimator <Gaussian, double>(Gaussian.Uniform());
            Accumulator <double> gea = ge as Accumulator <double>;

            for (int i = 0; i < 10000; i++)
            {
                gea.Add(g.Sample());
            }

            Gaussian gest = Gaussian.Uniform();

            gest = ge.GetDistribution(gest);

            double expectedMean  = g.GetMean();
            double expectedSDev  = System.Math.Sqrt(g.GetVariance());
            double estimatedMean = gest.GetMean();
            double estimatedSDev = System.Math.Sqrt(gest.GetVariance());

            Assert.True(System.Math.Abs(expectedMean - estimatedMean) < 0.02);
            Assert.True(System.Math.Abs(expectedSDev - estimatedSDev) < 0.02);
        }
Esempio n. 3
0
 /// <summary>
 /// Get the estimated distribution from the samples
 /// </summary>
 /// <param name="result"></param>
 /// <returns></returns>
 public TDist GetDistribution(TDist result)
 {
     return(estimator.GetDistribution(result));
 }