public void CanCreateInverseGamma(double a, double b)
 {
     var n = new InverseGamma(a, b);
     Assert.AreEqual(a, n.Shape);
     Assert.AreEqual(b, n.Scale);
 }
 public void ValidateToString()
 {
     var n = new InverseGamma(1.1d, 2.1d);
     Assert.AreEqual("InverseGamma(α = 1.1, β = 2.1)", n.ToString());
 }
 public void ValidateVariance(double a, double b)
 {
     var n = new InverseGamma(a, b);
     if (a > 2)
     {
         Assert.AreEqual(b * b / ((a - 1.0) * (a - 1.0) * (a - 2.0)), n.Variance);
     }
 }
 public void ValidateMode(double a, double b)
 {
     var n = new InverseGamma(a, b);
     Assert.AreEqual(b / (a + 1.0), n.Mode);
 }
 public void ValidateStdDev(double a, double b)
 {
     var n = new InverseGamma(a, b);
     if (a > 2)
     {
         Assert.AreEqual(b / ((a - 1.0) * Math.Sqrt(a - 2.0)), n.StdDev);
     }
 }
示例#6
0
 public void SetBFailsWithNonPositiveB(double b)
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.That(() => n.Scale = b, Throws.ArgumentException);
 }
 public void ValidateMinimum()
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.AreEqual(0.0, n.Minimum);
 }
 public void ValidateMaximum()
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
 }
 public void ValidateMean(double a, double b)
 {
     var n = new InverseGamma(a, b);
     if (a > 1)
     {
         Assert.AreEqual(b / (a - 1.0), n.Mean);
     }
 }
 public void ValidateCumulativeDistribution(double a, double b, double x)
 {
     var n = new InverseGamma(a, b);
     double expected = SpecialFunctions.GammaUpperRegularized(a, b/x);
     Assert.AreEqual(expected, n.CumulativeDistribution(x));
     Assert.AreEqual(expected, InverseGamma.CDF(a, b, x));
 }
 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));
 }
 public void SetBFailsWithNonPositiveB(double b)
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.Throws<ArgumentOutOfRangeException>(() => n.Scale = b);
 }
 public void SetAFailsWithNonPositiveA(double a)
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.Throws<ArgumentOutOfRangeException>(() => n.Shape = a);
 }
        /// <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];
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = inverseGamma.Sample();
            }

            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.Shape = 8;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = inverseGamma.Sample();
            }

            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.Scale = 2;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = inverseGamma.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
        }
 public void CanSample()
 {
     var n = new InverseGamma(1.0, 1.0);
     n.Sample();
 }
 public void ValidateMedianThrowsNotSupportedException()
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.Throws<NotSupportedException>(() => { var median = n.Median; });
 }
 public void CanSampleSequence()
 {
     var n = new InverseGamma(1.0, 1.0);
     var ied = n.Samples();
     ied.Take(5).ToArray();
 }
示例#18
0
 public void SetAFailsWithNonPositiveA(double a)
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.That(() => n.Shape = a, Throws.ArgumentException);
 }