Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
mrpt::math::CHistogram Class Reference

Detailed Description

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 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...
 

Constructor & Destructor Documentation

◆ CHistogram()

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

Constructor.

Exceptions
std::exceptionOn 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().

Here is the caller graph for this function:

Member Function Documentation

◆ add() [1/3]

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().

Here is the caller graph for this function:

◆ add() [2/3]

template<typename Derived >
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 78 of file CHistogram.h.

References add().

Here is the call graph for this function:

◆ add() [3/3]

template<typename T >
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 87 of file CHistogram.h.

References add().

Here is the call graph for this function:

◆ clear()

void CHistogram::clear ( )

Clear the histogram:

Definition at line 33 of file CHistogram.cpp.

References m_bins, and m_count.

◆ createWithFixedWidth()

static CHistogram mrpt::math::CHistogram::createWithFixedWidth ( double  min,
double  max,
double  binWidth 
)
inlinestatic

Constructor with a fixed bin width.

Exceptions
std::exceptionOn 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBinCount()

size_t CHistogram::getBinCount ( const size_t  index) const

Retuns the elements count into the selected bin index, where first one is 0.

Exceptions
std::exceptionOn invalid index

Definition at line 55 of file CHistogram.cpp.

References m_bins, and THROW_EXCEPTION.

◆ getBinRatio()

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.

Exceptions
std::exceptionOn invalid index.

Definition at line 65 of file CHistogram.cpp.

References m_bins, m_count, and THROW_EXCEPTION.

◆ getHistogram()

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

Returns the list of bin centers & hit counts.

See also
getHistogramNormalized

Definition at line 78 of file CHistogram.cpp.

References mrpt::math::linspace(), m_bins, m_max, and m_min.

Referenced by mrpt::math::histogram().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getHistogramNormalized()

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.

See also
getHistogram

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().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_bins

std::vector<size_t> mrpt::math::CHistogram::m_bins
private

The bins counter.

Definition at line 45 of file CHistogram.h.

Referenced by add(), clear(), getBinCount(), getBinRatio(), getHistogram(), and getHistogramNormalized().

◆ m_binSizeInv

double mrpt::math::CHistogram::m_binSizeInv
private

((max-min)/nBins)^-1

Definition at line 43 of file CHistogram.h.

Referenced by add(), CHistogram(), and getHistogramNormalized().

◆ m_count

size_t mrpt::math::CHistogram::m_count
private

The total elements count.

Definition at line 47 of file CHistogram.h.

Referenced by add(), clear(), getBinRatio(), and getHistogramNormalized().

◆ m_max

double mrpt::math::CHistogram::m_max
private

Definition at line 41 of file CHistogram.h.

Referenced by add(), CHistogram(), getHistogram(), and getHistogramNormalized().

◆ m_min

double mrpt::math::CHistogram::m_min
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