예제 #1
0
        public void CanCreateInverseGamma([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
        {
            var n = new InverseGamma(a, b);

            Assert.AreEqual(a, n.Shape);
            Assert.AreEqual(b, n.Scale);
        }
예제 #2
0
        public void ValidateToString()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var n = new InverseGamma(1.1d, 2.1d);

            Assert.AreEqual("InverseGamma(α = 1.1, β = 2.1)", n.ToString());
        }
        public void CanSampleSequence()
        {
            var n   = new InverseGamma(1.0, 1.0);
            var ied = n.Samples();

            GC.KeepAlive(ied.Take(5).ToArray());
        }
        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 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 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));
        }
예제 #7
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));
        }
예제 #8
0
        public void ValidateStdDev([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
        {
            var n = new InverseGamma(a, b);

            if (a > 2)
            {
                Assert.AreEqual(b / ((a - 1.0) * Math.Sqrt(a - 2.0)), n.StdDev);
            }
        }
예제 #9
0
        public void ValidateVariance([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] 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);
            }
        }
예제 #10
0
        public void ValidateMean([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
        {
            var n = new InverseGamma(a, b);

            if (a > 1)
            {
                Assert.AreEqual(b / (a - 1.0), n.Mean);
            }
        }
예제 #11
0
        public void ValidateCumulativeDistribution(
            [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(SpecialFunctions.GammaUpperRegularized(a, b / x), n.CumulativeDistribution(x));
        }
        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 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);
            }
        }
        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 ValidateDensity(double a, double b, double x)
        {
            var n = new InverseGamma(a, b);

            if (x >= 0)
            {
                Assert.AreEqual <double>(Math.Pow(b, a) * Math.Pow(x, -a - 1.0) * Math.Exp(-b / x) / SpecialFunctions.Gamma(a), n.Density(x));
            }
            else
            {
                Assert.AreEqual <double>(0.0, n.Density(x));
            }
        }
예제 #16
0
        public void ValidateDensity(
            [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);

            if (x >= 0)
            {
                Assert.AreEqual(Math.Pow(b, a) * Math.Pow(x, -a - 1.0) * Math.Exp(-b / x) / SpecialFunctions.Gamma(a), n.Density(x));
            }
            else
            {
                Assert.AreEqual(0.0, n.Density(x));
            }
        }
 public void SetAFailsWithNonPositiveA(double a)
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.Throws<ArgumentOutOfRangeException>(() => n.Shape = a);
 }
 public void CanCreateInverseGamma(double a, double b)
 {
     var n = new InverseGamma(a, b);
     Assert.AreEqual(a, n.Shape);
     Assert.AreEqual(b, n.Scale);
 }
예제 #19
0
 public void ValidateCumulativeDistribution(double a, double b, double x)
 {
     var n = new InverseGamma(a, b);
     Assert.AreEqual<double>(SpecialFunctions.GammaLowerIncomplete(a, b / x), n.CumulativeDistribution(x));
 }
예제 #20
0
 public void CanSetB(double b)
 {
     var n = new InverseGamma(1.0, 1.0);
     n.Scale = b;
 }
 public void CanSampleSequence()
 {
     var n = new InverseGamma(1.0, 1.0);
     var ied = n.Samples();
     ied.Take(5).ToArray();
 }
        public void CanSample()
        {
            var n = new InverseGamma(1.0, 1.0);

            n.Sample();
        }
예제 #23
0
 public void ValidateMedian()
 {
     var n = new InverseGamma(1.0, 1.0);
     var median = n.Median;
 }
        public void ValidateMedianThrowsNotSupportedException()
        {
            var n = new InverseGamma(1.0, 1.0);

            Assert.Throws <NotSupportedException>(() => { var median = n.Median; });
        }
        public void ValidateMaximum()
        {
            var n = new InverseGamma(1.0, 1.0);

            Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
        }
        public void ValidateToString()
        {
            var n = new InverseGamma(1.1d, 2.1d);

            Assert.AreEqual("InverseGamma(α = 1.1, β = 2.1)", n.ToString());
        }
        public void SetBFailsWithNonPositiveB(double b)
        {
            var n = new InverseGamma(1.0, 1.0);

            n.Scale = b;
        }
        public void ValidateToString()
        {
            var n = new InverseGamma(1.1, 2.1);

            Assert.AreEqual(String.Format("InverseGamma(Shape = {0}, Inverse Scale = {1})", n.Shape, n.Scale), n.ToString());
        }
 public void InverseGammaCreateFailsWithBadParameters(double a, double b)
 {
     var n = new InverseGamma(a, b);
 }
        public void ValidateCumulativeDistribution(double a, double b, double x)
        {
            var n = new InverseGamma(a, b);

            Assert.AreEqual <double>(SpecialFunctions.GammaUpperRegularized(a, b / x), n.CumulativeDistribution(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));
        }
 public void ValidateMedian()
 {
     var n      = new InverseGamma(1.0, 1.0);
     var median = n.Median;
 }
        public void ValidateMode(double a, double b)
        {
            var n = new InverseGamma(a, b);

            Assert.AreEqual(b / (a + 1.0), n.Mode);
        }
 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 ValidateMinimum()
        {
            var n = new InverseGamma(1.0, 1.0);

            Assert.AreEqual(0.0, n.Minimum);
        }
 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);
     }
 }
예제 #37
0
 public void CanSetA(double a)
 {
     var n = new InverseGamma(1.0, 1.0);
     n.Shape = a;
 }
 public void ValidateMedianThrowsNotSupportedException()
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.Throws<NotSupportedException>(() => { var median = n.Median; });
 }
예제 #39
0
 public void ValidateToString()
 {
     var n = new InverseGamma(1.1, 2.1);
     Assert.AreEqual<string>("InverseGamma(Shape = 1.1, Inverse Scale = 2.1)", n.ToString());
 }
 public void ValidateMaximum()
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
 }
        public void CanSetA(double a)
        {
            var n = new InverseGamma(1.0, 1.0);

            n.Shape = a;
        }
 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));
 }
예제 #43
0
 public void ValidateMean([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
 {
     var n = new InverseGamma(a, b);
     if (a > 1)
     {
         Assert.AreEqual(b / (a - 1.0), n.Mean);
     }
 }
예제 #44
0
 public void ValidateVariance([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] 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 SetBFailsWithNonPositiveB(double b)
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.Throws<ArgumentOutOfRangeException>(() => n.Scale = b);
 }
예제 #46
0
 public void ValidateStdDev([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
 {
     var n = new InverseGamma(a, b);
     if (a > 2)
     {
         Assert.AreEqual(b / ((a - 1.0) * Math.Sqrt(a - 2.0)), n.StdDev);
     }
 }
 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);
     }
 }
예제 #48
0
 public void ValidateMode([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
 {
     var n = new InverseGamma(a, b);
     Assert.AreEqual(b / (a + 1.0), n.Mode);
 }
 public void ValidateMode(double a, double b)
 {
     var n = new InverseGamma(a, b);
     Assert.AreEqual(b / (a + 1.0), n.Mode);
 }
예제 #50
0
 public void ValidateDensity(
     [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);
     if (x >= 0)
     {
         Assert.AreEqual(Math.Pow(b, a) * Math.Pow(x, -a - 1.0) * Math.Exp(-b / x) / SpecialFunctions.Gamma(a), n.Density(x));
     }
     else
     {
         Assert.AreEqual(0.0, n.Density(x));
     }
 }
 public void ValidateMinimum()
 {
     var n = new InverseGamma(1.0, 1.0);
     Assert.AreEqual(0.0, n.Minimum);
 }
예제 #52
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 ValidateDensity(double a, double b, double x)
 {
     var n = new InverseGamma(a, b);
     if (x >= 0)
     {
         Assert.AreEqual(Math.Pow(b, a) * Math.Pow(x, -a - 1.0) * Math.Exp(-b / x) / SpecialFunctions.Gamma(a), n.Density(x));
     }
     else
     {
         Assert.AreEqual(0.0, n.Density(x));
     }
 }
예제 #54
0
 public void ValidateCumulativeDistribution(
     [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(SpecialFunctions.GammaUpperRegularized(a, b / x), n.CumulativeDistribution(x));
 }
 public void CanSample()
 {
     var n = new InverseGamma(1.0, 1.0);
     n.Sample();
 }
예제 #56
0
 public void CanCreateInverseGamma([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
 {
     var n = new InverseGamma(a, b);
     Assert.AreEqual(a, n.Shape);
     Assert.AreEqual(b, n.Scale);
 }
 public void ValidateCumulativeDistribution(double a, double b, double x)
 {
     var n = new InverseGamma(a, b);
     Assert.AreEqual(SpecialFunctions.GammaUpperRegularized(a, b / x), n.CumulativeDistribution(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);
        }
 public void ValidateToString()
 {
     var n = new InverseGamma(1.1, 2.1);
     Assert.AreEqual(String.Format("InverseGamma(Shape = {0}, Inverse Scale = {1})", n.Shape, n.Scale), n.ToString());
 }
예제 #60
0
 public void SetBFailsWithNonPositiveB(double b)
 {
     var n = new InverseGamma(1.0, 1.0);
     n.Scale = b;
 }