DGtal  1.1.0
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)
34
35 #define Histogram_RECURSES
36
37 #if !defined Histogram_h
38
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
51 namespace DGtal
52 {
63  template <typename TQuantity>
64  struct RegularBinner {
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 > >
145  class Histogram
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
169  Scott };
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
209  void addValue( Quantity q );
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
253  Size accumulation( Bin b ) const;
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:
285  const Binner* myBinner;
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)
DGtal::Histogram::BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT((boost::is_same< TQuantity, typename TBinner::Quantity >::value))
DGtal::Clone
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition: Clone.h:267
DGtal::Histogram::size
Bin size() const
DGtal::Histogram::Container
std::vector< Size > Container
Definition: Histogram.h:159
DGtal::RegularBinner::Self
RegularBinner< Quantity > Self
Definition: Histogram.h:66
DGtal::RegularBinner::myMin
Quantity myMin
Definition: Histogram.h:69
DGtal::Histogram::ConstIterator
Container::const_iterator ConstIterator
Definition: Histogram.h:160
DGtal::Histogram::myBinner
const Binner * myBinner
The binner that places quantities into a bin.
Definition: Histogram.h:285
DGtal::uint32_t
boost::uint32_t uint32_t
unsigned 32-bit integer.
Definition: BasicTypes.h:63
DGtal::Histogram::prepare
void prepare(Bin size)
max
int max(int a, int b)
Definition: testArithmeticalDSS.cpp:1108
DGtal::Histogram::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::Histogram::~Histogram
~Histogram()
DGtal::RegularBinner::myMax
Quantity myMax
Definition: Histogram.h:70
DGtal::NumberTraits
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:533
DGtal::Histogram::cdf
double cdf(Bin b) const
DGtal::Histogram::nb
Size nb(Bin b) const
DGtal::Histogram::terminate
void terminate()
DGtal::Histogram::Size
DGtal::uint64_t Size
Definition: Histogram.h:158
DGtal::Histogram::Scott
@ Scott
Definition: Histogram.h:169
DGtal::Histogram::Histogram
Histogram(const Histogram &other)
DGtal::Histogram::Bin
Binner::Bin Bin
Definition: Histogram.h:157
DGtal::Histogram
Aim: Represents a typical histogram in statistics, which is a discrete estimate of the probability di...
Definition: Histogram.h:146
DGtal::Histogram::Binner
TBinner Binner
Definition: Histogram.h:155
DGtal::Statistic
Aim: This class processes a set of sample values for one variable and can then compute different stat...
Definition: Statistic.h:70
DGtal::Histogram::Quantity
TQuantity Quantity
Definition: Histogram.h:154
DGtal::Histogram::Histogram
Histogram()
DGtal::Histogram::init
void init(Bin nbBins, const Statistic< Quantity > &stat)
DGtal::RegularBinner::size
Bin size() const
Definition: Histogram.h:95
DGtal::Histogram::Self
Histogram< Quantity, Binner > Self
Definition: Histogram.h:156
DGtal::Histogram::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CEuclideanRing< TQuantity >))
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::Histogram::init
void init(Formula formula, const Statistic< Quantity > &stat)
DGtal::Histogram::operator=
Histogram & operator=(const Histogram &other)
DGtal::RegularBinner
Aim: Represents an elementary functor that partitions quantities into regular intervals,...
Definition: Histogram.h:64
DGtal::RegularBinner::RegularBinner
RegularBinner(const Quantity &min, const Quantity &max, Bin n)
Definition: Histogram.h:84
DGtal::Histogram::accumulation
Size accumulation(Bin b) const
DGtal::RegularBinner::operator()
Bin operator()(const Quantity &q) const
Definition: Histogram.h:105
DGtal::concepts::CEuclideanRing
Aim: Defines the mathematical concept equivalent to a unitary commutative ring with a division operat...
Definition: CEuclideanRing.h:88
DGtal::uint64_t
boost::uint64_t uint64_t
unsigned 64-bit integer.
Definition: BasicTypes.h:65
DGtal::RegularBinner::Bin
DGtal::uint32_t Bin
Definition: Histogram.h:67
DGtal::Histogram::init
void init(Clone< Binner > binner)
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::Histogram::Rice
@ Rice
Definition: Histogram.h:168
DGtal::Histogram::isValid
bool isValid() const
DGtal::Histogram::clear
void clear()
DGtal::concepts::CBinner
Aim: Represents an object that places a quantity into a bin, i.e. a functor that associates a natural...
Definition: CBinner.h:98
DGtal::Histogram::area
Size area() const
DGtal::Histogram::pdf
double pdf(Bin b) const
DGtal::Histogram::Formula
Formula
Definition: Histogram.h:166
DGtal::RegularBinner::myWidth
Quantity myWidth
Definition: Histogram.h:72
DGtal::RegularBinner::myNb
Bin myNb
Definition: Histogram.h:71
DGtal::Histogram::bin
Bin bin(Quantity q) const
DGtal::Histogram::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CBinner< TBinner >))
DGtal::RegularBinner::Quantity
TQuantity Quantity
Definition: Histogram.h:65
DGtal::Histogram::myCumulativeHistogram
Container myCumulativeHistogram
The cumulative histogram data.
Definition: Histogram.h:289
DGtal::Histogram::Sturges
@ Sturges
Definition: Histogram.h:167
DGtal::Histogram::myHistogram
Container myHistogram
The histogram data.
Definition: Histogram.h:287
DGtal::Histogram::SquareRoot
@ SquareRoot
Definition: Histogram.h:166