Ejemplo n.º 1
0
        public void ValidateDensityLn(double mu, double sigma, double x, double p)
        {
            var n = new LogNormal(mu, sigma);

            AssertHelpers.AlmostEqual(p, n.DensityLn(x), 14);
            AssertHelpers.AlmostEqual(p, LogNormal.PDFLn(mu, sigma, x), 14);
        }
Ejemplo n.º 2
0
        public void ValidateDensityLn(
            [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(Double.NegativeInfinity, -238.88282294119596467794686179588610665317241097599, -15.514385149961296196003163062199569075052113039686, 0.84857339958981283964373051826407417105725729082041, -0.099903235403144611051953094864849327288457482212211, -0.70943947804316122682964396008813828577195771418027, -1.1046299420497998262946038709903250420774183529995, 0.07924534056485078867266307735371665927517517183681, -1.1702279707433794860424967893989374511050637417043, -1.6132988605030400828957768752511536087538109996183, -719.29643782024317312262673764204041218720576249741, -238.41793403955250272430898754048547661932857086122, -146.85439481068371057247137024006716189469284256628, -2.2350748570877992856465076624973458117562108140674, -1.7001219175524556705452882616787223585705662860012, -1.7610875785399045023354101841009649273236721172008, -0.68941644324162489418137656699398207513321602763104, -1.5268736489667254857801287379715477173125628275598, -1.8496236096394777662704671479709839674424623547308, -1149.5549471196476523788026360929146688367845019398, -507.73265209554698134113704985174959301922196605736, -369.16874994210463740474549611573497379941224077335, -4.1473348984184862316495477617980296904955324113457, -2.8970762200235424747307247601045786110485663457169, -2.7491513791239977024488074547907467152956602019989, -1.3778300581206721947424710027422282714793718026513, -1.9577771978563167352868858774048559682046428490575, -2.2053265778497513183112901654193054111123780652581)] double p)
        {
            var n = new LogNormal(mu, sigma);

            AssertHelpers.AlmostEqual(p, n.DensityLn(x), 14);
        }
Ejemplo n.º 3
0
 public void ValidateDensityLn(double mu, double sigma, double x, double p)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqual(p, n.DensityLn(x), 14);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
 public void ValidateDensityLn(
     [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(Double.NegativeInfinity, -238.88282294119596467794686179588610665317241097599, -15.514385149961296196003163062199569075052113039686, 0.84857339958981283964373051826407417105725729082041, -0.099903235403144611051953094864849327288457482212211, -0.70943947804316122682964396008813828577195771418027, -1.1046299420497998262946038709903250420774183529995, 0.07924534056485078867266307735371665927517517183681, -1.1702279707433794860424967893989374511050637417043, -1.6132988605030400828957768752511536087538109996183, -719.29643782024317312262673764204041218720576249741, -238.41793403955250272430898754048547661932857086122, -146.85439481068371057247137024006716189469284256628, -2.2350748570877992856465076624973458117562108140674, -1.7001219175524556705452882616787223585705662860012, -1.7610875785399045023354101841009649273236721172008, -0.68941644324162489418137656699398207513321602763104, -1.5268736489667254857801287379715477173125628275598, -1.8496236096394777662704671479709839674424623547308, -1149.5549471196476523788026360929146688367845019398, -507.73265209554698134113704985174959301922196605736, -369.16874994210463740474549611573497379941224077335, -4.1473348984184862316495477617980296904955324113457, -2.8970762200235424747307247601045786110485663457169, -2.7491513791239977024488074547907467152956602019989, -1.3778300581206721947424710027422282714793718026513, -1.9577771978563167352868858774048559682046428490575, -2.2053265778497513183112901654193054111123780652581)] double p)
 {
     var n = new LogNormal(mu, sigma);
     AssertHelpers.AlmostEqual(p, n.DensityLn(x), 14);
 }