Beispiel #1
0
 public OuterQuantiles(int quantileCount, CanGetQuantile canGetQuantile) : this(quantileCount)
 {
     for (int i = 0; i < quantileCount; i++)
     {
         this.quantiles[i] = canGetQuantile.GetQuantile(i / (quantileCount - 1.0));
     }
 }
 public InnerQuantiles(int quantileCount, CanGetQuantile canGetQuantile) : this(quantileCount)
 {
     for (int i = 0; i < quantileCount; i++)
     {
         this.quantiles[i] = canGetQuantile.GetQuantile((i + 1.0) / (quantileCount + 1.0));
     }
 }
Beispiel #3
0
 public OuterQuantiles(int quantileCount, CanGetQuantile canGetQuantile)
 {
     this.quantiles = new double[quantileCount];
     for (int i = 0; i < quantileCount; i++)
     {
         this.quantiles[i] = canGetQuantile.GetQuantile(i / (quantileCount - 1.0));
     }
 }
Beispiel #4
0
        public static InnerQuantiles FromDistribution(int quantileCount, CanGetQuantile canGetQuantile)
        {
            if (quantileCount == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(quantileCount), quantileCount, "quantileCount == 0");
            }
            var quantiles = Util.ArrayInit(quantileCount, i => canGetQuantile.GetQuantile((i + 1.0) / (quantileCount + 1.0)));

            return(new InnerQuantiles(quantiles));
        }
Beispiel #5
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));
        }
Beispiel #6
0
 /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="RatioGaussianOp"]/message_doc[@name="QuantileAverageConditional(CanGetQuantile{double}, Gaussian)"]/*'/>
 public static Gaussian QuantileAverageConditional(CanGetQuantile <double> canGetQuantile, Gaussian probability)
 {
     if (probability.IsPointMass)
     {
         return(Gaussian.PointMass(canGetQuantile.GetQuantile(probability.Point)));
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Beispiel #7
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);
     }
 }
 public InnerQuantiles(int quantileCount, CanGetQuantile canGetQuantile)
 {
     if (quantileCount == 0)
     {
         throw new ArgumentException("quantileCount == 0", nameof(quantiles));
     }
     this.quantiles = new double[quantileCount];
     for (int i = 0; i < quantileCount; i++)
     {
         this.quantiles[i] = canGetQuantile.GetQuantile((i + 1.0) / (quantileCount + 1.0));
     }
     lowerGaussian = GetLowerGaussian(quantiles);
     upperGaussian = GetUpperGaussian(quantiles);
 }
Beispiel #9
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(Gaussian quantile, CanGetQuantile <double> canGetQuantile, [RequiredArgument] Gaussian probability)
 {
     if (quantile.IsPointMass)
     {
         return(ProbabilityAverageConditional(quantile.Point, canGetQuantile));
     }
     else if (probability.IsPointMass)
     {
         return(ProbabilityAverageConditional(quantile, canGetQuantile, probability.Point));
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Beispiel #10
0
        public static OuterQuantiles FromDistribution(int quantileCount, CanGetQuantile canGetQuantile)
        {
            var quantiles = Util.ArrayInit(quantileCount, i => canGetQuantile.GetQuantile(i / (quantileCount - 1.0)));

            return(new OuterQuantiles(quantiles));
        }
Beispiel #11
0
 public static double Quantile(CanGetQuantile <double> canGetQuantile, double probability)
 {
     return(canGetQuantile.GetQuantile(probability));
 }
Beispiel #12
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)));
        }