コード例 #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(TruncatedGaussian 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, v;
         GetMeanAndVariance(out m, out v);
         return(-0.5 * that.Gaussian.Precision * (m * m + v) + that.Gaussian.MeanTimesPrecision * m - that.GetLogNormalizer());
     }
 }
コード例 #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(TruncatedGaussian that)
 {
     if (IsPointMass)
     {
         return(that.GetLogProb(Point));
     }
     else if (that.IsPointMass)
     {
         return(GetLogProb(that.Point));
     }
     else
     {
         // neither this nor that is a point mass.
         TruncatedGaussian product = this * that;
         return(product.GetLogNormalizer() - this.GetLogNormalizer() - that.GetLogNormalizer());
     }
 }
コード例 #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(TruncatedGaussian 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());
     }
 }