DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Statistic.h
1 
17 #pragma once
18 
32 #if defined(Statistics_RECURSES)
33 #error Recursive header files inclusion detected in Statistics.h
34 #else // defined(Statistics_RECURSES)
35 
36 #define Statistics_RECURSES
37 
38 #if !defined Statistics_h
39 
40 #define Statistics_h
41 
43 // Inclusions
44 #include <iostream>
45 #include "DGtal/base/Common.h"
46 #include <utility>
47 #include <vector>
49 
50 namespace DGtal
51 {
65  template <typename RealNumberType>
66  class Statistic
67  {
68 
69  // ----------------------- Standard services ------------------------------
70  public:
71 
75  ~Statistic();
76 
80  Statistic(bool storeSample=false);
81 
86  Statistic( const Statistic & other );
87 
93  Statistic & operator=( const Statistic & other );
94 
102  Statistic & operator+=( const Statistic & other );
103 
110  Statistic operator+( const Statistic & other ) const;
111 
112 
113  // ----------------------- Accessors ------------------------------
114  public:
115 
116 
120  unsigned int samples() const;
121 
125  RealNumberType mean() const;
126 
130  RealNumberType variance() const;
131 
135  RealNumberType unbiasedVariance() const;
136 
140  RealNumberType max() const;
141 
145  RealNumberType min() const;
146 
147 
157  RealNumberType median() ;
158 
159 
165  void addValue( RealNumberType v );
166 
181  template <class Iter>
182  void addValues( Iter b, Iter e );
183 
187  void clear();
188 
197  void terminate();
198 
199 
200 
201  // ----------------------- Interface --------------------------------------
202  public:
203 
208  void selfDisplay( std::ostream & that_stream ) const;
209 
214  bool OK() const;
215 
216 
217  // ------------------------- Datas ----------------------------------------
218  private:
219 
220 
221  // ------------------------- Datas ----------------------------------------
222  private:
223 
227  unsigned int mySamples;
228 
232  RealNumberType myExp;
233 
238  RealNumberType myExp2;
239 
243  RealNumberType myMax;
244 
248  RealNumberType myMin;
249 
250 
254  RealNumberType myMedian;
255 
256 
261  std::vector < RealNumberType > myValues;
262 
263 
268 
269 
277 
278  };
279 
286  template <typename RealNumberType>
287  std::ostream&
288  operator<<( std::ostream & thatStream,
289  const Statistic<RealNumberType> & that_object_to_display );
290 
291 
292 } // namespace DGtal
293 
294 
296 // Includes inline functions/methods if necessary.
297 #include "DGtal/base/Statistic.ih"
298 
299 // //
301 
302 #endif // !defined Statistic_h
303 
304 #undef Statistic_RECURSES
305 #endif // else defined(Statistic_RECURSES)