/// <summary> /// Evidence message for EP /// </summary> /// <param name="isPositive">Incoming message from 'isPositive'.</param> /// <param name="x">Incoming message from 'x'.</param> /// <returns>Logarithm of the factor's average value across the given argument distributions</returns> /// <remarks><para> /// The formula for the result is <c>log(sum_(isPositive,x) p(isPositive,x) factor(isPositive,x))</c>. /// </para></remarks> public static double LogAverageFactor(Bernoulli isPositive, Gaussian x) { Bernoulli to_isPositive = IsPositiveAverageConditional(x); return(isPositive.GetLogAverageOf(to_isPositive)); #if false // Z = p(b=T) p(x > 0) + p(b=F) p(x <= 0) // = p(b=F) + (p(b=T) - p(b=F)) p(x > 0) if (x.IsPointMass) { return(Factor.IsPositive(x.Point) ? isPositive.GetLogProbTrue() : isPositive.GetLogProbFalse()); } else if (x.IsUniform()) { return(Bernoulli.LogProbEqual(isPositive.LogOdds, 0.0)); } else { // m/sqrt(v) = (m/v)/sqrt(1/v) double z = x.MeanTimesPrecision / Math.Sqrt(x.Precision); if (isPositive.IsPointMass) { return(isPositive.Point ? MMath.NormalCdfLn(z) : MMath.NormalCdfLn(-z)); } else { return(MMath.LogSumExp(isPositive.GetLogProbTrue() + MMath.NormalCdfLn(z), isPositive.GetLogProbFalse() + MMath.NormalCdfLn(-z))); } } #endif }