[apps] Probability: do not round the calculation results with 3 decimals

This commit is contained in:
Émilie Feral
2017-12-19 13:49:22 +01:00
committed by EmilieNumworks
parent 07054835b4
commit 0d3d7f3587
5 changed files with 9 additions and 27 deletions

View File

@@ -25,10 +25,6 @@ public:
virtual double lowerBound();
virtual double upperBound();
protected:
/* Parameters in probability application are rounded to 3 decimals. This is
* due to the limited precision of some calculation (e. g. standard normal
* cumulative distributive function or inverse). */
constexpr static double k_precision = 0.001;
virtual void compute(int indexKnownElement) = 0;
Law * m_law;
};

View File

@@ -62,8 +62,6 @@ void DiscreteCalculation::compute(int indexKnownElement) {
return;
}
m_result = m_law->evaluateAtDiscreteAbscissa(m_abscissa);
/* Results in probability application are rounder to 3 decimals */
m_result = std::round(m_result/k_precision)*k_precision;
}
}

View File

@@ -43,15 +43,14 @@ I18n::Message FiniteIntegralCalculation::legendForParameterAtIndex(int index) {
void FiniteIntegralCalculation::setParameterAtIndex(double f, int index) {
assert(index >= 0 && index < 3);
double rf = std::round(f/k_precision)*k_precision;
if (index == 0) {
m_lowerBound = rf;
m_lowerBound = f;
}
if (index == 1) {
m_upperBound = rf;
m_upperBound = f;
}
if (index == 2) {
m_result = rf;
m_result = f;
}
compute(index);
}
@@ -83,13 +82,10 @@ void FiniteIntegralCalculation::compute(int indexKnownElement) {
if (indexKnownElement == 2) {
assert(m_law->type() == Law::Type::Normal);
double p = (1.0+m_result)/2.0;
double a = ((NormalLaw *)m_law)->cumulativeDistributiveInverseForProbability(&p);
m_lowerBound = std::round((2.0*m_law->parameterValueAtIndex(0)-a)/k_precision)*k_precision;
m_upperBound = std::round(a/k_precision)*k_precision;
m_upperBound = ((NormalLaw *)m_law)->cumulativeDistributiveInverseForProbability(&p);
m_lowerBound = 2.0*m_law->parameterValueAtIndex(0)-m_upperBound;
}
m_result = m_law->finiteIntegralBetweenAbscissas(m_lowerBound, m_upperBound);
/* Results in probability application are rounder to 3 decimals */
m_result = std::round(m_result/k_precision)*k_precision;
}
}

View File

@@ -31,12 +31,11 @@ I18n::Message LeftIntegralCalculation::legendForParameterAtIndex(int index) {
void LeftIntegralCalculation::setParameterAtIndex(double f, int index) {
assert(index >= 0 && index < 2);
double rf = std::round(f/k_precision)*k_precision;
if (index == 0) {
m_upperBound = rf;
m_upperBound = f;
}
if (index == 1) {
m_result = rf;
m_result = f;
}
compute(index);
}
@@ -59,11 +58,8 @@ void LeftIntegralCalculation::compute(int indexKnownElement) {
}
if (indexKnownElement == 0) {
m_result = m_law->cumulativeDistributiveFunctionAtAbscissa(m_upperBound);
/* Results in probability application are rounder to 3 decimals */
m_result = std::round(m_result/k_precision)*k_precision;
} else {
m_upperBound = m_law->cumulativeDistributiveInverseForProbability(&m_result);
m_upperBound = std::round(m_upperBound/k_precision)*k_precision;
}
}

View File

@@ -31,12 +31,11 @@ I18n::Message RightIntegralCalculation::legendForParameterAtIndex(int index) {
void RightIntegralCalculation::setParameterAtIndex(double f, int index) {
assert(index >= 0 && index < 2);
double rf = std::round(f/k_precision)*k_precision;
if (index == 0) {
m_lowerBound = rf;
m_lowerBound = f;
}
if (index == 1) {
m_result = rf;
m_result = f;
}
compute(index);
}
@@ -59,11 +58,8 @@ void RightIntegralCalculation::compute(int indexKnownElement) {
}
if (indexKnownElement == 0) {
m_result = m_law->rightIntegralFromAbscissa(m_lowerBound);
/* Results in probability application are rounder to 3 decimals */
m_result = std::round(m_result/k_precision)*k_precision;
} else {
m_lowerBound = m_law->rightIntegralInverseForProbability(&m_result);
m_lowerBound = std::round(m_lowerBound/k_precision)*k_precision;
}
}