示例#1
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IsPositiveOp"]/message_doc[@name="IsPositiveAverageConditional(Gaussian)"]/*'/>
        public static Bernoulli IsPositiveAverageConditional([SkipIfUniform, Proper] Gaussian x)
        {
            Bernoulli result = new Bernoulli();

            if (x.IsPointMass)
            {
                result.Point = Factor.IsPositive(x.Point);
            }
            else if (x.IsUniform())
            {
                result.LogOdds = 0.0;
            }
            else if (!x.IsProper())
            {
                throw new ImproperMessageException(x);
            }
            else
            {
                // m/sqrt(v) = (m/v)/sqrt(1/v)
                double z = x.MeanTimesPrecision / Math.Sqrt(x.Precision);
                // p(true) = NormalCdf(z)
                // log(p(true)/p(false)) = NormalCdfLogit(z)
                result.LogOdds = MMath.NormalCdfLogit(z);
            }
            return(result);
        }
示例#2
0
 /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IsPositiveOp"]/message_doc[@name="LogAverageFactor(bool, double)"]/*'/>
 public static double LogAverageFactor(bool isPositive, double x)
 {
     return((isPositive == Factor.IsPositive(x)) ? 0.0 : Double.NegativeInfinity);
 }