[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:
Léa Saviot
2019-08-21 14:47:17 +02:00
parent 83fda9a587
commit c248363b34
4 changed files with 13 additions and 4 deletions

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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();
}

View File

@@ -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);
}
}