Exemplo n.º 1
0
 /// <summary>
 /// Get the average logarithm of that distribution under this distribution, i.e. int this(x) log( that(x) ) dx
 /// </summary>
 /// <param name="that"></param>
 /// <returns></returns>
 public double GetAverageLog(TruncatedGamma that)
 {
     if (IsPointMass)
     {
         if (that.IsPointMass && this.Point == that.Point)
         {
             return(0.0);
         }
         else
         {
             return(that.GetLogProb(this.Point));
         }
     }
     else if (this.LowerBound < that.LowerBound || this.UpperBound > that.UpperBound)
     {
         return(double.NegativeInfinity);
     }
     else if (that.IsPointMass)
     {
         return(Double.NegativeInfinity);
     }
     else if (!IsProper())
     {
         throw new ImproperDistributionException(this);
     }
     else
     {
         double m       = GetMean();
         double meanLog = GetMeanLog();
         return((that.Gamma.Shape - 1) * meanLog - that.Gamma.Rate * m - that.GetLogNormalizer());
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Get the logarithm of the average value of that distribution under this distribution, i.e. log(int this(x) that(x) dx)
 /// </summary>
 /// <param name="that"></param>
 /// <returns></returns>
 public double GetLogAverageOf(TruncatedGamma that)
 {
     if (IsPointMass)
     {
         return(that.GetLogProb(Point));
     }
     else if (that.IsPointMass)
     {
         return(GetLogProb(that.Point));
     }
     else
     {
         // neither this nor that is a point mass.
         TruncatedGamma product = this * that;
         return(product.GetLogNormalizer() - this.GetLogNormalizer() - that.GetLogNormalizer());
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Get the integral of this distribution times another distribution raised to a power.
 /// </summary>
 /// <param name="that"></param>
 /// <param name="power"></param>
 /// <returns></returns>
 public double GetLogAverageOfPower(TruncatedGamma that, double power)
 {
     if (IsPointMass)
     {
         return(power * that.GetLogProb(Point));
     }
     else if (that.IsPointMass)
     {
         if (power < 0)
         {
             throw new DivideByZeroException("The exponent is negative and the distribution is a point mass");
         }
         return(this.GetLogProb(that.Point));
     }
     else
     {
         var product = this * (that ^ power);
         return(product.GetLogNormalizer() - this.GetLogNormalizer() - power * that.GetLogNormalizer());
     }
 }