ZeusMath-Library  2.0.4
Distribution.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 : Distribution
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 DistributionH
33 #define DistributionH
34 
37 #include <zeusbase/System/ArrayList.hpp>
38 #include <zeusbase/System/Pair.hpp>
39 #include <math.h>
40 
41 
42 BEGIN_NAMESPACE_Zeus
43 
44 typedef TPair<Float, Float> TMappedValue;
45 
46 /***************************************************************************/
51 /***************************************************************************/
53 {
54  public:
55  TDistribution(const TArrayList<Float>& rlstData, bool bDataAsProbabilities);
56  TDistribution(const Float* pafData, Int iArraySize, bool bDataAsProbabilities);
57  TDistribution(const Float* pafSampleData, const Float* pafProb, Int iArraySize);
58  TDistribution(const TArrayList<TMappedValue>& rlstData);
59  TDistribution(const TDistribution& rDist);
60 
61  virtual ~TDistribution();
62 
63  //methods of IDistribution
64  virtual Float MQUALIFIER getEntropy() const;
65  virtual Float MQUALIFIER getExpectedValue() const;
66  virtual Float MQUALIFIER getMean() const;
67  virtual Float MQUALIFIER getMedian() const;
68  virtual Float MQUALIFIER getVariance() const;
69  virtual Float MQUALIFIER getMode() const;
70  virtual Float MQUALIFIER getSkewness() const;
71  virtual Float MQUALIFIER getCumulativeProb(const Float& rfStart, const Float& rfEnd) const;
72  virtual Float MQUALIFIER getStdDeviation() const;
73  virtual Float MQUALIFIER getProb(const Float& rfX) const;
74  virtual Float MQUALIFIER getSampleProb(Int iSample) const;
75 
76  //sample based methods
77  const TMappedValue& getSampleConst(Int iIndex) const;
78  TMappedValue& getSample(Int iIndex);
79  Int getSampleCount() const;
80  Float getSampleValue(Int iIndex) const;
81  Float getProbabilitySum() const;
82  Float getMaximumSampleValue() const;
83  Float getMinimumSampleValue() const;
84 
85  //static methods to operate on arrays
86  static Float getMean(const TArrayList<Float>& rlstData);
87  static Float getMean(const Float* pafData, Int iCount);
88 
89  static Float getMedian(const TArrayList<Float>& rlstData);
90  static Float getMedian(const Float* pafData, Int iCount);
91  static Float getMedian(const Float* pafData, Int iCount, Float fTotalArea);
92 
93  static Float getStdDeviation(const TArrayList<Float>& rlstData);
94  static Float getStdDeviation(const Float* pafData, Int iCount);
95 
96  protected:
97 
98  private:
100  TArrayList<TMappedValue> m_lstData;
101 
102  void create(const Float* pafSampleData, const Float* pafProb, Int iArraySize);
103 };
104 
105 //INLINE METHODS
106 /****************************************************************************/
109 /****************************************************************************/
110 inline Float MQUALIFIER TDistribution::getStdDeviation() const
111 {
112  return TMath::sqrt(getVariance());
113 }
114 
115 /****************************************************************************/
118 /****************************************************************************/
119 inline Float MQUALIFIER TDistribution::getProb(const Float& /*rfX*/) const
120 {
121  return 0.0; //not defined
122 }
123 
124 /****************************************************************************/
127 /****************************************************************************/
128 inline Float MQUALIFIER TDistribution::getSampleProb(Int iSample) const
129 {
130  return getSampleConst(iSample).getSecondConst();
131 }
132 
133 /****************************************************************************/
138 /****************************************************************************/
139 inline const TMappedValue& TDistribution::getSampleConst(Int iIndex) const
140 {
141  return m_lstData.getItemConst(iIndex);
142 }
143 
144 /****************************************************************************/
149 /****************************************************************************/
150 inline TMappedValue& TDistribution::getSample(Int iIndex)
151 {
152  return m_lstData.getItem(iIndex);
153 }
154 
155 /****************************************************************************/
158 /****************************************************************************/
159 inline Int TDistribution::getSampleCount() const
160 {
161  return m_lstData.getCount();
162 }
163 
164 /****************************************************************************/
169 /****************************************************************************/
170 inline Float TDistribution::getSampleValue(Int iIndex) const
171 {
172  return getSampleConst(iIndex).getFirstConst();
173 }
174 
175 /****************************************************************************/
179 /****************************************************************************/
180 inline Float TDistribution::getProbabilitySum() const
181 {
182  return getCumulativeProb(0, m_lstData.getCount()-1);
183 }
184 
185 /****************************************************************************/
188 /****************************************************************************/
189 inline /*static*/ Float TDistribution::getMean(const TArrayList<Float>& rlstData)
190 {
191  return TDistribution::getMean(rlstData.getArrayConst(), rlstData.getCount());
192 }
193 
194 /****************************************************************************/
197 /****************************************************************************/
198 inline /*static*/ Float TDistribution::getMedian(const TArrayList<Float>& rlstData)
199 {
200  return TDistribution::getMedian(rlstData.getArrayConst(), rlstData.getCount());
201 }
202 
203 /****************************************************************************/
206 /****************************************************************************/
207 inline /*static*/ Float TDistribution::getMedian(const Float* pafData, Int iCount)
208 {
209  Float fTotal = 1.0;
210 
211  for (Int i = 0; i < iCount; i++)
212  {
213  fTotal += pafData[i];
214  }
215  return TDistribution::getMedian(pafData, iCount, fTotal);
216 }
217 
218 /****************************************************************************/
221 /****************************************************************************/
222 inline /*static*/ Float TDistribution::getStdDeviation(const TArrayList<Float>& rlstData)
223 {
224  return TDistribution::getStdDeviation(rlstData.getArrayConst(), rlstData.getCount());
225 }
226 
227 
228 END_NAMESPACE_Zeus
229 //---------------------------------------------------------------------------
230 #endif
#define zeusmath_class
Definition: PlatformDefines.hpp:48
TPair< Float, Float > TMappedValue
Definition: Distribution.h:44
Definition: IDistribution.hpp:45
Definition: Distribution.h:52


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