コード例 #1
0
 public override void Construct()
 {
     this.ParameterDictionary.Add(Statistic.Location, LognormalDistribution.Estimate(data.ToArray()).Location);
     this.ParameterDictionary.Add(Statistic.Shape, LognormalDistribution.Estimate(data.ToArray()).Shape);
     this.ParameterDictionary.Add(Statistic.Min, data.Min());
     this.ParameterDictionary.Add(Statistic.Max, data.Max());
     this.ParameterDictionary.Add(Statistic.Median, data[(data.Count / 2) - 1]);
 }
コード例 #2
0
        public void EstimateTest2()
        {
            double[] observations = { 0.04, 0.12, 1.52 };

            double[] weights             = { 0.25, 0.50, 0.25 };
            LognormalDistribution actual = LognormalDistribution.Estimate(observations, weights);

            Assert.AreEqual(-1.76017314060255, actual.Location, 1e-15);
            Assert.AreEqual(1.6893403335885702, actual.Shape);
        }
コード例 #3
0
 public LognormalEstimate(List <double> data) : base(data)
 {
     if (data.Min() <= 0)
     {
         this.score = -1;        //negative data implies it can't be Lognormal
         return;
     }
     this.DistributionType = Distribution.Lognormal;
     this.testDistribution = LognormalDistribution.Estimate(data.ToArray());
     this.RunTestOfFit();
 }
コード例 #4
0
        public void GenerateTest()
        {
            LognormalDistribution target = new LognormalDistribution(2, 5);

            double[] samples = target.Generate(1000000);

            var actual = LognormalDistribution.Estimate(samples);

            actual.Fit(samples);

            Assert.AreEqual(2, actual.Location, 0.01);
            Assert.AreEqual(5, actual.Shape, 0.01);
        }
コード例 #5
0
        public void EstimateTest()
        {
            double[] observations = { 2, 2, 2, 2, 2 };

            NormalOptions options = new NormalOptions()
            {
                Regularization = 0.1
            };

            LognormalDistribution actual = LognormalDistribution.Estimate(observations, options);

            Assert.AreEqual(System.Math.Log(2), actual.Location);
            Assert.AreEqual(System.Math.Sqrt(0.1), actual.Shape);
        }
コード例 #6
0
        public void GenerateTest2()
        {
            LognormalDistribution target = new LognormalDistribution(4, 2);

            double[] samples = new double[1000000];
            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] = target.Generate();
            }

            var actual = LognormalDistribution.Estimate(samples);

            actual.Fit(samples);

            Assert.AreEqual(4, actual.Location, 0.01);
            Assert.AreEqual(2, actual.Shape, 0.01);
        }
コード例 #7
0
        public void EstimateTest1()
        {
            double[] observations =
            {
                1.26, 0.34, 0.70, 1.75, 50.57, 1.55, 0.08, 0.42, 0.50, 3.20,
                0.15, 0.49, 0.95, 0.24,  1.37, 0.17, 6.98, 0.10, 0.94, 0.38
            };

            LognormalDistribution actual = LognormalDistribution.Estimate(observations);


            double expectedLocation = -0.307069523211925;
            double expectedShape    = 1.51701553338489;

            Assert.AreEqual(expectedLocation, actual.Location, 1e-15);
            Assert.AreEqual(expectedShape, actual.Shape, 1e-14);
        }