DGtal  0.9.4.1
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 "DGtal/kernel/CCommutativeRing.h"
47 #include "DGtal/kernel/NumberTraits.h"
48 #include <utility>
49 #include <vector>
51
52 namespace DGtal
53 {
68  template <typename TQuantity>
69  class Statistic
70  {
71
72  // ----------------------- public types -----------------------------------
73  public:
74  typedef TQuantity Quantity;
76  typedef std::vector< Quantity > Container;
77  typedef typename Container::const_iterator ConstIterator;
78
79  // ----------------------- Standard services ------------------------------
80  public:
81
85  ~Statistic();
86
90  Statistic(bool storeSample=false);
91
96  Statistic( const Statistic & other );
97
103  Statistic & operator=( const Statistic & other );
104
112  Statistic & operator+=( const Statistic & other );
113
120  Statistic operator+( const Statistic & other ) const;
121
125  ConstIterator begin() const;
126
130  ConstIterator end() const;
131
132  // ----------------------- Accessors ------------------------------
133  public:
134
135
139  unsigned int samples() const;
140
144  double mean() const;
145
149  double variance() const;
150
154  double unbiasedVariance() const;
155
159  Quantity max() const;
160
164  Quantity min() const;
165
166
176  Quantity median() ;
177
178
184  void addValue( Quantity v );
185
200  template <class Iter>
201  void addValues( Iter b, Iter e );
202
206  void clear();
207
216  void terminate();
217
218
219
220  // ----------------------- Interface --------------------------------------
221  public:
222
227  void selfDisplay( std::ostream & that_stream ) const;
228
233  bool OK() const;
234
235
236  // ------------------------- Datas ----------------------------------------
237  private:
238
239
240  // ------------------------- Datas ----------------------------------------
241  private:
242
246  unsigned int mySamples;
247
252
258
263
268
269
274
275
281
282
287
288
296
297  };
298
305  template <typename TQuantity>
306  std::ostream&
307  operator<<( std::ostream & thatStream,
308  const Statistic<TQuantity> & that_object_to_display );
309
310
311 } // namespace DGtal
312
313
315 // Includes inline functions/methods if necessary.
316 #include "DGtal/math/Statistic.ih"
317
318 // //
320
321 #endif // !defined Statistic_h
322
323 #undef Statistic_RECURSES
324 #endif // else defined(Statistic_RECURSES)
TQuantity Quantity
Definition: Statistic.h:74
Container myValues
Definition: Statistic.h:280
double variance() const
Quantity myExp2
Definition: Statistic.h:257
std::vector< Quantity > Container
Definition: Statistic.h:76
double mean() const
void selfDisplay(std::ostream &that_stream) const
Aim: Defines the mathematical concept equivalent to a unitary commutative ring.
Aim: This class processes a set of sample values for one variable and can then compute different stat...
Definition: Statistic.h:69
Quantity median()
ConstIterator begin() const
Statistic operator+(const Statistic &other) const
Statistic & operator+=(const Statistic &other)
ConstIterator end() const
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
Statistic & operator=(const Statistic &other)
Quantity myMedian
Definition: Statistic.h:273
DGtal is the top-level namespace which contains all DGtal functions and types.
double unbiasedVariance() const
Quantity min() const
BOOST_CONCEPT_ASSERT((concepts::CCommutativeRing< Quantity >))
bool OK() const
unsigned int mySamples
Definition: Statistic.h:246
Statistic(bool storeSample=false)
Quantity max() const
Quantity myMin
Definition: Statistic.h:267
Container::const_iterator ConstIterator
Definition: Statistic.h:77
Quantity myExp
Definition: Statistic.h:251
unsigned int samples() const
Quantity myMax
Definition: Statistic.h:262