Class CHistogram

Class Documentation

class CHistogram

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) << "\n";       // Result: "1"
std::cout << hist.getBinRatio(0) << "\n";       // Result: "0.33"

Public Functions

CHistogram(const double min, const double max, size_t nBins)

Constructor

Throws:

std::exception – On nBins<=0 or max<=min

CHistogram createWithFixedWidth(double min, double max, double binWidth)

Constructor with a fixed bin width.

Throws:

std::exception – On max<=min or width<=0

void clear()

Clear the histogram:

void add(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>
inline 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>
inline 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.

Throws:

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.

Throws:

std::exception – On invalid index.

void getHistogram(std::vector<double> &x, std::vector<double> &hits) const

Returns the list of bin centers & hit counts

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

getHistogram