6663b6c9
adorian
projet complet av...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#include "uniform_law.h"
#include <cmath>
#include <float.h>
#include <assert.h>
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);
if (index == 0) {
return I18n::Message::A;
} else {
return I18n::Message::B;
}
}
I18n::Message UniformLaw::parameterDefinitionAtIndex(int index) {
assert(index >= 0 && index < 2);
if (index == 0) {
return I18n::Message::IntervalDefinition;
} else {
return I18n::Message::Default;
}
}
float UniformLaw::xMin() {
assert(m_parameter2 >= m_parameter1);
if (m_parameter2 - m_parameter1 < FLT_EPSILON) {
return m_parameter1 - 1.0f;
}
return m_parameter1 - 0.6f*(m_parameter2 - m_parameter1);
}
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();
}
float UniformLaw::yMax() {
float result = m_parameter2 - m_parameter1 < FLT_EPSILON ? k_diracMaximum : 1.0f/(m_parameter2-m_parameter1);
if (result <= 0.0f || std::isnan(result) || std::isinf(result)) {
result = 1.0f;
}
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 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) {
return true;
}
if (m_parameter1 > x) {
return false;
}
return true;
}
void UniformLaw::setParameterAtIndex(float f, int index) {
TwoParameterLaw::setParameterAtIndex(f, index);
if (index == 0 && m_parameter2 < m_parameter1) {
m_parameter2 = m_parameter1+1.0f;
}
}
double UniformLaw::cumulativeDistributiveFunctionAtAbscissa(double x) const {
if (x <= m_parameter1) {
return 0.0;
}
if (x < m_parameter2) {
return (x-m_parameter1)/(m_parameter2-m_parameter1);
}
return 1.0;
}
double UniformLaw::cumulativeDistributiveInverseForProbability(double * probability) {
if (*probability >= 1.0f) {
return m_parameter2;
}
if (*probability <= 0.0f) {
return m_parameter1;
}
return m_parameter1*(1-*probability)+*probability*m_parameter2;
}
}
|