/// <summary>Evidence message for EP.</summary>
        /// <param name="sample">Constant value for <c>sample</c>.</param>
        /// <param name="probTrue">Incoming message from <c>probTrue</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_(probTrue) p(probTrue) factor(sample,probTrue))</c>.</para>
        /// </remarks>
        public static double LogAverageFactor(IList <int> sample, SparseBetaList probTrue)
        {
            Func <bool, Beta, double> f = BernoulliFromBetaOp.LogAverageFactor;

            return(f.Map(BernoulliIntegerSubset.SubsetToList(sample, probTrue.Count), probTrue).EnumerableSum(x => x));
        }
        /// <summary>Evidence message for EP.</summary>
        /// <param name="sample">Constant value for <c>sample</c>.</param>
        /// <param name="probTrue">Constant value for <c>probTrue</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(sample,probTrue))</c>. Adding up these values across all factors and variables gives the log-evidence estimate for EP.</para>
        /// </remarks>
        public static double LogEvidenceRatio(IList <int> sample, ISparseList <double> probTrue)
        {
            Func <bool, double, double> f = BernoulliFromBetaOp.LogEvidenceRatio;

            return(f.Map(BernoulliIntegerSubset.SubsetToList(sample, probTrue.Count), probTrue).EnumerableSum(x => x));
        }
 /// <summary>VMP message to <c>probTrue</c>.</summary>
 /// <param name="sample">Constant value for <c>sample</c>.</param>
 /// <param name="result">Modified to contain the outgoing message.</param>
 /// <returns>
 ///   <paramref name="result" />
 /// </returns>
 /// <remarks>
 ///   <para>The outgoing message is the factor viewed as a function of <c>probTrue</c> conditioned on the given values.</para>
 /// </remarks>
 public static SparseBetaList ProbTrueAverageLogarithm(IList <int> sample, SparseBetaList result)
 {
     result.SetToFunction(BernoulliIntegerSubset.SubsetToList(sample, result.Count), s => BernoulliFromBetaOp.ProbTrueAverageLogarithm(s));
     return(result);
 }