Example #1
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoubleOp"]/message_doc[@name="DoubleAverageConditional(Gaussian, Discrete)"]/*'/>
        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] * System.Math.Exp(logp - max));
            }
            Gaussian result = est.GetDistribution(new Gaussian());

            result.SetToRatio(result, Double, ForceProper);
            return(result);
        }
Example #2
0
 /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoubleOp"]/message_doc[@name="LogEvidenceRatio(double, int)"]/*'/>
 public static double LogEvidenceRatio(double Double, int Integer)
 {
     return((Double == Factor.Double(Integer)) ? 0.0 : double.NegativeInfinity);
 }