[poincare/normal_distribution.cpp] Fixed approximation error

Removed limitation in calculation of normal_distribution. It was used to
speed-up computation but yielded 0 for small values.
Previously P(X<5) with X->N(7,0.3162) gave 0 as a result
now it gives 1.26e-10

Change-Id: I3f1c997dfe2ba6424b372a0a82af6d9871443657
This commit is contained in:
Arthur Camouseigt
2020-07-01 16:18:50 +02:00
committed by Émilie Feral
parent de681705e6
commit 6072ffd848
2 changed files with 1 additions and 6 deletions

View File

@@ -16,11 +16,6 @@ public:
* The result of the verification is *result. */
static bool ExpressionMuAndVarAreOK(bool * result, const Expression & mu, const Expression & sigma, Context * context);
private:
/* For the standard normal distribution, P(X < y) > 0.99999995 for y >= 5.33 so the
* value displayed is 1. But this is dependent on the fact that we display
* only 7 decimal values! */
static_assert(Preferences::LargeNumberOfSignificantDigits == 7, "k_boundStandardNormalDistribution is ill-defined compared to LargeNumberOfSignificantDigits");
constexpr static double k_boundStandardNormalDistribution = 5.33;
template<typename T> static T StandardNormalCumulativeDistributiveFunctionAtAbscissa(T abscissa);
template<typename T> static T StandardNormalCumulativeDistributiveInverseForProbability(T probability);
};

View File

@@ -88,7 +88,7 @@ T NormalDistribution::StandardNormalCumulativeDistributiveFunctionAtAbscissa(T a
if (std::isnan(abscissa)) {
return NAN;
}
if (std::isinf(abscissa) || std::fabs(abscissa) > k_boundStandardNormalDistribution) {
if (std::isinf(abscissa)) {
return abscissa > (T)0.0 ? (T)1.0 : (T)0.0;
}
if (abscissa == (T)0.0) {