ZeusMath-Library  2.0.4
PoissonDistribution.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch)
3  *****************************************************************************
4  * Project : Zeus Math Library
5  * Module : PoissonDistribution
6  * Package : Zeus.ZeusMath.Stochastic
7  * Author : Benjamin Hadorn
8  * Date : 27.12.2011
9  * System : Zeus-Framework
10  *****************************************************************************
11  * Licence: *
12  * This library is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU Lesser General Public License as *
14  * published by the Free Software Foundation; either version *
15  * 2.1 of the License, or (at your option) any later version. *
16  * *
17  * This library is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU Lesser General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU Lesser General Public *
23  * License along with this library; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
25  *****************************************************************************/
26 
27 /*****************************************************************************
28  * Changes:
29  * 27.12.2011 bha: created zeus 2.0
30  *****************************************************************************/
31 
32 #ifndef PoissonDistributionH
33 #define PoissonDistributionH
34 
37 #include <zeusbase/System/Float.h>
38 
39 BEGIN_NAMESPACE_Zeus
40 
41 /***************************************************************************/
45 /***************************************************************************/
47 {
48  public:
49  /***********************************************************************/
53  /***********************************************************************/
54  inline TPoissonDistribution(const Float& rfLambda)
55  {
56  m_fLambda = rfLambda;
57  }
58 
59  /***********************************************************************/
62  /***********************************************************************/
63  virtual inline ~TPoissonDistribution() {}
64 
65  static Float getProbability(const Float& rfLambda, const Float& rfX);
66 
67  //methods of IDistribution
68  virtual Float MQUALIFIER getEntropy() const;
69  virtual Float MQUALIFIER getExpectedValue() const;
70  virtual Float MQUALIFIER getMean() const;
71  virtual Float MQUALIFIER getMedian() const;
72  virtual Float MQUALIFIER getVariance() const;
73  virtual Float MQUALIFIER getMode() const;
74  virtual Float MQUALIFIER getSkewness() const;
75  virtual Float MQUALIFIER getCumulativeProb(const Float& rfStart, const Float& rfEnd) const;
76  virtual Float MQUALIFIER getStdDeviation() const;
77  virtual Float MQUALIFIER getProb(const Float& rfX) const;
78  virtual Float MQUALIFIER getSampleProb(Int iSample) const;
79 
80  private:
82  Float m_fLambda;
83 
84  static Float getCumulativeProb_internal(const Float& rfLambda, const Float& rfEnd);
85 };
86 
87 //INLINE METHODS
88 /****************************************************************************/
91 /****************************************************************************/
92 inline Float MQUALIFIER TPoissonDistribution::getEntropy() const
93 {
94  return 0.5 * TMath::ln(TConstants::Pi * TMath::exp(1)*m_fLambda) - 1.0/(12*m_fLambda) -
95  1.0/(241*m_fLambda*m_fLambda) - 19.0/(360*m_fLambda*m_fLambda*m_fLambda);
96 }
97 
98 /****************************************************************************/
101 /****************************************************************************/
102 inline Float MQUALIFIER TPoissonDistribution::getExpectedValue() const
103 {
104  return m_fLambda;
105 }
106 
107 /****************************************************************************/
110 /****************************************************************************/
111 inline Float MQUALIFIER TPoissonDistribution::getMean() const
112 {
113  return m_fLambda;
114 }
115 
116 /****************************************************************************/
119 /****************************************************************************/
120 inline Float MQUALIFIER TPoissonDistribution::getMedian() const
121 {
122  //formula taken from wikipedia
123  return TMath::floor(m_fLambda + 1.0/3.0 - 0.02/m_fLambda);
124 }
125 
126 /****************************************************************************/
129 /****************************************************************************/
130 inline Float MQUALIFIER TPoissonDistribution::getVariance() const
131 {
132  return m_fLambda;
133 }
134 
135 /****************************************************************************/
138 /****************************************************************************/
139 inline Float MQUALIFIER TPoissonDistribution::getStdDeviation() const
140 {
141  return TMath::sqrt(m_fLambda);
142 }
143 
144 /****************************************************************************/
147 /****************************************************************************/
148 inline Float MQUALIFIER TPoissonDistribution::getMode() const
149 {
150  Float fRetval = TMath::floor(m_fLambda);
151 
152  //if lambda is an interger
153  if (TFloat::equalsFloat(m_fLambda, fRetval))
154  {
155  fRetval = m_fLambda - 1;
156  }
157  return fRetval;
158 }
159 
160 /****************************************************************************/
163 /****************************************************************************/
164 inline Float MQUALIFIER TPoissonDistribution::getSkewness() const
165 {
166  return TMath::pow(m_fLambda, -0.5);
167 }
168 
169 /****************************************************************************/
172 /****************************************************************************/
173 inline Float MQUALIFIER TPoissonDistribution::getProb(const Float& rfX) const
174 {
175  return TPoissonDistribution::getProbability(m_fLambda, rfX);
176 }
177 
178 /****************************************************************************/
181 /****************************************************************************/
182 inline Float MQUALIFIER TPoissonDistribution::getSampleProb(Int iSample) const
183 {
184  return TPoissonDistribution::getProbability(m_fLambda, iSample);
185 }
186 
187 
188 /****************************************************************************/
194 /****************************************************************************/
195 inline /*static*/ Float TPoissonDistribution::getProbability(const Float& rfLambda, const Float& rfX)
196 {
197  return TMath::pow(rfLambda, rfX) / TFloat::getFactorial(rfX) * TMath::exp(-rfLambda);
198 }
199 
200 
201 END_NAMESPACE_Zeus
202 
203 #endif
Definition: PoissonDistribution.h:46
#define zeusmath_class
Definition: PlatformDefines.hpp:48
TPoissonDistribution(const Float &rfLambda)
Definition: PoissonDistribution.h:54
Definition: IDistribution.hpp:45
virtual ~TPoissonDistribution()
Definition: PoissonDistribution.h:63


Written by Benjamin Hadorn http://www.xatlantis.ch.
Last change made on Wed Sep 14 2016 06:45:54