Ejemplo n.º 1
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IntegralOp"]/message_doc[@name="UpperBoundAverageConditional(Gaussian, double, Func{double,double}, ITruncatableDistribution{double})"]/*'/>
        public static Gaussian UpperBoundAverageConditional(Gaussian integral, double upperBound, Func <double, double> func, ITruncatableDistribution <double> distribution)
        {
            CanGetLogProb <double> canGetLogProb = (CanGetLogProb <double>)distribution;
            double dlogf  = integral.MeanTimesPrecision * func(upperBound) * Math.Exp(canGetLogProb.GetLogProb(upperBound));
            double ddlogf = 0; // approximation ignoring integral.Precision

            return(Gaussian.FromDerivatives(upperBound, dlogf, ddlogf, false));
        }
Ejemplo n.º 2
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="RatioGaussianOp"]/message_doc[@name="ProbabilityAverageConditional(Gaussian, CanGetQuantile{double}, double)"]/*'/>
        public static Gaussian ProbabilityAverageConditional(Gaussian quantile, CanGetQuantile <double> canGetQuantile, double probability)
        {
            // The quantile function is the inverse function of the cdf.
            // The derivative of the quantile function is the reciprocal of the pdf.
            double x = canGetQuantile.GetQuantile(probability);
            CanGetLogProb <double> canGetLogProb = (CanGetLogProb <double>)canGetQuantile;
            double dlogp  = quantile.MeanTimesPrecision / Math.Exp(canGetLogProb.GetLogProb(x));
            double ddlogp = 0; // approximation ignoring quantile.Precision

            return(Gaussian.FromDerivatives(probability, dlogp, ddlogp, false));
        }
Ejemplo n.º 3
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="ProbBetweenOp"]/message_doc[@name="LowerBoundAverageConditional(Gaussian, CanGetProbLessThan{double}, double)"]/*'/>
        public static Gaussian LowerBoundAverageConditional(Gaussian probBetween, CanGetProbLessThan <double> canGetProbLessThan, double lowerBound)
        {
            CanGetLogProb <double> canGetLogProb = (CanGetLogProb <double>)canGetProbLessThan;
            // factor is N(ProbBetween(left, right); m, v)
            // logp = -(m - ProbBetween(left, right))^2/(2v)
            // dlogp = (m - ProbBetween(left, right))/v * dProbBetween(left, right)
            // dProbBetween(left, right)/dleft = -p(left)
            // ddlogp = (m - ProbBetween(left, right))/v * ddProbBetween(left, right) - dProbBetween(left, right)/v * dProbBetween(left, right)
            // (m - ProbBetween(left, right))/v -> m/v
            double dlogp  = -Math.Exp(canGetLogProb.GetLogProb(lowerBound)) * probBetween.MeanTimesPrecision;
            double ddlogp = 0; // approximation ignoring probBetween.Precision

            return(Gaussian.FromDerivatives(lowerBound, dlogp, ddlogp, false));
        }
Ejemplo n.º 4
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="ProbBetweenOp"]/message_doc[@name="UpperBoundAverageConditional(Gaussian, CanGetProbLessThan{double}, Gaussian)"]/*'/>
        public static Gaussian UpperBoundAverageConditional(Gaussian probBetween, CanGetProbLessThan <double> canGetProbLessThan, [RequiredArgument] Gaussian upperBound)
        {
            CanGetLogProb <double> canGetLogProb = (CanGetLogProb <double>)canGetProbLessThan;

            // factor is N(ProbBetween(left, right); m, v)
            if (upperBound.IsPointMass)
            {
                // logp = -(m - ProbBetween(left, right))^2/(2v)
                // dlogp = (m - ProbBetween(left, right))/v * dProbBetween(left, right)
                // dProbBetween(left, right)/dright = p(right)
                // ddlogp = (m - ProbBetween(left, right))/v * ddProbBetween(left, right) - dProbBetween(left, right)/v * dProbBetween(left, right)
                double dlogp  = Math.Exp(canGetLogProb.GetLogProb(upperBound.Point)) * probBetween.MeanTimesPrecision;
                double ddlogp = 0; // approximation ignoring probBetween.Precision
                return(Gaussian.FromDerivatives(upperBound.Point, dlogp, ddlogp, false));
            }
            else
            {
                throw new NotSupportedException();
            }
        }