DGtal 1.3.0
Loading...
Searching...
No Matches
Histogram.h
1
17#pragma once
18
31#if defined(Histogram_RECURSES)
32#error Recursive header files inclusion detected in Histogram.h
33#else // defined(Histogram_RECURSES)
35#define Histogram_RECURSES
36
37#if !defined Histogram_h
39#define Histogram_h
40
42// Inclusions
43#include <iostream>
44#include "DGtal/base/Common.h"
45#include "DGtal/base/Clone.h"
46#include "DGtal/math/CBinner.h"
47#include "DGtal/kernel/CEuclideanRing.h"
48#include "DGtal/math/Statistic.h"
50
51namespace DGtal
52{
63 template <typename TQuantity>
65 typedef TQuantity Quantity;
68
84 RegularBinner( const Quantity & min, const Quantity & max, Bin n )
85 : myMin( min ), myMax( max ), myNb( n )
86 {
87 ASSERT( max > min );
88 ASSERT( n > 0 );
89 myWidth = ( max - min ) / static_cast<Quantity>( n );
90 }
91
95 inline Bin size() const
96 {
97 return myNb;
98 }
99
105 inline Bin operator()( const Quantity & q ) const
106 {
107 if ( q <= myMin ) return NumberTraits<Bin>::ZERO;
108 else if ( q >= myMax ) return myNb - NumberTraits<Bin>::ONE;
109 else return static_cast<Bin>( floor( NumberTraits<Quantity>::castToDouble( ( q - myMin ) / myWidth ) ) );
110 }
111 };
112
114 // template class Histogram
143 template < typename TQuantity,
144 typename TBinner = RegularBinner< TQuantity > >
146 {
147 public:
150 BOOST_STATIC_ASSERT(( boost::is_same< TQuantity, typename TBinner::Quantity >::value ));
151
152 // ----------------------- public types ------------------------------
153 public:
154 typedef TQuantity Quantity;
155 typedef TBinner Binner;
157 typedef typename Binner::Bin Bin;
159 typedef std::vector<Size> Container;
160 typedef Container::const_iterator ConstIterator;
161
170 // ----------------------- Standard services ------------------------------
171 public:
172
177
182
186 void clear();
187
191 void init( Clone<Binner> binner );
192
197 void init( Formula formula, const Statistic<Quantity> & stat );
198
203 void init( Bin nbBins, const Statistic<Quantity> & stat );
204
210
217 template <typename TInputIterator>
218 void addValues( TInputIterator it, TInputIterator itE );
219
223 void terminate();
224
229 Bin bin( Quantity q ) const;
230
234 Bin size() const;
235
240 Size area() const;
241
246 Size nb( Bin b ) const;
247
254
259 double pdf( Bin b ) const;
260
265 double cdf( Bin b ) const;
266
267 // ----------------------- Interface --------------------------------------
268 public:
269
274 void selfDisplay ( std::ostream & out ) const;
275
280 bool isValid() const;
281
282 // ------------------------- Protected Datas ------------------------------
283 protected:
290
291 // ------------------------- Private Datas --------------------------------
292 private:
293
294 // ------------------------- Hidden services ------------------------------
295 private:
296
302 Histogram ( const Histogram & other );
303
310 Histogram & operator= ( const Histogram & other );
311
312 // ------------------------- Internals ------------------------------------
313 private:
317 void prepare( Bin size );
318
319
320 }; // end of class Histogram
321
322
329 template <typename TQuantity, typename TBinner>
330 std::ostream&
331 operator<< ( std::ostream & out, const Histogram<TQuantity, TBinner> & object );
332
333} // namespace DGtal
334
335
337// Includes inline functions.
338#include "DGtal/math/Histogram.ih"
339
340// //
342
343#endif // !defined Histogram_h
344
345#undef Histogram_RECURSES
346#endif // else defined(Histogram_RECURSES)
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition: Clone.h:267
Aim: Represents a typical histogram in statistics, which is a discrete estimate of the probability di...
Definition: Histogram.h:146
Container::const_iterator ConstIterator
Definition: Histogram.h:160
DGtal::uint64_t Size
Definition: Histogram.h:158
Size accumulation(Bin b) const
void addValues(TInputIterator it, TInputIterator itE)
void init(Bin nbBins, const Statistic< Quantity > &stat)
double pdf(Bin b) const
Binner::Bin Bin
Definition: Histogram.h:157
void selfDisplay(std::ostream &out) const
Histogram & operator=(const Histogram &other)
void prepare(Bin size)
std::vector< Size > Container
Definition: Histogram.h:159
bool isValid() const
void init(Formula formula, const Statistic< Quantity > &stat)
BOOST_CONCEPT_ASSERT((concepts::CEuclideanRing< TQuantity >))
Size nb(Bin b) const
void addValue(Quantity q)
TQuantity Quantity
Definition: Histogram.h:154
Bin size() const
const Binner * myBinner
The binner that places quantities into a bin.
Definition: Histogram.h:285
TBinner Binner
Definition: Histogram.h:155
Container myCumulativeHistogram
The cumulative histogram data.
Definition: Histogram.h:289
BOOST_STATIC_ASSERT((boost::is_same< TQuantity, typename TBinner::Quantity >::value))
double cdf(Bin b) const
Histogram(const Histogram &other)
void init(Clone< Binner > binner)
Container myHistogram
The histogram data.
Definition: Histogram.h:287
Bin bin(Quantity q) const
Size area() const
BOOST_CONCEPT_ASSERT((concepts::CBinner< TBinner >))
Histogram< Quantity, Binner > Self
Definition: Histogram.h:156
Aim: This class processes a set of sample values for one variable and can then compute different stat...
Definition: Statistic.h:70
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::uint32_t uint32_t
unsigned 32-bit integer.
Definition: BasicTypes.h:63
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
boost::uint64_t uint64_t
unsigned 64-bit integer.
Definition: BasicTypes.h:65
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:564
Aim: Represents an elementary functor that partitions quantities into regular intervals,...
Definition: Histogram.h:64
TQuantity Quantity
Definition: Histogram.h:65
RegularBinner(const Quantity &min, const Quantity &max, Bin n)
Definition: Histogram.h:84
RegularBinner< Quantity > Self
Definition: Histogram.h:66
Bin operator()(const Quantity &q) const
Definition: Histogram.h:105
DGtal::uint32_t Bin
Definition: Histogram.h:67
Bin size() const
Definition: Histogram.h:95
Aim: Represents an object that places a quantity into a bin, i.e. a functor that associates a natural...
Definition: CBinner.h:98
Aim: Defines the mathematical concept equivalent to a unitary commutative ring with a division operat...
int max(int a, int b)