Numworks Epsilon  1.4.1
Graphing Calculator Operating System
poisson_law.cpp
Go to the documentation of this file.
1 #include "poisson_law.h"
2 #include <assert.h>
3 #include <cmath>
4 #include <ion.h>
5 
6 namespace Probability {
7 
9  OneParameterLaw(4.0f)
10 {
11 }
12 
13 I18n::Message PoissonLaw::title() {
14  return I18n::Message::PoissonLaw;
15 }
16 
18  return Type::Poisson;
19 }
20 
22  return false;
23 }
24 
25 I18n::Message PoissonLaw::parameterNameAtIndex(int index) {
26  assert(index == 0);
27  return I18n::Message::Lambda;
28 }
29 
30 I18n::Message PoissonLaw::parameterDefinitionAtIndex(int index) {
31  assert(index == 0);
32  return I18n::Message::LambdaPoissonDefinition;
33 }
34 
37 }
38 
40  assert(m_parameter1 != 0);
42 }
43 
45  return - k_displayBottomMarginRatio * yMax();
46 }
47 
49  int maxAbscissa = (int)m_parameter1;
50  assert(maxAbscissa >= 0.0f);
51  float result = evaluateAtAbscissa(maxAbscissa);
52  if (result <= 0.0f) {
53  result = 1.0f;
54  }
55  return result*(1.0f+ k_displayTopMarginRatio);
56 }
57 
58 bool PoissonLaw::authorizedValueAtIndex(float x, int index) const {
59  if (x <= 0.0f || x > 999.0f) {
60  return false;
61  }
62  return true;
63 }
64 
65 template<typename T>
66 T PoissonLaw::templatedApproximateAtAbscissa(T x) const {
67  if (x < 0) {
68  return NAN;
69  }
71  return std::exp(lResult);
72 }
73 
74 }
75 
76 template float Probability::PoissonLaw::templatedApproximateAtAbscissa(float x) const;
77 template double Probability::PoissonLaw::templatedApproximateAtAbscissa(double x) const;
bool authorizedValueAtIndex(float x, int index) const override
Definition: poisson_law.cpp:58
float xMax() override
Definition: poisson_law.cpp:39
#define exp(x)
Definition: math.h:176
#define NAN
Definition: math.h:30
#define assert(e)
Definition: assert.h:9
#define lgamma(x)
Definition: math.h:182
#define T(x)
Definition: events.cpp:26
static constexpr float k_displayBottomMarginRatio
Definition: law.h:45
I18n::Message parameterDefinitionAtIndex(int index) override
Definition: poisson_law.cpp:30
float evaluateAtAbscissa(float x) const override
Definition: poisson_law.h:20
#define log(x)
Definition: math.h:184
float yMin() override
Definition: poisson_law.cpp:44
float yMax() override
Definition: poisson_law.cpp:48
static constexpr float k_displayTopMarginRatio
Definition: law.h:44
I18n::Message parameterNameAtIndex(int index) override
Definition: poisson_law.cpp:25
float xMin() override
Definition: poisson_law.cpp:35
static constexpr float k_displayRightMarginRatio
Definition: law.h:47
bool isContinuous() const override
Definition: poisson_law.cpp:21
static constexpr float k_displayLeftMarginRatio
Definition: law.h:46
#define floor(x)
Definition: math.h:179
#define sqrt(x)
Definition: math.h:196
Type type() const override
Definition: poisson_law.cpp:17
I18n::Message title() override
Definition: poisson_law.cpp:13