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:
Definition at line 37 of file CHistogram.h.
#include <mrpt/math/CHistogram.h>
Public Member Functions | |
CHistogram (const double min, const double max, const size_t nBins) | |
Constructor. More... | |
void | clear () |
Clear the histogram: More... | |
void | add (const double x) |
Add an element to the histogram. More... | |
template<typename Derived > | |
void | add (const Eigen::MatrixBase< Derived > &x) |
Add all the elements from a MRPT container to the histogram. More... | |
template<typename T > | |
void | add (const std::vector< T > &x) |
size_t | getBinCount (const size_t index) const |
Retuns the elements count into the selected bin index, where first one is 0. More... | |
double | getBinRatio (const size_t index) const |
Retuns the ratio in [0,1] range for the selected bin index, where first one is 0. More... | |
void | getHistogram (std::vector< double > &x, std::vector< double > &hits) const |
Returns the list of bin centers & hit counts. More... | |
void | getHistogramNormalized (std::vector< double > &x, std::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. More... | |
Static Public Member Functions | |
static CHistogram | createWithFixedWidth (double min, double max, double binWidth) |
Constructor with a fixed bin width. More... | |
Private Attributes | |
double | m_min |
The histogram limits. More... | |
double | m_max |
double | m_binSizeInv |
((max-min)/nBins)^-1 More... | |
std::vector< size_t > | m_bins |
The bins counter. More... | |
size_t | m_count |
The total elements count. More... | |
CHistogram::CHistogram | ( | const double | min, |
const double | max, | ||
const size_t | nBins | ||
) |
Constructor.
std::exception | On nBins<=0 or max<=min |
Definition at line 22 of file CHistogram.cpp.
References ASSERT_, m_binSizeInv, m_max, m_min, and min.
Referenced by createWithFixedWidth().
void CHistogram::add | ( | const double | x | ) |
Add an element to the histogram.
If element is out of [min,max] it is ignored.
Definition at line 42 of file CHistogram.cpp.
References m_bins, m_binSizeInv, m_count, m_max, and m_min.
Referenced by add(), mrpt::math::CMonteCarlo< T, NUM, OTHER >::CStatisticalAnalyzer::getDistribution(), and mrpt::math::histogram().
|
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 78 of file CHistogram.h.
References add().
|
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 87 of file CHistogram.h.
References add().
void CHistogram::clear | ( | ) |
|
inlinestatic |
Constructor with a fixed bin width.
std::exception | On max<=min or width<=0 |
Definition at line 58 of file CHistogram.h.
References ASSERT_, CHistogram(), and min.
Referenced by mrpt::math::CMonteCarlo< T, NUM, OTHER >::CStatisticalAnalyzer::getDistribution().
size_t 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 |
Definition at line 55 of file CHistogram.cpp.
References m_bins, and THROW_EXCEPTION.
double 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. |
Definition at line 65 of file CHistogram.cpp.
References m_bins, m_count, and THROW_EXCEPTION.
void CHistogram::getHistogram | ( | std::vector< double > & | x, |
std::vector< double > & | hits | ||
) | const |
Returns the list of bin centers & hit counts.
Definition at line 78 of file CHistogram.cpp.
References mrpt::math::linspace(), m_bins, m_max, and m_min.
Referenced by mrpt::math::histogram().
void CHistogram::getHistogramNormalized | ( | std::vector< double > & | x, |
std::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.
Definition at line 93 of file CHistogram.cpp.
References mrpt::math::linspace(), m_bins, m_binSizeInv, m_count, m_max, and m_min.
Referenced by mrpt::math::histogram().
|
private |
The bins counter.
Definition at line 45 of file CHistogram.h.
Referenced by add(), clear(), getBinCount(), getBinRatio(), getHistogram(), and getHistogramNormalized().
|
private |
((max-min)/nBins)^-1
Definition at line 43 of file CHistogram.h.
Referenced by add(), CHistogram(), and getHistogramNormalized().
|
private |
The total elements count.
Definition at line 47 of file CHistogram.h.
Referenced by add(), clear(), getBinRatio(), and getHistogramNormalized().
|
private |
Definition at line 41 of file CHistogram.h.
Referenced by add(), CHistogram(), getHistogram(), and getHistogramNormalized().
|
private |
The histogram limits.
Definition at line 41 of file CHistogram.h.
Referenced by add(), CHistogram(), getHistogram(), and getHistogramNormalized().
Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019 |