Numworks Epsilon  1.4.1
Graphing Calculator Operating System
uniform_law.cpp
Go to the documentation of this file.
1 #include "uniform_law.h"
2 #include <cmath>
3 #include <float.h>
4 #include <assert.h>
5 
6 namespace Probability {
7 
9  TwoParameterLaw(-1.0f, 1.0f)
10 {
11 }
12 
13 I18n::Message UniformLaw::title() {
14  return I18n::Message::UniformLaw;
15 }
16 
18  return Type::Uniform;
19 }
20 
22  return true;
23 }
24 
25 I18n::Message UniformLaw::parameterNameAtIndex(int index) {
26  assert(index >= 0 && index < 2);
27  if (index == 0) {
28  return I18n::Message::A;
29  } else {
30  return I18n::Message::B;
31  }
32 }
33 
34 I18n::Message UniformLaw::parameterDefinitionAtIndex(int index) {
35  assert(index >= 0 && index < 2);
36  if (index == 0) {
37  return I18n::Message::IntervalDefinition;
38  } else {
39  return I18n::Message::Default;
40  }
41 }
42 
46  return m_parameter1 - 1.0f;
47  }
48  return m_parameter1 - 0.6f*(m_parameter2 - m_parameter1);
49 }
50 
53  return m_parameter1 + 1.0f;
54  }
55  return m_parameter2 + 0.6f*(m_parameter2 - m_parameter1);
56 }
57 
60 }
61 
63  float result = m_parameter2 - m_parameter1 < FLT_EPSILON ? k_diracMaximum : 1.0f/(m_parameter2-m_parameter1);
64  if (result <= 0.0f || std::isnan(result) || std::isinf(result)) {
65  result = 1.0f;
66  }
67  return result*(1.0f+ k_displayTopMarginRatio);
68 }
69 
70 float UniformLaw::evaluateAtAbscissa(float t) const {
72  if (m_parameter1 - k_diracWidth<= t && t <= m_parameter2 + k_diracWidth) {
73  return 2.0f*k_diracMaximum;
74  }
75  return 0.0f;
76  }
77  if (m_parameter1 <= t && t <= m_parameter2) {
78  return (1.0f/(m_parameter2-m_parameter1));
79  }
80  return 0.0f;
81 }
82 
83 bool UniformLaw::authorizedValueAtIndex(float x, int index) const {
84  if (index == 0) {
85  return true;
86  }
87  if (m_parameter1 > x) {
88  return false;
89  }
90  return true;
91 }
92 
93 void UniformLaw::setParameterAtIndex(float f, int index) {
95  if (index == 0 && m_parameter2 < m_parameter1) {
97  }
98 }
99 
101  if (x <= m_parameter1) {
102  return 0.0;
103  }
104  if (x < m_parameter2) {
106  }
107  return 1.0;
108 }
109 
111  if (*probability >= 1.0f) {
112  return m_parameter2;
113  }
114  if (*probability <= 0.0f) {
115  return m_parameter1;
116  }
117  return m_parameter1*(1-*probability)+*probability*m_parameter2;
118 }
119 
120 }
bool authorizedValueAtIndex(float x, int index) const override
Definition: uniform_law.cpp:83
void setParameterAtIndex(float f, int index) override
float yMax() override
Definition: uniform_law.cpp:62
#define FLT_EPSILON
Definition: float.h:8
#define assert(e)
Definition: assert.h:9
bool isContinuous() const override
Definition: uniform_law.cpp:21
#define isinf(x)
Definition: math.h:44
float yMin() override
Definition: uniform_law.cpp:58
double cumulativeDistributiveFunctionAtAbscissa(double x) const override
static constexpr float k_displayBottomMarginRatio
Definition: law.h:45
float xMax() override
Definition: uniform_law.cpp:51
float xMin() override
Definition: uniform_law.cpp:43
I18n::Message parameterNameAtIndex(int index) override
Definition: uniform_law.cpp:25
I18n::Message title() override
Definition: uniform_law.cpp:13
void setParameterAtIndex(float f, int index) override
Definition: uniform_law.cpp:93
static constexpr float k_displayTopMarginRatio
Definition: law.h:44
#define isnan(x)
Definition: math.h:43
float evaluateAtAbscissa(float x) const override
Definition: uniform_law.cpp:70
Type type() const override
Definition: uniform_law.cpp:17
I18n::Message parameterDefinitionAtIndex(int index) override
Definition: uniform_law.cpp:34
double cumulativeDistributiveInverseForProbability(double *probability) override