Files
Upsilon/apps/probability/calculation/left_integral_calculation.cpp
Léa Saviot 7ec6bea991 [apps/proba] More seamless computation
If the user computes P(x<a) which gives b, then presses OK on b, return
a.
This prevents some comutation errors such as for student distribution
with 0.05 degrees of freedom, P(x<9900000) then press ok on the result
2019-08-20 10:08:57 +02:00

59 lines
1.4 KiB
C++

#include "left_integral_calculation.h"
#include <assert.h>
#include <ion.h>
#include <cmath>
namespace Probability {
LeftIntegralCalculation::LeftIntegralCalculation() :
Calculation(),
m_upperBound(0.0),
m_result(0.0)
{
compute(0);
}
I18n::Message LeftIntegralCalculation::legendForParameterAtIndex(int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
return I18n::Message::LeftIntegralFirstLegend;
}
return I18n::Message::LeftIntegralSecondLegend;
}
void LeftIntegralCalculation::setParameterAtIndex(double f, int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
m_upperBound = f;
}
if (index == 1) {
m_result = f;
}
compute(index);
}
double LeftIntegralCalculation::parameterAtIndex(int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
return m_upperBound;
}
return m_result;
}
void LeftIntegralCalculation::compute(int indexKnownElement) {
if (m_law == nullptr) {
return;
}
if (indexKnownElement == 0) {
m_result = m_law->cumulativeDistributiveFunctionAtAbscissa(m_upperBound);
} else {
double currentResult = m_law->cumulativeDistributiveFunctionAtAbscissa(m_upperBound);
if (std::fabs(currentResult - m_result) < std::pow(10.0, - Constant::LargeNumberOfSignificantDigits)) {
return;
}
m_upperBound = m_law->cumulativeDistributiveInverseForProbability(&m_result);
}
}
}