[apps/probability] Clean class NormalLaw

This commit is contained in:
Léa Saviot
2018-12-13 13:51:40 +01:00
parent 86409c771a
commit 48bccac8de
2 changed files with 22 additions and 41 deletions

View File

@@ -7,41 +7,6 @@
namespace Probability {
NormalLaw::NormalLaw() :
TwoParameterLaw(0.0f, 1.0f)
{
}
I18n::Message NormalLaw::title() {
return I18n::Message::NormalLaw;
}
Law::Type NormalLaw::type() const {
return Type::Normal;
}
bool NormalLaw::isContinuous() const {
return true;
}
I18n::Message NormalLaw::parameterNameAtIndex(int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
return I18n::Message::Mu;
} else {
return I18n::Message::Sigma;
}
}
I18n::Message NormalLaw::parameterDefinitionAtIndex(int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
return I18n::Message::MeanDefinition;
} else {
return I18n::Message::DeviationDefinition;
}
}
float NormalLaw::xMin() {
if (m_parameter2 == 0.0f) {
return m_parameter1 - 1.0f;
@@ -69,6 +34,22 @@ float NormalLaw::yMax() {
return result*(1.0f+ k_displayTopMarginRatio);
}
I18n::Message NormalLaw::parameterNameAtIndex(int index) {
if (index == 0) {
return I18n::Message::Mu;
}
assert(index == 1);
return I18n::Message::Sigma;
}
I18n::Message NormalLaw::parameterDefinitionAtIndex(int index) {
if (index == 0) {
return I18n::Message::MeanDefinition;
}
assert(index == 1);
return I18n::Message::DeviationDefinition;
}
float NormalLaw::evaluateAtAbscissa(float x) const {
if (m_parameter2 == 0.0f) {
return NAN;

View File

@@ -5,12 +5,12 @@
namespace Probability {
class NormalLaw : public TwoParameterLaw {
class NormalLaw final : public TwoParameterLaw {
public:
NormalLaw();
I18n::Message title() override;
Type type() const override;
bool isContinuous() const override;
NormalLaw() : TwoParameterLaw(0.0f, 1.0f) {}
I18n::Message title() override { return I18n::Message::NormalLaw; }
Type type() const override { return Type::Normal; }
bool isContinuous() const override { return true; }
float xMin() override;
float yMin() override;
float xMax() override;
@@ -24,7 +24,7 @@ public:
double cumulativeDistributiveInverseForProbability(double * probability) override;
private:
constexpr static double k_maxRatioMuSigma = 1000.0f;
/* For the standard norma law, P(X < y) > 0.9999995 with y >= 4.892 so the
/* For the standard normal law, P(X < y) > 0.9999995 with y >= 4.892 so the
* value displayed is 1. But this is dependent on the fact that we display
* only 7 decimal values! */
static_assert(Constant::LargeNumberOfSignificantDigits == 7, "k_maxProbability is ill-defined compared to LargeNumberOfSignificantDigits");