public void ValidateDensityLn(double a, double b, double x)
        {
            var    n        = new InverseGamma(a, b);
            double expected = Math.Log(Math.Pow(b, a) * Math.Pow(x, -a - 1.0) * Math.Exp(-b / x) / SpecialFunctions.Gamma(a));

            Assert.AreEqual(expected, n.DensityLn(x));
            Assert.AreEqual(expected, InverseGamma.PDFLn(a, b, x));
        }
Exemplo n.º 2
0
        public void ValidateDensityLn(
            [Values(0.1, 0.1, 0.1, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double a,
            [Values(0.1, 1.0, Double.PositiveInfinity, 0.1, 1.0, Double.PositiveInfinity, 0.1, 1.0, Double.PositiveInfinity)] double b,
            [Values(1.2, 2.0, 1.1, 1.5, 1.2, 1.5, 5.0, 2.5, 1.0)] double x)
        {
            var n = new InverseGamma(a, b);

            Assert.AreEqual(Math.Log(n.Density(x)), n.DensityLn(x));
        }
 public void ValidateDensityLn(double a, double b, double x)
 {
     var n = new InverseGamma(a, b);
     Assert.AreEqual(Math.Log(n.Density(x)), n.DensityLn(x));
 }
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/Inverse-gamma_distribution">InverseGamma distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the InverseGamma distribution class with parameters shape = 4, scale = 0.5
            var inverseGamma = new InverseGamma(4, 0.5);

            Console.WriteLine(@"1. Initialize the new instance of the InverseGamma distribution class with parameters Shape = {0}, Scale = {1}", inverseGamma.Shape, inverseGamma.Scale);
            Console.WriteLine();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // 4. Generate 100000 samples of the InverseGamma(4, 0.5) distribution and display histogram
            Console.WriteLine(@"4. Generate 100000 samples of the InverseGamma(4, 0.5) distribution and display histogram");
            var data = new double[100000];

            InverseGamma.Samples(data, 4, 0.5);
            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 5. Generate 100000 samples of the InverseGamma(8, 0.5) distribution and display histogram
            Console.WriteLine(@"5. Generate 100000 samples of the InverseGamma(8, 0.5) distribution and display histogram");
            InverseGamma.Samples(data, 8, 0.5);
            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 6. Generate 100000 samples of the InverseGamma(2, 1) distribution and display histogram
            Console.WriteLine(@"6. Generate 100000 samples of the InverseGamma(8, 2) distribution and display histogram");
            InverseGamma.Samples(data, 8, 2);
            ConsoleHelper.DisplayHistogram(data);
        }
Exemplo n.º 5
0
 public void ValidateDensityLn(
     [Values(0.1, 0.1, 0.1, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double a, 
     [Values(0.1, 1.0, Double.PositiveInfinity, 0.1, 1.0, Double.PositiveInfinity, 0.1, 1.0, Double.PositiveInfinity)] double b, 
     [Values(1.2, 2.0, 1.1, 1.5, 1.2, 1.5, 5.0, 2.5, 1.0)] double x)
 {
     var n = new InverseGamma(a, b);
     Assert.AreEqual(Math.Log(n.Density(x)), n.DensityLn(x));
 }
        public void ValidateDensityLn(double a, double b, double x)
        {
            var n = new InverseGamma(a, b);

            Assert.AreEqual <double>(Math.Log(n.Density(x)), n.DensityLn(x));
        }