コード例 #1
0
ファイル: GammaPower.cs プロジェクト: k1moday/infer
 /// <summary>
 /// Get the mean and variance
 /// </summary>
 /// <param name="mean">Where to put the mean</param>
 /// <param name="variance">Where to put the variance</param>
 public void GetMeanAndVariance(out double mean, out double variance)
 {
     if (Power == 0)
     {
         mean     = 1;
         variance = 0;
     }
     if (IsPointMass)
     {
         mean     = Point;
         variance = 0;
     }
     else if (!IsProper() && Rate != 0)
     {
         throw new ImproperDistributionException(this);
     }
     else
     {
         double logMean = GetLogMeanPower(1);
         mean = Math.Exp(logMean);
         if (Rate == 0 && Shape + 2 * Power == 0 && 2 * Power < -1)
         {
             variance = 0;
         }
         else if (Shape + 2 * Power <= 0)
         {
             variance = double.PositiveInfinity;
         }
         else
         {
             double logMean2 = GetLogMeanPower(2);
             if (logMean2 > double.MaxValue)
             {
                 variance = double.PositiveInfinity;
             }
             else
             {
                 variance = MMath.DifferenceOfExp(logMean2, 2 * logMean);
             }
         }
     }
 }