/// <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(Beta 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()); } }
/// <summary> /// The log of the integral of the product of this Beta and that Beta /// </summary> /// <param name="that">That beta</param> /// <returns>The log inner product</returns> public double GetLogAverageOf(Beta that) { if (IsPointMass) { return(that.GetLogProb(Point)); } else if (that.IsPointMass) { return(GetLogProb(that.Point)); } else { // int_p Beta(p;a1,a0) Beta(p;b1,b0) d_p = int_p Beta(p;a1+b1-1,a0+b0-1)*z // where z = Beta(a1+b1-1,a0+b0-1) / (Beta(a1,a0) Beta(b1,b0)) double newTrueCount = TrueCount + that.TrueCount - 1; double newFalseCount = FalseCount + that.FalseCount - 1; //if (newTrueCount <= 0 || newFalseCount <= 0) throw new ArgumentException("The product is improper"); return(BetaLn(newTrueCount, newFalseCount) - BetaLn(TrueCount, FalseCount) - BetaLn(that.TrueCount, that.FalseCount)); } }