class mrpt::math::CHistogram
Overview
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"
#include <mrpt/math/CHistogram.h> class CHistogram { public: // construction CHistogram(const double min, const double max, size_t nBins); // methods CHistogram createWithFixedWidth(double min, double max, double binWidth); void clear(); void add(const double x); template <typename MAT_VECTOR_LIKE, typename = typename MAT_VECTOR_LIKE::Scalar> void add(const MAT_VECTOR_LIKE& x); template <typename T> void add(const std::vector<T>& x); size_t getBinCount(size_t index) const; double getBinRatio(size_t index) const; void getHistogram(std::vector<double>& x, std::vector<double>& hits) const; void getHistogramNormalized(std::vector<double>& x, std::vector<double>& hits) const; };
Construction
CHistogram(const double min, const double max, size_t nBins)
Constructor.
Parameters:
std::exception |
On nBins<=0 or max<=min |
Methods
CHistogram createWithFixedWidth(double min, double max, double binWidth)
Constructor with a fixed bin width.
Parameters:
std::exception |
On max<=min or width<=0 |
void clear()
Clear the histogram:
void add(const double x)
Add an element to the histogram.
If element is out of [min,max] it is ignored.
template <typename MAT_VECTOR_LIKE, typename = typename MAT_VECTOR_LIKE::Scalar> void add(const MAT_VECTOR_LIKE& x)
Add all the elements from a MRPT container to the histogram.
If an element is out of [min,max] it is ignored.
template <typename T> void add(const std::vector<T>& x)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
size_t getBinCount(size_t index) const
Returns the elements count into the selected bin index, where first one is 0.
Parameters:
std::exception |
On invalid index |
double getBinRatio(size_t index) const
Returns 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.
Parameters:
std::exception |
On invalid index. |
void getHistogram(std::vector<double>& x, std::vector<double>& hits) const
Returns the list of bin centers & hit counts.
See also:
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.
See also: