/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IsGreaterThanOp"]/message_doc[@name="IsGreaterThanAverageConditional(int, Binomial)"]/*'/> public static Bernoulli IsGreaterThanAverageConditional(int a, [Proper] Binomial b) { if (b.IsPointMass) { return(Bernoulli.PointMass(a > b.Point)); } if (b.A == 1 && b.B == 1) { if (a <= 0) { return(Bernoulli.PointMass(false)); } else if (a > b.TrialCount) { return(Bernoulli.PointMass(true)); } else { return(new Bernoulli(MMath.Beta(1 - b.ProbSuccess, b.TrialCount - a + 1, a))); } } else { double sum = 0; for (int i = 0; i < a; i++) { sum += Math.Exp(b.GetLogProb(i)); } if (sum > 1) { sum = 1; // this can happen due to round-off errors } return(new Bernoulli(sum)); } }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IsGreaterThanOp"]/message_doc[@name="IsGreaterThanAverageConditional(Binomial, int)"]/*'/> public static Bernoulli IsGreaterThanAverageConditional([Proper] Binomial a, int b) { if (a.IsPointMass) { return(Bernoulli.PointMass(a.Point > b)); } if (a.A == 1 && a.B == 1) { if (b < 0) { return(Bernoulli.PointMass(true)); } else if (b >= a.TrialCount) { return(Bernoulli.PointMass(false)); } else { return(new Bernoulli(MMath.Beta(a.ProbSuccess, b + 1, a.TrialCount - b))); } } else { double sum = 0; for (int i = 0; i <= b; i++) { sum += Math.Exp(a.GetLogProb(i)); } if (sum > 1) { sum = 1; // this can happen due to round-off errors } return(new Bernoulli(1 - sum)); } }
/// <summary> /// Compute the probability that a sample from this distribution is less than x. /// </summary> /// <param name="x">Any real number.</param> /// <returns>The cumulative beta distribution at <paramref name="x"/></returns> public double GetProbLessThan(double x) { if (x < 0.0) { return(0.0); } else if (x > 1.0) { return(1.0); } else if (this.IsPointMass) { return((this.Point < x) ? 1.0 : 0.0); } else if (this.IsUniform()) { return(x); } else { return(MMath.Beta(x, this.TrueCount, this.FalseCount)); } }