public void CanEstimateParameters(double mu, double sigma)
        {
            var original = new LogNormal(mu, sigma, new Random(100));
            var estimated = LogNormal.Estimate(original.Samples().Take(10000));

            AssertHelpers.AlmostEqualRelative(mu, estimated.Mu, 1);
            AssertHelpers.AlmostEqualRelative(sigma, estimated.Sigma, 1);
        }
        public void SetupDistributions()
        {
            dists = new IDistribution[8];

            dists[0] = new Beta(1.0, 1.0);
            dists[1] = new ContinuousUniform(0.0, 1.0);
            dists[2] = new Gamma(1.0, 1.0);
            dists[3] = new Normal(0.0, 1.0);
            dists[4] = new Bernoulli(0.6);
            dists[5] = new Weibull(1.0, 1.0);
            dists[6] = new DiscreteUniform(1, 10);
            dists[7] = new LogNormal(1.0, 1.0);
        }
 public void ValidateMean(double mu, double sigma, double mean)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqualRelative(mean, n.Mean, 14);
 }
 public void ValidateMaximum()
 {
     var n = new LogNormal(1.0, 2.0);
     Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
 }
Пример #5
0
 public void LogNormalCreateFailsWithBadParameters(double mu, double sigma)
 {
     var n = new LogNormal(mu, sigma);
 }
Пример #6
0
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/Log-normal_distribution">LogNormal distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the LogNormal distribution class with parameters Mu = 0, Sigma = 1
            var logNormal = new LogNormal(0, 1);
            Console.WriteLine(@"1. Initialize the new instance of the LogNormal distribution class with parameters Mu = {0}, Sigma = {1}", logNormal.Mu, logNormal.Sigma);
            Console.WriteLine();

            // 2. Distributuion properties:
            Console.WriteLine(@"2. {0} distributuion properties:", logNormal);

            // Cumulative distribution function
            Console.WriteLine(@"{0} - Сumulative distribution at location '0.3'", logNormal.CumulativeDistribution(0.3).ToString(" #0.00000;-#0.00000"));

            // Probability density
            Console.WriteLine(@"{0} - Probability density at location '0.3'", logNormal.Density(0.3).ToString(" #0.00000;-#0.00000"));

            // Log probability density
            Console.WriteLine(@"{0} - Log probability density at location '0.3'", logNormal.DensityLn(0.3).ToString(" #0.00000;-#0.00000"));

            // Entropy
            Console.WriteLine(@"{0} - Entropy", logNormal.Entropy.ToString(" #0.00000;-#0.00000"));

            // Largest element in the domain
            Console.WriteLine(@"{0} - Largest element in the domain", logNormal.Maximum.ToString(" #0.00000;-#0.00000"));

            // Smallest element in the domain
            Console.WriteLine(@"{0} - Smallest element in the domain", logNormal.Minimum.ToString(" #0.00000;-#0.00000"));

            // Mean
            Console.WriteLine(@"{0} - Mean", logNormal.Mean.ToString(" #0.00000;-#0.00000"));

            // Median
            Console.WriteLine(@"{0} - Median", logNormal.Median.ToString(" #0.00000;-#0.00000"));

            // Mode
            Console.WriteLine(@"{0} - Mode", logNormal.Mode.ToString(" #0.00000;-#0.00000"));

            // Variance
            Console.WriteLine(@"{0} - Variance", logNormal.Variance.ToString(" #0.00000;-#0.00000"));

            // Standard deviation
            Console.WriteLine(@"{0} - Standard deviation", logNormal.StdDev.ToString(" #0.00000;-#0.00000"));

            // Skewness
            Console.WriteLine(@"{0} - Skewness", logNormal.Skewness.ToString(" #0.00000;-#0.00000"));
            Console.WriteLine();

            // 3. Generate 10 samples
            Console.WriteLine(@"3. Generate 10 samples");
            for (var i = 0; i < 10; i++)
            {
                Console.Write(logNormal.Sample().ToString("N05") + @" ");
            }

            Console.WriteLine();
            Console.WriteLine();

            // 4. Generate 100000 samples of the LogNormal(0, 1) distribution and display histogram
            Console.WriteLine(@"4. Generate 100000 samples of the LogNormal(0, 1) distribution and display histogram");
            var data = new double[100000];
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = logNormal.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 5. Generate 100000 samples of the LogNormal(0, 0.5) distribution and display histogram
            Console.WriteLine(@"5. Generate 100000 samples of the LogNormal(0, 0.5) distribution and display histogram");
            logNormal.Sigma = 0.5;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = logNormal.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 6. Generate 100000 samples of the LogNormal(5, 0.25) distribution and display histogram
            Console.WriteLine(@"6. Generate 100000 samples of the LogNormal(5, 0.25) distribution and display histogram");
            logNormal.Mu = 5;
            logNormal.Sigma = 0.25;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = logNormal.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
        }
 public void ValidateToString()
 {
     var n = new LogNormal(1d, 2d);
     Assert.AreEqual("LogNormal(μ = 1, σ = 2)", n.ToString());
 }
 public void ValidateMode(double mu, double sigma, double mode)
 {
     var n = new LogNormal(mu, sigma);
     Assert.AreEqual(mode, n.Mode);
 }
 public void CanSampleSequence()
 {
     var n = new LogNormal(1.0, 2.0);
     var ied = n.Samples();
     ied.Take(5).ToArray();
 }
Пример #10
0
 public void ValidateDensity(double mu, double sigma, double x, double p)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqual(p, n.Density(x), 14);
     AssertHelpers.AlmostEqual(p, LogNormal.PDF(mu, sigma, x), 14);
 }
Пример #11
0
 public void SetSigmaFailsWithNegativeSigma()
 {
     var n = new LogNormal(1.0, 2.0);
     Assert.Throws<ArgumentOutOfRangeException>(() => n.Sigma = -1.0);
 }
Пример #12
0
 public void CanSetMu(double mu)
 {
     var n = new LogNormal(1.0, 2.0);
     n.Mu = mu;
 }
Пример #13
0
 public void ValidateToString()
 {
     var n = new LogNormal(1.0, 2.0);
     AssertEx.AreEqual<string>("LogNormal(Mu = 1, Sigma = 2)", n.ToString());
 }
Пример #14
0
 public void SetSigmaFailsWithNegativeSigma()
 {
     var n = new LogNormal(1.0, 2.0);
     n.Sigma = -1.0;
 }
Пример #15
0
 public void ValidateMedian(double mu, double sigma, double median)
 {
     var n = new LogNormal(mu, sigma);
     Assert.AreEqual(median, n.Median);
 }
Пример #16
0
 public void ValidateMinimum()
 {
     var n = new LogNormal(1.0, 2.0);
     Assert.AreEqual(0.0, n.Minimum);
 }
Пример #17
0
 public void SetSigmaFailsWithNegativeSigma()
 {
     var n = new LogNormal(1.0, 2.0);
     Assert.That(() => n.Sigma = -1.0, Throws.ArgumentException);
 }
Пример #18
0
 public void ValidateSkewness(double mu, double sigma, double skewness)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqualRelative(skewness, n.Skewness, 13);
 }
Пример #19
0
 public void ValidateCumulativeDistribution(double mu, double sigma, double x, double f)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqualRelative(f, n.CumulativeDistribution(x), 7);
     AssertHelpers.AlmostEqualRelative(f, LogNormal.CDF(mu, sigma, x), 7);
 }
Пример #20
0
 public void CanCreateLogNormal(double mu, double sigma)
 {
     var n = new LogNormal(mu, sigma);
     Assert.AreEqual(mu, n.Mu);
     Assert.AreEqual(sigma, n.Sigma);
 }
Пример #21
0
 public void ValidateDensityLn(double mu, double sigma, double x, double p)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqualRelative(p, n.DensityLn(x), 13);
     AssertHelpers.AlmostEqualRelative(p, LogNormal.PDFLn(mu, sigma, x), 13);
 }
Пример #22
0
 public void CanSample()
 {
     var n = new LogNormal(1.0, 2.0);
     n.Sample();
 }
Пример #23
0
 public void ValidateEntropy(double mu, double sigma, double entropy)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqualRelative(entropy, n.Entropy, 14);
 }
Пример #24
0
 public void ValidateInverseCumulativeDistribution(double mu, double sigma, double x, double f)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqualRelative(x, n.InverseCumulativeDistribution(f), 8);
     AssertHelpers.AlmostEqualRelative(x, LogNormal.InvCDF(mu, sigma, f), 8);
 }
Пример #25
0
 public void CanSetSigma(double sigma)
 {
     var n = new LogNormal(1.0, 2.0);
     n.Sigma = sigma;
 }