[poincare/proba] Fix P(X<?) = 0 for binomial distribution

Returns 0 if p = 1, else NAN
This commit is contained in:
Léa Saviot
2019-08-26 16:28:13 +02:00
parent 107976ee9d
commit c47bcb5bd1
2 changed files with 19 additions and 2 deletions

View File

@@ -77,7 +77,12 @@ T BinomialDistribution::CumulativeDistributiveInverseForProbability(T probabilit
if (nIsZero && (pIsZero || pIsOne)) {
return NAN;
}
if (std::abs(probability) < precision) {
if (pIsOne) {
return 0;
}
return NAN;
}
if (std::abs(probability - (T)1.0) < precision) {
return n;
}

View File

@@ -72,7 +72,19 @@ Expression InvBinom::shallowReduce(ExpressionNode::ReductionContext reductionCon
return replaceWithUndefinedInPlace();
}
// TODO LEA if a == 0, check p ?
// If a == 0, check p
if (rationalA.isZero()) {
Expression p = childAtIndex(2);
if (p.type() != ExpressionNode::Type::Rational) {
return *this;
}
if (static_cast<Rational &>(p).isOne()) {
Expression result = Rational::Builder(0);
replaceWithInPlace(result);
return result;
}
return replaceWithUndefinedInPlace();
}
// n if a == 1
if (rationalA.isOne()) {
replaceWithInPlace(n);