/// <summary>EP message to <c>double</c>.</summary> /// <param name="Double">Incoming message from <c>double</c>.</param> /// <param name="Integer">Incoming message from <c>integer</c>.</param> /// <returns>The outgoing EP message to the <c>double</c> argument.</returns> /// <remarks> /// <para>The outgoing message is a distribution matching the moments of <c>double</c> as the random arguments are varied. The formula is <c>proj[p(double) sum_(integer) p(integer) factor(double,integer)]/p(double)</c>.</para> /// </remarks> public static Gaussian DoubleAverageConditional(Gaussian Double, Discrete Integer) { if (Integer.IsPointMass) { return(Gaussian.PointMass(Factor.Double(Integer.Point))); } // Z = sum_i int_x q(x) delta(x - i) q(i) dx // = sum_i q(x=i) q(i) double max = double.NegativeInfinity; for (int i = 0; i < Integer.Dimension; i++) { double logp = Double.GetLogProb(i); if (logp > max) { max = logp; } } if (double.IsNegativeInfinity(max)) { throw new AllZeroException(); } GaussianEstimator est = new GaussianEstimator(); for (int i = 0; i < Integer.Dimension; i++) { double logp = Double.GetLogProb(i); est.Add(i, Integer[i] * Math.Exp(logp - max)); } Gaussian result = est.GetDistribution(new Gaussian()); result.SetToRatio(result, Double, ForceProper); return(result); }
/// <summary>Evidence message for EP.</summary> /// <param name="Double">Constant value for <c>double</c>.</param> /// <param name="Integer">Constant value for <c>integer</c>.</param> /// <returns>Logarithm of the factor's contribution the EP model evidence.</returns> /// <remarks> /// <para>The formula for the result is <c>log(factor(double,integer))</c>. Adding up these values across all factors and variables gives the log-evidence estimate for EP.</para> /// </remarks> public static double LogEvidenceRatio(double Double, int Integer) { return((Double == Factor.Double(Integer)) ? 0.0 : double.NegativeInfinity); }