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 55 of file CHistogram.h.
#include <mrpt/math/CHistogram.h>
Public Member Functions | |||
CHistogram (const double min, const double max, const size_t nBins) | |||
Constructor
| |||
void | clear () | ||
Clear the histogram: | |||
void | add (const double x) | ||
Add an element to the histogram. | |||
template<typename Derived > | |||
void | add (const Eigen::MatrixBase< Derived > &x) | ||
Add all the elements from a MRPT container to the histogram. | |||
template<typename T > | |||
void | add (const std::vector< T > &x) | ||
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. | |||
Static Public Member Functions | |||
static CHistogram | createWithFixedWidth (double min, double max, double binWidth) | ||
Constructor with a fixed bin width. | |||
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. |
mrpt::math::CHistogram::CHistogram | ( | const double | min, |
const double | max, | ||
const size_t | nBins | ||
) |
Constructor
std::exception | On nBins<=0 or max<=min. |
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::CMonteCarlo< T, NUM, OTHER >::CStatisticalAnalyzer::getDistribution(), and mrpt::math::histogram().
void mrpt::math::CHistogram::add | ( | const Eigen::MatrixBase< Derived > & | x ) | [inline] |
Add all the elements from a MRPT container to the histogram.
If an element is out of [min,max] it is ignored.
Definition at line 87 of file CHistogram.h.
void mrpt::math::CHistogram::add | ( | const std::vector< T > & | x ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 96 of file CHistogram.h.
void mrpt::math::CHistogram::clear | ( | ) |
Clear the histogram:
static CHistogram mrpt::math::CHistogram::createWithFixedWidth | ( | double | min, |
double | max, | ||
double | binWidth | ||
) | [inline, static] |
Constructor with a fixed bin width.
std::exception | On max<=min or width<=0 |
Definition at line 72 of file CHistogram.h.
References ASSERT_.
Referenced by mrpt::math::CMonteCarlo< T, NUM, OTHER >::CStatisticalAnalyzer::getDistribution().
int mrpt::math::CHistogram::getBinCount | ( | const size_t | index ) | const |
Retuns the elements count into the selected bin index, where first one is 0.
std::exception | On invalid index |
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.
std::exception | On invalid index. |
void mrpt::math::CHistogram::getHistogram | ( | vector_double & | x, |
vector_double & | hits | ||
) | const |
Returns the list of bin centers & hit counts.
Referenced by mrpt::math::histogram().
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.
Referenced by mrpt::math::histogram().
std::vector<size_t> mrpt::math::CHistogram::m_bins [private] |
The bins counter.
Definition at line 60 of file CHistogram.h.
double mrpt::math::CHistogram::m_binSizeInv [private] |
((max-min)/nBins)^-1
Definition at line 59 of file CHistogram.h.
size_t mrpt::math::CHistogram::m_count [private] |
The total elements count.
Definition at line 61 of file CHistogram.h.
double mrpt::math::CHistogram::m_max [private] |
The histogram limits.
Definition at line 58 of file CHistogram.h.
double mrpt::math::CHistogram::m_min [private] |
Definition at line 58 of file CHistogram.h.
Page generated by Doxygen 1.7.2 for MRPT 0.9.4 SVN: at Mon Jan 10 22:30:30 UTC 2011 |