mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-20 09:17:23 +01:00
[apps/probability] Code cleaning
This commit is contained in:
@@ -18,7 +18,6 @@ app_objs += $(addprefix apps/probability/,\
|
||||
law/exponential_law.o\
|
||||
law/law.o\
|
||||
law/normal_law.o\
|
||||
law/one_parameter_law.o\
|
||||
law/poisson_law.o\
|
||||
law/two_parameter_law.o\
|
||||
law/uniform_law.o\
|
||||
|
||||
@@ -4,11 +4,6 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
Calculation::Calculation():
|
||||
m_law(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void Calculation::setLaw(Law * law) {
|
||||
m_law = law;
|
||||
compute(0);
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
RightIntegral,
|
||||
Discrete,
|
||||
};
|
||||
Calculation();
|
||||
Calculation() : m_law(nullptr) {}
|
||||
virtual ~Calculation() = default;
|
||||
virtual Type type() = 0;
|
||||
void setLaw(Law * law);
|
||||
|
||||
@@ -13,18 +13,6 @@ DiscreteCalculation::DiscreteCalculation() :
|
||||
compute(0);
|
||||
}
|
||||
|
||||
Calculation::Type DiscreteCalculation::type() {
|
||||
return Type::Discrete;
|
||||
}
|
||||
|
||||
int DiscreteCalculation::numberOfParameters() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
int DiscreteCalculation::numberOfEditableParameters() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
I18n::Message DiscreteCalculation::legendForParameterAtIndex(int index) {
|
||||
assert(index >= 0 && index < 2);
|
||||
if (index == 0) {
|
||||
@@ -49,14 +37,6 @@ double DiscreteCalculation::parameterAtIndex(int index) {
|
||||
return m_result;
|
||||
}
|
||||
|
||||
double DiscreteCalculation::lowerBound() {
|
||||
return m_abscissa;
|
||||
}
|
||||
|
||||
double DiscreteCalculation::upperBound() {
|
||||
return m_abscissa;
|
||||
}
|
||||
|
||||
void DiscreteCalculation::compute(int indexKnownElement) {
|
||||
if (m_law == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
class DiscreteCalculation : public Calculation {
|
||||
class DiscreteCalculation final : public Calculation {
|
||||
public:
|
||||
DiscreteCalculation();
|
||||
Type type() override;
|
||||
int numberOfParameters() override;
|
||||
int numberOfEditableParameters() override;
|
||||
Type type() override { return Type::Discrete; }
|
||||
int numberOfParameters() override { return 2; }
|
||||
int numberOfEditableParameters() override { return 1; }
|
||||
I18n::Message legendForParameterAtIndex(int index) override;
|
||||
void setParameterAtIndex(double f, int index) override;
|
||||
double parameterAtIndex(int index) override;
|
||||
double lowerBound() override;
|
||||
double upperBound() override;
|
||||
double lowerBound() override { return m_abscissa; }
|
||||
double upperBound() override { return m_abscissa; }
|
||||
private:
|
||||
void compute(int indexKnownElement) override;
|
||||
double m_abscissa;
|
||||
|
||||
@@ -15,14 +15,6 @@ FiniteIntegralCalculation::FiniteIntegralCalculation() :
|
||||
compute(0);
|
||||
}
|
||||
|
||||
Calculation::Type FiniteIntegralCalculation::type() {
|
||||
return Type::FiniteIntegral;
|
||||
}
|
||||
|
||||
int FiniteIntegralCalculation::numberOfParameters() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
int FiniteIntegralCalculation::numberOfEditableParameters() {
|
||||
if (m_law->type() == Law::Type::Normal) {
|
||||
return 3;
|
||||
@@ -67,14 +59,6 @@ double FiniteIntegralCalculation::parameterAtIndex(int index) {
|
||||
return m_result;
|
||||
}
|
||||
|
||||
double FiniteIntegralCalculation::lowerBound() {
|
||||
return m_lowerBound;
|
||||
}
|
||||
|
||||
double FiniteIntegralCalculation::upperBound() {
|
||||
return m_upperBound;
|
||||
}
|
||||
|
||||
void FiniteIntegralCalculation::compute(int indexKnownElement) {
|
||||
if (m_law == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -8,14 +8,14 @@ namespace Probability {
|
||||
class FiniteIntegralCalculation : public Calculation {
|
||||
public:
|
||||
FiniteIntegralCalculation();
|
||||
Type type() override;
|
||||
int numberOfParameters() override;
|
||||
Type type() override { return Type::FiniteIntegral; }
|
||||
int numberOfParameters() override { return 3; }
|
||||
int numberOfEditableParameters() override;
|
||||
I18n::Message legendForParameterAtIndex(int index) override;
|
||||
void setParameterAtIndex(double f, int index) override;
|
||||
double parameterAtIndex(int index) override;
|
||||
double lowerBound() override;
|
||||
double upperBound() override;
|
||||
double lowerBound() override { return m_lowerBound; }
|
||||
double upperBound() override { return m_upperBound; }
|
||||
private:
|
||||
void compute(int indexKnownElement) override;
|
||||
double m_lowerBound;
|
||||
|
||||
@@ -13,14 +13,6 @@ LeftIntegralCalculation::LeftIntegralCalculation() :
|
||||
compute(0);
|
||||
}
|
||||
|
||||
Calculation::Type LeftIntegralCalculation::type() {
|
||||
return Type::LeftIntegral;
|
||||
}
|
||||
|
||||
int LeftIntegralCalculation::numberOfParameters() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
I18n::Message LeftIntegralCalculation::legendForParameterAtIndex(int index) {
|
||||
assert(index >= 0 && index < 2);
|
||||
if (index == 0) {
|
||||
@@ -48,10 +40,6 @@ double LeftIntegralCalculation::parameterAtIndex(int index) {
|
||||
return m_result;
|
||||
}
|
||||
|
||||
double LeftIntegralCalculation::upperBound() {
|
||||
return m_upperBound;
|
||||
}
|
||||
|
||||
void LeftIntegralCalculation::compute(int indexKnownElement) {
|
||||
if (m_law == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
class LeftIntegralCalculation : public Calculation {
|
||||
class LeftIntegralCalculation final : public Calculation {
|
||||
public:
|
||||
LeftIntegralCalculation();
|
||||
Type type() override;
|
||||
int numberOfParameters() override;
|
||||
Type type() override { return Type::LeftIntegral; }
|
||||
int numberOfParameters() override { return 2; }
|
||||
I18n::Message legendForParameterAtIndex(int index) override;
|
||||
void setParameterAtIndex(double f, int index) override;
|
||||
double parameterAtIndex(int index) override;
|
||||
double upperBound() override;
|
||||
double upperBound() override { return m_upperBound; }
|
||||
private:
|
||||
void compute(int indexKnownElement) override;
|
||||
double m_upperBound;
|
||||
|
||||
@@ -13,14 +13,6 @@ RightIntegralCalculation::RightIntegralCalculation() :
|
||||
compute(0);
|
||||
}
|
||||
|
||||
Calculation::Type RightIntegralCalculation::type() {
|
||||
return Type::RightIntegral;
|
||||
}
|
||||
|
||||
int RightIntegralCalculation::numberOfParameters() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
I18n::Message RightIntegralCalculation::legendForParameterAtIndex(int index) {
|
||||
assert(index >= 0 && index < 2);
|
||||
if (index == 0) {
|
||||
@@ -48,10 +40,6 @@ double RightIntegralCalculation::parameterAtIndex(int index) {
|
||||
return m_result;
|
||||
}
|
||||
|
||||
double RightIntegralCalculation::lowerBound() {
|
||||
return m_lowerBound;
|
||||
}
|
||||
|
||||
void RightIntegralCalculation::compute(int indexKnownElement) {
|
||||
if (m_law == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
class RightIntegralCalculation : public Calculation {
|
||||
class RightIntegralCalculation final : public Calculation {
|
||||
public:
|
||||
RightIntegralCalculation();
|
||||
Type type() override;
|
||||
int numberOfParameters() override;
|
||||
Type type() override { return Type::RightIntegral; }
|
||||
int numberOfParameters() override { return 2; }
|
||||
I18n::Message legendForParameterAtIndex(int index) override;
|
||||
void setParameterAtIndex(double f, int index) override;
|
||||
double parameterAtIndex(int index) override;
|
||||
double lowerBound() override;
|
||||
double lowerBound() override { return m_lowerBound; }
|
||||
private:
|
||||
void compute(int indexKnownElement) override;
|
||||
double m_lowerBound;
|
||||
|
||||
@@ -4,23 +4,6 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
BinomialLaw::BinomialLaw() :
|
||||
TwoParameterLaw(20.0, 0.5)
|
||||
{
|
||||
}
|
||||
|
||||
I18n::Message BinomialLaw::title() {
|
||||
return I18n::Message::BinomialLaw;
|
||||
}
|
||||
|
||||
Law::Type BinomialLaw::type() const {
|
||||
return Type::Binomial;
|
||||
}
|
||||
|
||||
bool BinomialLaw::isContinuous() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
I18n::Message BinomialLaw::parameterNameAtIndex(int index) {
|
||||
assert(index >= 0 && index < 2);
|
||||
if (index == 0) {
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
class BinomialLaw : public TwoParameterLaw {
|
||||
class BinomialLaw final : public TwoParameterLaw {
|
||||
public:
|
||||
BinomialLaw();
|
||||
I18n::Message title() override;
|
||||
Type type() const override;
|
||||
bool isContinuous() const override;
|
||||
BinomialLaw() : TwoParameterLaw(20.0, 0.5) {}
|
||||
I18n::Message title() override { return I18n::Message::BinomialLaw; }
|
||||
Type type() const override { return Type::Binomial; }
|
||||
bool isContinuous() const override { return false; }
|
||||
float xMin() override;
|
||||
float yMin() override;
|
||||
float xMax() override;
|
||||
|
||||
@@ -1,41 +1,15 @@
|
||||
#include "exponential_law.h"
|
||||
#include <assert.h>
|
||||
#include <cmath>
|
||||
#include <float.h>
|
||||
#include <ion.h>
|
||||
|
||||
namespace Probability {
|
||||
|
||||
ExponentialLaw::ExponentialLaw() :
|
||||
OneParameterLaw(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
I18n::Message ExponentialLaw::title() {
|
||||
return I18n::Message::ExponentialLaw;
|
||||
}
|
||||
|
||||
Law::Type ExponentialLaw::type() const {
|
||||
return Type::Exponential;
|
||||
}
|
||||
|
||||
bool ExponentialLaw::isContinuous() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
I18n::Message ExponentialLaw::parameterNameAtIndex(int index) {
|
||||
assert(index == 0);
|
||||
return I18n::Message::Lambda;
|
||||
}
|
||||
|
||||
I18n::Message ExponentialLaw::parameterDefinitionAtIndex(int index) {
|
||||
assert(index == 0);
|
||||
return I18n::Message::LambdaExponentialDefinition;
|
||||
}
|
||||
|
||||
float ExponentialLaw::xMin() {
|
||||
float max = xMax();
|
||||
return - k_displayLeftMarginRatio * max;
|
||||
return - k_displayLeftMarginRatio * xMax();
|
||||
}
|
||||
|
||||
float ExponentialLaw::yMin() {
|
||||
return -k_displayBottomMarginRatio * yMax();
|
||||
}
|
||||
|
||||
float ExponentialLaw::xMax() {
|
||||
@@ -44,11 +18,7 @@ float ExponentialLaw::xMax() {
|
||||
if (result <= 0.0f) {
|
||||
result = 1.0f;
|
||||
}
|
||||
return result*(1.0f+ k_displayRightMarginRatio);
|
||||
}
|
||||
|
||||
float ExponentialLaw::yMin() {
|
||||
return -k_displayBottomMarginRatio*yMax();
|
||||
return result * (1.0f + k_displayRightMarginRatio);
|
||||
}
|
||||
|
||||
float ExponentialLaw::yMax() {
|
||||
@@ -59,14 +29,14 @@ float ExponentialLaw::yMax() {
|
||||
if (result <= 0.0f) {
|
||||
result = 1.0f;
|
||||
}
|
||||
return result*(1.0f+ k_displayTopMarginRatio);
|
||||
return result * (1.0f + k_displayTopMarginRatio);
|
||||
}
|
||||
|
||||
float ExponentialLaw::evaluateAtAbscissa(float x) const {
|
||||
if (x < 0.0f) {
|
||||
return NAN;
|
||||
}
|
||||
return m_parameter1*std::exp(-m_parameter1*x);
|
||||
return m_parameter1 * std::exp(-m_parameter1 * x);
|
||||
}
|
||||
|
||||
bool ExponentialLaw::authorizedValueAtIndex(float x, int index) const {
|
||||
@@ -77,7 +47,7 @@ bool ExponentialLaw::authorizedValueAtIndex(float x, int index) const {
|
||||
}
|
||||
|
||||
double ExponentialLaw::cumulativeDistributiveFunctionAtAbscissa(double x) const {
|
||||
return 1.0 - std::exp((double)(-m_parameter1*x));
|
||||
return 1.0 - std::exp((double)(-m_parameter1 * x));
|
||||
}
|
||||
|
||||
double ExponentialLaw::cumulativeDistributiveInverseForProbability(double * probability) {
|
||||
|
||||
@@ -2,21 +2,28 @@
|
||||
#define PROBABILITE_EXPONENTIAL_LAW_H
|
||||
|
||||
#include "one_parameter_law.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Probability {
|
||||
|
||||
class ExponentialLaw : public OneParameterLaw {
|
||||
class ExponentialLaw final : public OneParameterLaw {
|
||||
public:
|
||||
ExponentialLaw();
|
||||
I18n::Message title() override;
|
||||
Type type() const override;
|
||||
bool isContinuous() const override;
|
||||
ExponentialLaw() : OneParameterLaw(1.0f) {}
|
||||
I18n::Message title() override { return I18n::Message::ExponentialLaw; }
|
||||
Type type() const override { return Type::Exponential; }
|
||||
bool isContinuous() const override { return true; }
|
||||
float xMin() override;
|
||||
float yMin() override;
|
||||
float xMax() override;
|
||||
float yMax() override;
|
||||
I18n::Message parameterNameAtIndex(int index) override;
|
||||
I18n::Message parameterDefinitionAtIndex(int index) override;
|
||||
I18n::Message parameterNameAtIndex(int index) override {
|
||||
assert(index == 0);
|
||||
return I18n::Message::Lambda;
|
||||
}
|
||||
I18n::Message parameterDefinitionAtIndex(int index) override {
|
||||
assert(index == 0);
|
||||
return I18n::Message::LambdaExponentialDefinition;
|
||||
}
|
||||
float evaluateAtAbscissa(float x) const override;
|
||||
bool authorizedValueAtIndex(float x, int index) const override;
|
||||
double cumulativeDistributiveFunctionAtAbscissa(double x) const override;
|
||||
|
||||
@@ -4,11 +4,6 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
Law::Law() :
|
||||
Shared::CurveViewRange()
|
||||
{
|
||||
}
|
||||
|
||||
float Law::xGridUnit() {
|
||||
return computeGridUnit(Axis::X, xMax() - xMin());
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Probability {
|
||||
|
||||
class Law : public Shared::CurveViewRange {
|
||||
public:
|
||||
Law();
|
||||
Law() : Shared::CurveViewRange() {}
|
||||
enum class Type : uint8_t{
|
||||
Binomial,
|
||||
Uniform,
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#include "one_parameter_law.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Probability {
|
||||
|
||||
OneParameterLaw::OneParameterLaw(float parameterValue) :
|
||||
m_parameter1(parameterValue)
|
||||
{
|
||||
}
|
||||
|
||||
int OneParameterLaw::numberOfParameter() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
float OneParameterLaw::parameterValueAtIndex(int index) {
|
||||
assert(index == 0);
|
||||
return m_parameter1;
|
||||
}
|
||||
|
||||
void OneParameterLaw::setParameterAtIndex(float f, int index) {
|
||||
assert(index == 0);
|
||||
m_parameter1 = f;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,15 +2,22 @@
|
||||
#define PROBABILITE_ONE_PARAMETER_LAW_H
|
||||
|
||||
#include "law.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Probability {
|
||||
|
||||
class OneParameterLaw : public Law {
|
||||
public:
|
||||
OneParameterLaw(float parameterValue);
|
||||
int numberOfParameter() override;
|
||||
float parameterValueAtIndex(int index) override;
|
||||
void setParameterAtIndex(float f, int index) override;
|
||||
OneParameterLaw(float parameterValue) : m_parameter1(parameterValue) {}
|
||||
int numberOfParameter() override { return 1; }
|
||||
float parameterValueAtIndex(int index) override {
|
||||
assert(index == 0);
|
||||
return m_parameter1;
|
||||
}
|
||||
void setParameterAtIndex(float f, int index) override {
|
||||
assert(index == 0);
|
||||
m_parameter1 = f;
|
||||
}
|
||||
protected:
|
||||
float m_parameter1;
|
||||
};
|
||||
|
||||
@@ -5,46 +5,19 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
PoissonLaw::PoissonLaw() :
|
||||
OneParameterLaw(4.0f)
|
||||
{
|
||||
}
|
||||
|
||||
I18n::Message PoissonLaw::title() {
|
||||
return I18n::Message::PoissonLaw;
|
||||
}
|
||||
|
||||
Law::Type PoissonLaw::type() const {
|
||||
return Type::Poisson;
|
||||
}
|
||||
|
||||
bool PoissonLaw::isContinuous() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
I18n::Message PoissonLaw::parameterNameAtIndex(int index) {
|
||||
assert(index == 0);
|
||||
return I18n::Message::Lambda;
|
||||
}
|
||||
|
||||
I18n::Message PoissonLaw::parameterDefinitionAtIndex(int index) {
|
||||
assert(index == 0);
|
||||
return I18n::Message::LambdaPoissonDefinition;
|
||||
}
|
||||
|
||||
float PoissonLaw::xMin() {
|
||||
return -k_displayLeftMarginRatio*xMax();
|
||||
}
|
||||
|
||||
float PoissonLaw::xMax() {
|
||||
assert(m_parameter1 != 0);
|
||||
return (m_parameter1 + 5.0f*std::sqrt(m_parameter1))*(1.0f+k_displayRightMarginRatio);
|
||||
return -k_displayLeftMarginRatio * xMax();
|
||||
}
|
||||
|
||||
float PoissonLaw::yMin() {
|
||||
return - k_displayBottomMarginRatio * yMax();
|
||||
}
|
||||
|
||||
float PoissonLaw::xMax() {
|
||||
assert(m_parameter1 != 0);
|
||||
return (m_parameter1 + 5.0f * std::sqrt(m_parameter1)) * (1.0f + k_displayRightMarginRatio);
|
||||
}
|
||||
|
||||
float PoissonLaw::yMax() {
|
||||
int maxAbscissa = (int)m_parameter1;
|
||||
assert(maxAbscissa >= 0.0f);
|
||||
@@ -52,7 +25,7 @@ float PoissonLaw::yMax() {
|
||||
if (result <= 0.0f) {
|
||||
result = 1.0f;
|
||||
}
|
||||
return result*(1.0f+ k_displayTopMarginRatio);
|
||||
return result * (1.0f + k_displayTopMarginRatio);
|
||||
}
|
||||
|
||||
bool PoissonLaw::authorizedValueAtIndex(float x, int index) const {
|
||||
@@ -67,7 +40,7 @@ T PoissonLaw::templatedApproximateAtAbscissa(T x) const {
|
||||
if (x < 0) {
|
||||
return NAN;
|
||||
}
|
||||
T lResult = -(T)m_parameter1+std::floor(x)*std::log((T)m_parameter1)-std::lgamma(std::floor(x)+1);
|
||||
T lResult = -(T)m_parameter1 + std::floor(x) * std::log((T)m_parameter1) - std::lgamma(std::floor(x) + 1);
|
||||
return std::exp(lResult);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,18 +5,24 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
class PoissonLaw : public OneParameterLaw {
|
||||
class PoissonLaw final : public OneParameterLaw {
|
||||
public:
|
||||
PoissonLaw();
|
||||
I18n::Message title() override;
|
||||
Type type() const override;
|
||||
bool isContinuous() const override;
|
||||
PoissonLaw() : OneParameterLaw(4.0f) {}
|
||||
I18n::Message title() override { return I18n::Message::PoissonLaw; }
|
||||
Type type() const override { return Type::Poisson; }
|
||||
bool isContinuous() const override { return false; }
|
||||
float xMin() override;
|
||||
float yMin() override;
|
||||
float xMax() override;
|
||||
float yMax() override;
|
||||
I18n::Message parameterNameAtIndex(int index) override;
|
||||
I18n::Message parameterDefinitionAtIndex(int index) override;
|
||||
I18n::Message parameterNameAtIndex(int index) override {
|
||||
assert(index == 0);
|
||||
return I18n::Message::Lambda;
|
||||
}
|
||||
I18n::Message parameterDefinitionAtIndex(int index) override {
|
||||
assert(index == 0);
|
||||
return I18n::Message::LambdaPoissonDefinition;
|
||||
}
|
||||
float evaluateAtAbscissa(float x) const override {
|
||||
return templatedApproximateAtAbscissa(x);
|
||||
}
|
||||
|
||||
@@ -3,16 +3,6 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
TwoParameterLaw::TwoParameterLaw(float parameterValue1, float parameterValue2) :
|
||||
m_parameter1(parameterValue1),
|
||||
m_parameter2(parameterValue2)
|
||||
{
|
||||
}
|
||||
|
||||
int TwoParameterLaw::numberOfParameter() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
float TwoParameterLaw::parameterValueAtIndex(int index) {
|
||||
assert(index >= 0 && index < 2);
|
||||
if (index == 0) {
|
||||
|
||||
@@ -7,8 +7,11 @@ namespace Probability {
|
||||
|
||||
class TwoParameterLaw : public Law {
|
||||
public:
|
||||
TwoParameterLaw(float parameterValue1, float parameterValue2);
|
||||
int numberOfParameter() override;
|
||||
TwoParameterLaw(float parameterValue1, float parameterValue2) :
|
||||
m_parameter1(parameterValue1),
|
||||
m_parameter2(parameterValue2)
|
||||
{}
|
||||
int numberOfParameter() override { return 2; }
|
||||
float parameterValueAtIndex(int index) override;
|
||||
void setParameterAtIndex(float f, int index) override;
|
||||
protected:
|
||||
|
||||
@@ -5,22 +5,6 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
UniformLaw::UniformLaw() :
|
||||
TwoParameterLaw(-1.0f, 1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
I18n::Message UniformLaw::title() {
|
||||
return I18n::Message::UniformLaw;
|
||||
}
|
||||
|
||||
Law::Type UniformLaw::type() const {
|
||||
return Type::Uniform;
|
||||
}
|
||||
|
||||
bool UniformLaw::isContinuous() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
I18n::Message UniformLaw::parameterNameAtIndex(int index) {
|
||||
assert(index >= 0 && index < 2);
|
||||
@@ -45,18 +29,18 @@ float UniformLaw::xMin() {
|
||||
if (m_parameter2 - m_parameter1 < FLT_EPSILON) {
|
||||
return m_parameter1 - 1.0f;
|
||||
}
|
||||
return m_parameter1 - 0.6f*(m_parameter2 - m_parameter1);
|
||||
return m_parameter1 - 0.6f * (m_parameter2 - m_parameter1);
|
||||
}
|
||||
|
||||
float UniformLaw::yMin() {
|
||||
return -k_displayBottomMarginRatio * yMax();
|
||||
}
|
||||
|
||||
float UniformLaw::xMax() {
|
||||
if (m_parameter2 - m_parameter1 < FLT_EPSILON) {
|
||||
return m_parameter1 + 1.0f;
|
||||
}
|
||||
return m_parameter2 + 0.6f*(m_parameter2 - m_parameter1);
|
||||
}
|
||||
|
||||
float UniformLaw::yMin() {
|
||||
return -k_displayBottomMarginRatio*yMax();
|
||||
return m_parameter2 + 0.6f * (m_parameter2 - m_parameter1);
|
||||
}
|
||||
|
||||
float UniformLaw::yMax() {
|
||||
@@ -64,18 +48,18 @@ float UniformLaw::yMax() {
|
||||
if (result <= 0.0f || std::isnan(result) || std::isinf(result)) {
|
||||
result = 1.0f;
|
||||
}
|
||||
return result*(1.0f+ k_displayTopMarginRatio);
|
||||
return result * (1.0f+ k_displayTopMarginRatio);
|
||||
}
|
||||
|
||||
float UniformLaw::evaluateAtAbscissa(float t) const {
|
||||
if (m_parameter2 - m_parameter1 < FLT_EPSILON) {
|
||||
if (m_parameter1 - k_diracWidth<= t && t <= m_parameter2 + k_diracWidth) {
|
||||
return 2.0f*k_diracMaximum;
|
||||
return 2.0f * k_diracMaximum;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
if (m_parameter1 <= t && t <= m_parameter2) {
|
||||
return (1.0f/(m_parameter2-m_parameter1));
|
||||
return (1.0f/(m_parameter2 - m_parameter1));
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
@@ -93,7 +77,7 @@ bool UniformLaw::authorizedValueAtIndex(float x, int index) const {
|
||||
void UniformLaw::setParameterAtIndex(float f, int index) {
|
||||
TwoParameterLaw::setParameterAtIndex(f, index);
|
||||
if (index == 0 && m_parameter2 < m_parameter1) {
|
||||
m_parameter2 = m_parameter1+1.0f;
|
||||
m_parameter2 = m_parameter1 + 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +86,7 @@ double UniformLaw::cumulativeDistributiveFunctionAtAbscissa(double x) const {
|
||||
return 0.0;
|
||||
}
|
||||
if (x < m_parameter2) {
|
||||
return (x-m_parameter1)/(m_parameter2-m_parameter1);
|
||||
return (x - m_parameter1)/(m_parameter2 - m_parameter1);
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
@@ -114,7 +98,7 @@ double UniformLaw::cumulativeDistributiveInverseForProbability(double * probabil
|
||||
if (*probability <= 0.0f) {
|
||||
return m_parameter1;
|
||||
}
|
||||
return m_parameter1*(1-*probability)+*probability*m_parameter2;
|
||||
return m_parameter1 * (1 - *probability) + *probability * m_parameter2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
namespace Probability {
|
||||
|
||||
class UniformLaw : public TwoParameterLaw {
|
||||
class UniformLaw final : public TwoParameterLaw {
|
||||
public:
|
||||
UniformLaw();
|
||||
I18n::Message title() override;
|
||||
Type type() const override;
|
||||
bool isContinuous() const override;
|
||||
UniformLaw() : TwoParameterLaw(-1.0f, 1.0f) {}
|
||||
I18n::Message title() override { return I18n::Message::UniformLaw; }
|
||||
Type type() const override { return Type::Uniform; }
|
||||
bool isContinuous() const override { return true; }
|
||||
float xMin() override;
|
||||
float yMin() override;
|
||||
float xMax() override;
|
||||
|
||||
Reference in New Issue
Block a user