Files
Upsilon/apps/probability/normal_law.cpp
Émilie Feral 2a79d8bfd9 [apps/probability] Make law model an abstract class with inheritance for
all specific laws (binomial...)

Change-Id: Ida6d5bfb7a3fbfc288393cd2f7e9e9b934798073
2016-12-15 13:51:40 +01:00

75 lines
1.3 KiB
C++

#include "normal_law.h"
#include <assert.h>
namespace Probability {
NormalLaw::NormalLaw(EvaluateContext * evaluateContext) :
TwoParameterLaw(evaluateContext),
m_expression(Expression::parse("p1-p2*t"))
{
//m_expression = Expression::parse("(1/(p2*sqrt(2*Pi))*exp(-0.5*((t-p1)/p2)^2)");
assert(m_expression != nullptr);
}
NormalLaw::~NormalLaw() {
delete m_expression;
}
const char * NormalLaw::title() {
return "Loi normale";
}
Expression * NormalLaw::expression() const {
return m_expression;
}
Law::Type NormalLaw::type() const {
return Type::Normal;
}
bool NormalLaw::isContinuous() {
return true;
}
const char * NormalLaw::parameterNameAtIndex(int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
return "u";
} else {
return "o";
}
}
const char * NormalLaw::parameterDefinitionAtIndex(int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
return "u : moyenne";
} else {
return "o : ecart-type";
}
}
float NormalLaw::xMin() {
if (m_parameter2 == 0.0f) {
return m_parameter1 - 1.0f;
}
return m_parameter1 - 5.0f*m_parameter2;
}
float NormalLaw::xMax() {
if (m_parameter2 == 0.0f) {
return m_parameter1 + 1.0f;
}
return m_parameter1 + 5.0f*m_parameter2;
}
float NormalLaw::yMin() {
return -0.2f;
}
float NormalLaw::yMax() {
return 1.0f;
}
}