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 35 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 |
| double | m_max |
| The histogram limits. More... | |
| 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.
| 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 ASSERT_, m_bins, m_binSizeInv, m_count, m_max, and m_min.
Referenced by mrpt::math::CMonteCarlo< T, NUM, OTHER >::CStatisticalAnalyzer::getDistribution(), mrpt::math::histogram(), and TEST().
|
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 67 of file CHistogram.h.
|
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 76 of file CHistogram.h.
| void CHistogram::clear | ( | ) |
|
inlinestatic |
Constructor with a fixed bin width.
| std::exception | On max<=min or width<=0 |
Definition at line 52 of file CHistogram.h.
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 57 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 67 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(), and TEST().
| 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 90 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 40 of file CHistogram.h.
Referenced by add(), clear(), getBinCount(), getBinRatio(), getHistogram(), and getHistogramNormalized().
|
private |
((max-min)/nBins)^-1
Definition at line 39 of file CHistogram.h.
Referenced by add(), CHistogram(), and getHistogramNormalized().
|
private |
The total elements count.
Definition at line 41 of file CHistogram.h.
Referenced by add(), clear(), getBinRatio(), and getHistogramNormalized().
|
private |
The histogram limits.
Definition at line 38 of file CHistogram.h.
Referenced by add(), CHistogram(), getHistogram(), and getHistogramNormalized().
|
private |
Definition at line 38 of file CHistogram.h.
Referenced by add(), CHistogram(), getHistogram(), and getHistogramNormalized().
| Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019 |