Files
Upsilon/apps/probability/law.cpp
Émilie Feral 3ab38866dd [apps/probability] Create a class for law model
Change-Id: I17f883b12d5a8286d7bf92c83b928a96685f9868
2016-12-08 15:21:52 +01:00

81 lines
1.4 KiB
C++

#include "law.h"
#include <assert.h>
namespace Probability {
Law::Law():
m_type(Law::Type::NoType),
m_parameter1(0.0f),
m_parameter2(0.0f),
m_expression(nullptr),
m_xMin(-10.0f),
m_xMax(10.0f)
{
}
int Law::numberOfParameter() {
switch (m_type) {
case Law::Type::Binomial:
return 2;
case Law::Type::Uniform:
return 2;
case Law::Type::Exponential:
return 1;
case Law::Type::Normal:
return 2;
case Law::Type::Poisson:
return 1;
default:
return 0;
}
}
float Law::parameterAtIndex(int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
return m_parameter1;
}
return m_parameter2;
}
void Law::setParameterAtIndex(float f, int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
m_parameter1 = f;
return;
}
m_parameter2 = f;
}
float Law::evaluateAtAbscissa(float x, Graph::EvaluateContext * context) const {
context->setOverridenValueForSymbolX(x);
return m_expression->approximate(*context);
}
Law::Type Law::type() const {
return m_type;
}
void Law::setType(Type type) {
m_type = type;
}
bool Law::isContinuous() {
switch (m_type) {
case Law::Type::Binomial:
return false;
case Law::Type::Uniform:
return true;
case Law::Type::Exponential:
return true;
case Law::Type::Normal:
return true;
case Law::Type::Poisson:
return false;
default:
return false;
}
}
}