mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare/proba] Fix P(X<?) = 0 for binomial distribution
Returns 0 if p = 1, else NAN
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user