MRPT logo

mrpt::math::CHistogram Class Reference

This class provides an easy way of computing histograms for unidimensional real valued variables. More...

#include <mrpt/math/CHistogram.h>

List of all members.

Public Member Functions

 CHistogram (const double min, const double max, const size_t nBins)
 Constructor
Exceptions:
std::exception On nBins<=0 or max<=min.

void clear ()
 Clear the histogram:.
void add (const double x)
 Add an element to the histogram.
template<typename T >
void add (const std::vector< T > &x)
 Add a vector of elements to the histogram.
int getBinCount (const size_t index) const
 Retuns the elements count into the selected bin index, where first one is 0.
double getBinRatio (const size_t index) const
 Retuns the ratio in [0,1] range for the selected bin index, where first one is 0.
void getHistogram (vector_double &x, vector_double &hits) const
 Returns the list of bin centers & hit counts.
void getHistogramNormalized (vector_double &x, vector_double &hits) const
 Returns the list of bin centers & hit counts, normalized such as the integral of the histogram, interpreted as a density PDF, amounts to 1.

Private Attributes

double m_min
double m_max
 The histogram limits.
double m_binSizeInv
 ((max-min)/nBins)^-1
std::vector< size_t > m_bins
 The bins counter.
size_t m_count
 The total elements count.


Detailed Description

This class provides an easy way of computing histograms for unidimensional real valued variables.

Call "getHistogram" or "getHistogramNormalized" to retrieve the full list of bin positions & hit counts.

Example:

        CHistogram              hist(0,100,10);
        hist.add(86);
        hist.add(7);
        hist.add(45);

        std::cout << hist.getBinCount(0) << std::endl;          // Result: "1"
        std::cout << hist.getBinRatio(0) << std::endl;          // Result: "0.33"

Definition at line 54 of file CHistogram.h.


Constructor & Destructor Documentation

mrpt::math::CHistogram::CHistogram ( const double  min,
const double  max,
const size_t  nBins 
)

Constructor

Exceptions:
std::exception On nBins<=0 or max<=min.


Member Function Documentation

template<typename T >
void mrpt::math::CHistogram::add ( const std::vector< T > &  x  )  [inline]

Add a vector of elements to the histogram.

If an element is out of [min,max] it is ignored.

Definition at line 77 of file CHistogram.h.

void mrpt::math::CHistogram::add ( const double  x  ) 

Add an element to the histogram.

If element is out of [min,max] it is ignored.

Referenced by mrpt::math::histogram().

void mrpt::math::CHistogram::clear (  ) 

Clear the histogram:.

int mrpt::math::CHistogram::getBinCount ( const size_t  index  )  const

Retuns the elements count into the selected bin index, where first one is 0.

Exceptions:
std::exception On invalid index

Referenced by mrpt::math::histogram().

double mrpt::math::CHistogram::getBinRatio ( const size_t  index  )  const

Retuns the ratio in [0,1] range for the selected bin index, where first one is 0.

It returns 0 if no elements have been added.

Exceptions:
std::exception On invalid index.

Referenced by mrpt::math::histogram().

void mrpt::math::CHistogram::getHistogram ( vector_double x,
vector_double hits 
) const

Returns the list of bin centers & hit counts.

See also:
getHistogramNormalized

void mrpt::math::CHistogram::getHistogramNormalized ( vector_double x,
vector_double hits 
) const

Returns the list of bin centers & hit counts, normalized such as the integral of the histogram, interpreted as a density PDF, amounts to 1.

See also:
getHistogram


Member Data Documentation

std::vector<size_t> mrpt::math::CHistogram::m_bins [private]

The bins counter.

Definition at line 59 of file CHistogram.h.

((max-min)/nBins)^-1

Definition at line 58 of file CHistogram.h.

The total elements count.

Definition at line 60 of file CHistogram.h.

The histogram limits.

Definition at line 57 of file CHistogram.h.

Definition at line 57 of file CHistogram.h.




Page generated by Doxygen 1.5.7.1 for MRPT 0.7.1 SVN: at Mon Aug 17 23:10:56 EDT 2009