MRPT  2.0.4
List of all members | 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 33 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...
 
CHistogram createWithFixedWidth (double min, double max, double binWidth)
 Constructor with a fixed bin width. More...
 
void clear ()
 Clear the histogram: More...
 
void add (const double x)
 Add an element to the histogram. More...
 
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. 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...
 

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, and m_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 ASSERT_, m_bins, m_binSizeInv, m_count, m_max, and m_min.

Referenced by add(), mrpt::math::CMonteCarlo< T, NUM, OTHER >::CStatisticalAnalyzer::getDistribution(), mrpt::math::histogram(), and TEST().

Here is the caller graph for this function:

◆ add() [2/3]

template<typename MAT_VECTOR_LIKE , typename = typename MAT_VECTOR_LIKE::Scalar>
void mrpt::math::CHistogram::add ( const MAT_VECTOR_LIKE &  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 69 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 77 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.

Referenced by TEST().

Here is the caller graph for this function:

◆ createWithFixedWidth()

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

Constructor with a fixed bin width.

Exceptions
std::exceptionOn max<=min or width<=0

Definition at line 97 of file CHistogram.cpp.

References ASSERT_, and CHistogram().

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 57 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 67 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 77 of file CHistogram.cpp.

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

Referenced by mrpt::math::histogram(), and TEST().

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 86 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 41 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 39 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 43 of file CHistogram.h.

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

◆ m_max

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

Definition at line 37 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 37 of file CHistogram.h.

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




Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020