mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
mx::math::histogramUniform< realT > Class Template Reference

template<typename realT>
class mx::math::histogramUniform< realT >

A histogram with uniform bin spacing.

Calculates the frequency in bins with uniform spacing.

Template Parameters
realTthe real data type

Definition at line 43 of file histogramUniform.hpp.

#include <math/histogramUniform.hpp>

Public Member Functions

 histogramUniform ()
 Default c'tor, does not allocate. More...
 
 histogramUniform (realT mn, realT mx, realT w)
 Setup the histogram, performing allocations. More...
 
void setup (realT mn, realT mx, realT w)
 Setup the histogram, performing allocations. More...
 
void reset ()
 Resize and 0 the frequency vector. Assumes m_min, m_max, and m_width are set. More...
 
void accum (const realT &val)
 Accumulate a value in the appropriate bin. More...
 
void accum (const std::vector< realT > &vals)
 Accumulate a vector of values. More...
 
realT freq (int i)
 Get the frequency in the i-th bin. More...
 
int bins ()
 Get the number of bins. More...
 
realT binLeft (int i)
 Get the value of the left-edge of the i-th bin. More...
 
realT binMid (int i)
 Get the value of the middle of the i-th bin. More...
 
realT binRight (int i)
 Get the value of the right edge of the i-th bin. More...
 
void normalize (int excludeTop=0)
 Normalize the current frequencies so that the integral over all bins is 1. More...
 

Public Attributes

realT m_min {0}
 The mininum bin location. More...
 
realT m_max {0}
 The maximum bin location. More...
 
realT m_width {0}
 The bin width. More...
 
std::vector< realT > _freqs
 The frequencies, one for each bin. More...
 

Constructor & Destructor Documentation

◆ histogramUniform() [1/2]

template<typename realT >
mx::math::histogramUniform< realT >::histogramUniform ( )
inline

Default c'tor, does not allocate.

Must call setup before use

Definition at line 55 of file histogramUniform.hpp.

◆ histogramUniform() [2/2]

template<typename realT >
mx::math::histogramUniform< realT >::histogramUniform ( realT  mn,
realT  mx,
realT  w 
)
inline

Setup the histogram, performing allocations.

Parameters
[in]mnthe new minimum bin location
[in]mxthe new maximum bin location
[in]wthe bin width

Definition at line 58 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::reset().

Member Function Documentation

◆ accum() [1/2]

template<typename realT >
void mx::math::histogramUniform< realT >::accum ( const realT &  val)
inline

Accumulate a value in the appropriate bin.

Parameters
[in]valThe value to accumulate

Definition at line 86 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::_freqs, mx::math::histogramUniform< realT >::m_min, and mx::math::histogramUniform< realT >::m_width.

Referenced by mx::math::histogramUniform< realT >::accum().

◆ accum() [2/2]

template<typename realT >
void mx::math::histogramUniform< realT >::accum ( const std::vector< realT > &  vals)
inline

Accumulate a vector of values.

Parameters
[in]valsThe vector of values to accumulate

Definition at line 97 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::accum().

◆ binLeft()

template<typename realT >
realT mx::math::histogramUniform< realT >::binLeft ( int  i)
inline

Get the value of the left-edge of the i-th bin.

Returns
the value of the left-edge of the i-th bin.
Parameters
[in]ithe bin number

Definition at line 115 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::m_min, and mx::math::histogramUniform< realT >::m_width.

◆ binMid()

template<typename realT >
realT mx::math::histogramUniform< realT >::binMid ( int  i)
inline

Get the value of the middle of the i-th bin.

Returns
the value of the middle of the i-th bin.
Parameters
[in]ithe bin number

Definition at line 121 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::m_min, and mx::math::histogramUniform< realT >::m_width.

◆ binRight()

template<typename realT >
realT mx::math::histogramUniform< realT >::binRight ( int  i)
inline

Get the value of the right edge of the i-th bin.

Returns
the value of the right edge of the i-th bin.
Parameters
[in]ithe bin number

Definition at line 127 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::m_min, and mx::math::histogramUniform< realT >::m_width.

◆ bins()

template<typename realT >
int mx::math::histogramUniform< realT >::bins ( )
inline

Get the number of bins.

Returns
the size of the frequency vector.

Definition at line 109 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::_freqs.

◆ freq()

template<typename realT >
realT mx::math::histogramUniform< realT >::freq ( int  i)
inline

Get the frequency in the i-th bin.

Returns
the current value of _freqs[i].
Parameters
[in]ithe bin number

Definition at line 103 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::_freqs.

◆ normalize()

template<typename realT >
void mx::math::histogramUniform< realT >::normalize ( int  excludeTop = 0)
inline

Normalize the current frequencies so that the integral over all bins is 1.

This normalizes the histogram so that it is a probability distribution, such that the sum \( \sum_i P_i \Delta x = 1 \) where \( \Delta x \) is the bin width.

Parameters
[in]excludeTop[optional] specifies a number of bins at the top of the range to exclude from the sum

Definition at line 136 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::_freqs, and mx::math::histogramUniform< realT >::m_width.

◆ reset()

template<typename realT >
void mx::math::histogramUniform< realT >::reset ( )
inline

◆ setup()

template<typename realT >
void mx::math::histogramUniform< realT >::setup ( realT  mn,
realT  mx,
realT  w 
)
inline

Setup the histogram, performing allocations.

Parameters
[in]mnthe new minimum bin location
[in]mxthe new maximum bin location
[in]wthe bin width

Definition at line 67 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::m_max, mx::math::histogramUniform< realT >::m_min, mx::math::histogramUniform< realT >::m_width, and mx::math::histogramUniform< realT >::reset().

Member Data Documentation

◆ _freqs

◆ m_max

template<typename realT >
realT mx::math::histogramUniform< realT >::m_max {0}

The maximum bin location.

Definition at line 48 of file histogramUniform.hpp.

Referenced by mx::math::histogramUniform< realT >::reset(), and mx::math::histogramUniform< realT >::setup().

◆ m_min

◆ m_width


The documentation for this class was generated from the following file: