Files
Upsilon/apps/probability/law/uniform_law.cpp
Émilie Feral c3008ca360 [apps] Improvements of MVC structure regarding curve views and ranges
Change-Id: Iec8031dbf349c34c18694dffabd02ef9c88ebf2d
2017-01-18 14:31:42 +01:00

115 lines
2.4 KiB
C++

#include "uniform_law.h"
#include <assert.h>
namespace Probability {
UniformLaw::UniformLaw() :
TwoParameterLaw(-1.0f, 1.0f)
{
}
const char * UniformLaw::title() {
return "Loi uniforme";
}
Law::Type UniformLaw::type() const {
return Type::Uniform;
}
bool UniformLaw::isContinuous() const {
return true;
}
const char * UniformLaw::parameterNameAtIndex(int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
return "a";
} else {
return "b";
}
}
const char * UniformLaw::parameterDefinitionAtIndex(int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
return "[a, b] intervalle";
} else {
return nullptr;
}
}
float UniformLaw::xMin() {
assert(m_parameter2 >= m_parameter1);
if (m_parameter1 == m_parameter2) {
return m_parameter1 - 1.0f;
}
return m_parameter1 - 0.6f*(m_parameter2 - m_parameter1);
}
float UniformLaw::xMax() {
if (m_parameter1 == m_parameter2) {
return m_parameter1 + 1.0f;
}
return m_parameter2 + 0.6f*(m_parameter2 - m_parameter1);
}
float UniformLaw::yMin() {
return -k_displayBottomMarginRatio*yMax();
}
float UniformLaw::yMax() {
float result = m_parameter1 == m_parameter2 ? k_diracMaximum : 1.0f/(m_parameter2-m_parameter1);
if (result <= 0.0f) {
result = 1.0f;
}
return result*(1.0f+ k_displayTopMarginRatio);
}
float UniformLaw::evaluateAtAbscissa(float t) const {
if (m_parameter1 == m_parameter2) {
if (m_parameter1 - k_diracWidth<= t && t <= m_parameter2 + k_diracWidth) {
return 2.0f*k_diracMaximum;
}
return 0.0f;
}
if (m_parameter1 <= t && t <= m_parameter2) {
return (1.0f/(m_parameter2-m_parameter1));
}
return 0.0f;
}
bool UniformLaw::authorizedValueAtIndex(float x, int index) const {
if (index == 0) {
if (x > m_parameter2) {
return false;
}
return true;
}
if (m_parameter1 > x) {
return false;
}
return true;
}
float UniformLaw::cumulativeDistributiveFunctionAtAbscissa(float x) const {
if (x < m_parameter1) {
return 0.0f;
}
if (x < m_parameter2) {
return (x-m_parameter1)/(m_parameter2-m_parameter1);
}
return 1.0f;
}
float UniformLaw::cumulativeDistributiveInverseForProbability(float * probability) {
if (*probability >= 1.0f) {
return m_parameter2;
}
if (*probability <= 0.0f) {
return m_parameter1;
}
return m_parameter1*(1-*probability)+*probability*m_parameter2;
}
}