示例#1
0
 /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="ProbBetweenOp"]/message_doc[@name="ProbBetweenAverageConditional(CanGetProbLessThan{double}, Gaussian, Gaussian)"]/*'/>
 public static Gaussian ProbBetweenAverageConditional(CanGetProbLessThan <double> canGetProbLessThan, [RequiredArgument] Gaussian lowerBound, [RequiredArgument] Gaussian upperBound)
 {
     if (lowerBound.IsPointMass && upperBound.IsPointMass)
     {
         return(Gaussian.PointMass(canGetProbLessThan.GetProbBetween(lowerBound.Point, upperBound.Point)));
     }
     else
     {
         throw new NotSupportedException();
     }
 }
示例#2
0
 /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="ProbBetweenOp"]/message_doc[@name="LowerBoundAverageConditional(Gaussian, CanGetProbLessThan{double}, Gaussian)"]/*'/>
 public static Gaussian LowerBoundAverageConditional(Gaussian probBetween, CanGetProbLessThan <double> canGetProbLessThan, [RequiredArgument] Gaussian lowerBound)
 {
     // factor is N(ProbBetween(left, right); m, v)
     if (lowerBound.IsPointMass)
     {
         return(LowerBoundAverageConditional(probBetween, canGetProbLessThan, lowerBound.Point));
     }
     else
     {
         throw new NotSupportedException();
     }
 }
示例#3
0
 internal void CheckGetQuantile(CanGetQuantile canGetQuantile, CanGetProbLessThan canGetProbLessThan, int minPercent = 0, int maxPercent = 100)
 {
     for (int i = minPercent; i < maxPercent; i++)
     {
         // probability = 1.0 is excluded
         double probability   = i / 100.0;
         double x             = canGetQuantile.GetQuantile(probability);
         double probLessThanX = canGetProbLessThan.GetProbLessThan(x);
         Assert.True(probLessThanX <= probability);
         double next             = MMath.NextDouble(x);
         double probLessThanNext = canGetProbLessThan.GetProbLessThan(next);
         Assert.True(probLessThanNext > probability);
     }
 }
示例#4
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));
        }
示例#5
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();
            }
        }
示例#6
0
        private void CheckProbLessThan(CanGetProbLessThan canGetProbLessThan, List <double> x, double maximumError)
        {
            x.Sort();
            var sortedData = new OuterQuantiles(x.ToArray());
            // check that quantiles match within the desired accuracy
            var    min        = MMath.Min(x);
            var    max        = MMath.Max(x);
            var    range      = max - min;
            var    margin     = range * 0.01;
            var    testPoints = EpTests.linspace(min - margin, max + margin, 100);
            double maxError   = 0;

            foreach (var testPoint in testPoints)
            {
                var trueRank = sortedData.GetProbLessThan(testPoint);
                var estRank  = canGetProbLessThan.GetProbLessThan(testPoint);
                var error    = System.Math.Abs(trueRank - estRank);
                maxError = System.Math.Max(maxError, error);
            }
            Console.WriteLine($"max rank error = {maxError}");
            Assert.True(maxError <= maximumError);
        }
示例#7
0
 public TruncatableDistribution(CanGetProbLessThan <T> canGetProbLessThan)
 {
     this.CanGetProbLessThan = canGetProbLessThan;
 }
示例#8
0
文件: Factor.cs 项目: kant2002/infer
 public static double ProbBetween <T>(CanGetProbLessThan <T> canGetProbLessThan, T lowerBound, T upperBound)
 {
     return(canGetProbLessThan.GetProbBetween(lowerBound, upperBound));
 }
示例#9
0
文件: Factor.cs 项目: kant2002/infer
 public static double ProbLessThan <T>(CanGetProbLessThan <T> canGetProbLessThan, T upperBound)
 {
     return(canGetProbLessThan.GetProbLessThan(upperBound));
 }
示例#10
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="RatioGaussianOp"]/message_doc[@name="ProbabilityAverageConditional(Gaussian, CanGetQuantile{double}, Gaussian)"]/*'/>
        public static Gaussian ProbabilityAverageConditional(double quantile, CanGetQuantile <double> canGetQuantile)
        {
            CanGetProbLessThan <double> canGetProbLessThan = (CanGetProbLessThan <double>)canGetQuantile;

            return(Gaussian.PointMass(canGetProbLessThan.GetProbLessThan(quantile)));
        }