/// <summary>Evidence message for EP.</summary> /// <param name="sample">Incoming message from <c>sample</c>.</param> /// <param name="mean">Incoming message from <c>mean</c>.</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_(sample,mean) p(sample,mean) factor(sample,mean))</c>.</para> /// </remarks> public static double LogAverageFactor(Poisson sample, Gamma mean) { if (sample.IsUniform()) { return(0); } if (sample.IsPointMass) { return(LogAverageFactor(sample.Point, mean, MeanAverageConditional(sample.Point))); } if (sample.Precision != 0) { throw new NotImplementedException("sample.Precision != 0 is not implemented"); } return(-mean.Shape * Math.Log(1 + (1 - sample.Rate) / mean.Rate) - sample.GetLogNormalizer()); }