Blame view

build6/epsilon-master/apps/probability/law/exponential_law.cpp 1.93 KB
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
  #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;
  }
  
  float ExponentialLaw::xMax() {
    assert(m_parameter1 != 0.0f);
    float result = 5.0f/m_parameter1;
    if (result <= 0.0f) {
      result = 1.0f;
    }
    return result*(1.0f+ k_displayRightMarginRatio);
  }
  
  float ExponentialLaw::yMin() {
    return -k_displayBottomMarginRatio*yMax();
  }
  
  float ExponentialLaw::yMax() {
    float result = m_parameter1;
    if (result <= 0.0f || std::isnan(result)) {
      result = 1.0f;
    }
    if (result <= 0.0f) {
      result = 1.0f;
    }
    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);
  }
  
  bool ExponentialLaw::authorizedValueAtIndex(float x, int index) const {
    if (x <= 0.0f || x > 7500.0f) {
      return false;
    }
    return true;
  }
  
  double ExponentialLaw::cumulativeDistributiveFunctionAtAbscissa(double x) const {
    return 1.0 - std::exp((double)(-m_parameter1*x));
  }
  
  double ExponentialLaw::cumulativeDistributiveInverseForProbability(double * probability) {
    if (*probability >= 1.0) {
      return INFINITY;
    }
    if (*probability <= 0.0) {
      return 0.0;
    }
    return -std::log(1.0 - *probability)/(double)m_parameter1;
  }
  
  }