mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/proba] Better handling of NAN values
For instance, chi squared law woth 1E8 degrees of freedom, comppute P(X<?) = 0.4 will give P(X<undef) = undef
This commit is contained in:
@@ -52,6 +52,9 @@ void LeftIntegralCalculation::compute(int indexKnownElement) {
|
||||
return;
|
||||
}
|
||||
m_upperBound = m_distribution->cumulativeDistributiveInverseForProbability(&m_result);
|
||||
if (std::isnan(m_upperBound)) {
|
||||
m_result = NAN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,9 @@ void RightIntegralCalculation::compute(int indexKnownElement) {
|
||||
return;
|
||||
}
|
||||
m_lowerBound = m_distribution->rightIntegralInverseForProbability(&m_result);
|
||||
if (std::isnan(m_lowerBound)) {
|
||||
m_result = NAN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ double Distribution::cumulativeDistributiveInverseForProbabilityUsingIncreasingF
|
||||
this,
|
||||
probability,
|
||||
nullptr);
|
||||
assert(std::fabs(result.value()) < FLT_EPSILON*100); // TODO FLT_EPSILON is too strict
|
||||
assert(std::isnan(result.value()) || std::fabs(result.value()) < FLT_EPSILON*100); // TODO FLT_EPSILON is too strict
|
||||
return result.abscissa();
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ Coordinate2D Solver::IncreasingFunctionRoot(double ax, double bx, double precisi
|
||||
return Coordinate2D(currentAbscissa, eval);
|
||||
}
|
||||
// The minimal value is already bigger than 0, return NAN.
|
||||
return Coordinate2D(currentAbscissa, NAN);
|
||||
return Coordinate2D(NAN, NAN);
|
||||
}
|
||||
while (max - min > precision) {
|
||||
currentAbscissa = (min + max) / 2.0;
|
||||
@@ -196,10 +196,13 @@ Coordinate2D Solver::IncreasingFunctionRoot(double ax, double bx, double precisi
|
||||
} else if (eval < -DBL_EPSILON) {
|
||||
min = currentAbscissa;
|
||||
} else {
|
||||
return Coordinate2D(currentAbscissa, eval);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Coordinate2D(currentAbscissa, std::fabs(eval) < precision ? eval : NAN);
|
||||
if (std::fabs(eval) < precision) {
|
||||
return Coordinate2D(currentAbscissa, eval);
|
||||
}
|
||||
return Coordinate2D(NAN, NAN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user