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

            AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 8);
            AssertHelpers.AlmostEqual(f, LogNormal.CDF(mu, sigma, x), 8);
        }
Пример #2
0
        public void ValidateCumulativeDistribution(
            [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, 0.0, 0.0000000015011556178148777579869633555518882664666520593658, 0.10908001076375810900224507908874442583171381706127, 0.070999149762464508991968731574953594549291668468349, 0.34626224992888089297789445771047690175505847991946, 0.46728530589487698517090261668589508746353129242404, 0.18914969879695093477606645992572208111152994999076, 0.40622798321378106125020505907901206714868922279347, 0.48035707589956665425068652807400957345208517749893, 0.0, 0.0, 0.0, 0.005621455876973168709588070988239748831823850202953, 0.07185716187918271235246980951571040808235628115265, 0.12532699044614938400496547188720940854423187977236, 0.064125647996943514411570834861724406903677144126117, 0.19017302281590810871719754032332631806011441356498, 0.24533064397555500690927047163085419096928289095201, 0.0, 0.0, 0.0, 0.00068304052220788502001572635016579586444611070077399, 0.016636862816580533038130583128179878924863968664206, 0.034729001282904174941366974418836262996834852343018, 0.027363708266690978870139978537188410215717307180775, 0.10075543423327634536450625420610429181921642201567, 0.13802019192453118732001307556787218421918336849121)] double f)
        {
            var n = new LogNormal(mu, sigma);

            AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 8);
        }
Пример #3
0
 public void ValidateCumulativeDistribution(double mu, double sigma, double x, double f)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 8);
 }
Пример #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 ValidateCumulativeDistribution(
     [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, 0.0, 0.0000000015011556178148777579869633555518882664666520593658, 0.10908001076375810900224507908874442583171381706127, 0.070999149762464508991968731574953594549291668468349, 0.34626224992888089297789445771047690175505847991946, 0.46728530589487698517090261668589508746353129242404, 0.18914969879695093477606645992572208111152994999076, 0.40622798321378106125020505907901206714868922279347, 0.48035707589956665425068652807400957345208517749893, 0.0, 0.0, 0.0, 0.005621455876973168709588070988239748831823850202953, 0.07185716187918271235246980951571040808235628115265, 0.12532699044614938400496547188720940854423187977236, 0.064125647996943514411570834861724406903677144126117, 0.19017302281590810871719754032332631806011441356498, 0.24533064397555500690927047163085419096928289095201, 0.0, 0.0, 0.0, 0.00068304052220788502001572635016579586444611070077399, 0.016636862816580533038130583128179878924863968664206, 0.034729001282904174941366974418836262996834852343018, 0.027363708266690978870139978537188410215717307180775, 0.10075543423327634536450625420610429181921642201567, 0.13802019192453118732001307556787218421918336849121)] double f)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 8);
 }