Пример #1
0
        public void ValidateDensity(double mu, double sigma, double x, double p)
        {
            var n = new LogNormal(mu, sigma);

            AssertHelpers.AlmostEqualRelative(p, n.Density(x), 13);
            AssertHelpers.AlmostEqualRelative(p, LogNormal.PDF(mu, sigma, x), 13);
        }
Пример #2
0
        public void ValidateDensity(
            [Values(-0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000)] double mu,
            [Values(0.100000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000)] double sigma,
            [Values(-0.100000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000)] double x,
            [Values(0.0, 1.7968349035073582236359415565799753846986440127816e-104, 0.00000018288923328441197822391757965928083462391836798722, 2.3363114904470413709866234247494393485647978367885, 0.90492497850024368541682348133921492204585092983646, 0.49191985207660942803818797602364034466489243416574, 0.33133347214343229148978298237579567194870525187207, 1.0824698632626565182080576574958317806389057196768, 0.31029619474753883558901295436486123689563749784867, 0.19922929916156673799861939824205622734205083805245, 4.1070141770545881694056265342787422035256248474059e-313, 2.8602688726477103843476657332784045661507239533567e-104, 1.6670425710002183246335601541889400558525870482613e-64, 0.10698412103361841220076392503406214751353235895732, 0.18266125308224685664142384493330155315630876975024, 0.17185785323404088913982425377565512294017306418953, 0.50186885259059181992025035649158160252576845315332, 0.21721369314437986034957451699565540205404697589349, 0.15729636000661278918949298391170443742675565300598, 5.6836826548848916385760779034504046896805825555997e-500, 3.1225608678589488061206338085285607881363155340377e-221, 4.6994713794671660918554320071312374073172560048297e-161, 0.015806486291412916772431170442330946677601577502353, 0.055184331257528847223852028950484131834529030116388, 0.063982134749859504449658286955049840393511776984362, 0.25212505662402617595900822552548977822542300480086, 0.14117186955911792460646517002386088579088567275401, 0.11021452580363707866161369621432656293405065561317)] double p)
        {
            var n = new LogNormal(mu, sigma);

            AssertHelpers.AlmostEqual(p, n.Density(x), 14);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
 }
Пример #6
0
 public void ValidateDensity(
     [Values(-0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000)] double mu, 
     [Values(0.100000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000)] double sigma, 
     [Values(-0.100000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000)] double x, 
     [Values(0.0, 1.7968349035073582236359415565799753846986440127816e-104, 0.00000018288923328441197822391757965928083462391836798722, 2.3363114904470413709866234247494393485647978367885, 0.90492497850024368541682348133921492204585092983646, 0.49191985207660942803818797602364034466489243416574, 0.33133347214343229148978298237579567194870525187207, 1.0824698632626565182080576574958317806389057196768, 0.31029619474753883558901295436486123689563749784867, 0.19922929916156673799861939824205622734205083805245, 4.1070141770545881694056265342787422035256248474059e-313, 2.8602688726477103843476657332784045661507239533567e-104, 1.6670425710002183246335601541889400558525870482613e-64, 0.10698412103361841220076392503406214751353235895732, 0.18266125308224685664142384493330155315630876975024, 0.17185785323404088913982425377565512294017306418953, 0.50186885259059181992025035649158160252576845315332, 0.21721369314437986034957451699565540205404697589349, 0.15729636000661278918949298391170443742675565300598, 5.6836826548848916385760779034504046896805825555997e-500, 3.1225608678589488061206338085285607881363155340377e-221, 4.6994713794671660918554320071312374073172560048297e-161, 0.015806486291412916772431170442330946677601577502353, 0.055184331257528847223852028950484131834529030116388, 0.063982134749859504449658286955049840393511776984362, 0.25212505662402617595900822552548977822542300480086, 0.14117186955911792460646517002386088579088567275401, 0.11021452580363707866161369621432656293405065561317)] double p)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqual(p, n.Density(x), 14);
 }