public void GammaUpperTest()
        {
            double[,] gammaUpperScale_pairs = ReadPairs(Path.Combine(TestUtils.DataFolderPath, "SpecialFunctionsValues", "GammaUpperScale.csv"));
            CheckFunctionValues(nameof(MMath.GammaUpperScale), MMath.GammaUpperScale, gammaUpperScale_pairs);

            double[,] gammaLower_pairs = ReadPairs(Path.Combine(TestUtils.DataFolderPath, "SpecialFunctionsValues", "GammaLower.csv"));
            CheckFunctionValues(nameof(MMath.GammaLower), MMath.GammaLower, gammaLower_pairs);

            /* In python mpmath:
             * from mpmath import *
             * mp.dps = 500
             * mp.pretty = True
             * gammainc(mpf('1'),mpf('1'),mpf('inf'),regularized=True)
             */
            double[,] gammaUpperRegularized_pairs = ReadPairs(Path.Combine(TestUtils.DataFolderPath, "SpecialFunctionsValues", "GammaUpperRegularized.csv"));
            CheckFunctionValues("GammaUpperRegularized", (a, x) => MMath.GammaUpper(a, x, true), gammaUpperRegularized_pairs);

            /* In python mpmath:
             * from mpmath import *
             * mp.dps = 500
             * mp.pretty = True
             * gammainc(mpf('1'),mpf('1'),mpf('inf'),regularized=False)
             */
            double[,] gammaUpper_pairs = ReadPairs(Path.Combine(TestUtils.DataFolderPath, "SpecialFunctionsValues", "GammaUpper.csv"));
            CheckFunctionValues("GammaUpper", (a, x) => MMath.GammaUpper(a, x, false), gammaUpper_pairs);
        }
예제 #2
0
 /// <summary>
 /// Computes E[x^power]
 /// </summary>
 /// <returns></returns>
 public double GetMeanPower(double power)
 {
     if (power == 0.0)
     {
         return(1.0);
     }
     else if (IsPointMass)
     {
         return(Math.Pow(Point, power));
     }
     //else if (Rate == 0.0) return (power > 0) ? Double.PositiveInfinity : 0.0;
     else if (!IsProper())
     {
         throw new ImproperDistributionException(this);
     }
     else if (this.Gamma.Shape <= -power && LowerBound == 0)
     {
         throw new ArgumentException("Cannot compute E[x^" + power + "] for " + this + " (shape <= " + (-power) + ")");
     }
     else
     {
         double Z = GetNormalizer();
         double shapePlusPower = this.Gamma.Shape + power;
         double Z1;
         bool   regularized = shapePlusPower >= 1;
         if (regularized)
         {
             Z1 = Math.Exp(MMath.GammaLn(shapePlusPower) - MMath.GammaLn(this.Gamma.Shape)) *
                  (MMath.GammaLower(shapePlusPower, this.Gamma.Rate * UpperBound) - MMath.GammaLower(shapePlusPower, this.Gamma.Rate * LowerBound));
         }
         else
         {
             Z1 = Math.Exp(-MMath.GammaLn(this.Gamma.Shape)) *
                  (MMath.GammaUpper(shapePlusPower, this.Gamma.Rate * LowerBound, regularized) - MMath.GammaUpper(shapePlusPower, this.Gamma.Rate * UpperBound, regularized));
         }
         return(Math.Pow(this.Gamma.Rate, -power) * Z1 / Z);
     }
 }