DGtal  1.0.0
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  unsigned int size() const;
145 
149  double mean() const;
150 
154  double variance() const;
155 
159  double unbiasedVariance() const;
160 
164  Quantity max() const;
165 
169  Quantity min() const;
170 
171 
180  Quantity median();
181 
184  Quantity operator[]( unsigned int i ) const;
185 
191  void addValue( Quantity v );
192 
207  template <class Iter>
208  void addValues( Iter b, Iter e );
209 
213  void clear();
214 
223  void terminate();
224 
225 
226 
227  // ----------------------- Interface --------------------------------------
228  public:
229 
234  void selfDisplay( std::ostream & that_stream ) const;
235 
240  bool OK() const;
241 
242 
243  // ------------------------- Datas ----------------------------------------
244  private:
245 
246 
247  // ------------------------- Datas ----------------------------------------
248  private:
249 
253  unsigned int mySamples;
254 
259 
265 
270 
275 
276 
281 
282 
288 
289 
294 
295 
303 
304  };
305 
312  template <typename TQuantity>
313  std::ostream&
314  operator<<( std::ostream & thatStream,
315  const Statistic<TQuantity> & that_object_to_display );
316 
317 
318 } // namespace DGtal
319 
320 
322 // Includes inline functions/methods if necessary.
323 #include "DGtal/math/Statistic.ih"
324 
325 // //
327 
328 #endif // !defined Statistic_h
329 
330 #undef Statistic_RECURSES
331 #endif // else defined(Statistic_RECURSES)
TQuantity Quantity
Definition: Statistic.h:74
Container myValues
Definition: Statistic.h:287
double variance() const
Quantity myExp2
Definition: Statistic.h:264
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)
void addValues(Iter b, Iter e)
unsigned int size() const
ConstIterator end() const
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
void addValue(Quantity v)
Statistic & operator=(const Statistic &other)
Quantity myMedian
Definition: Statistic.h:280
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 >))
Quantity operator[](unsigned int i) const
bool OK() const
unsigned int mySamples
Definition: Statistic.h:253
Statistic(bool storeSample=false)
Quantity max() const
Quantity myMin
Definition: Statistic.h:274
Container::const_iterator ConstIterator
Definition: Statistic.h:77
Quantity myExp
Definition: Statistic.h:258
unsigned int samples() const
Quantity myMax
Definition: Statistic.h:269