mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
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 45 of file histogramUniform.hpp.

#include <math/histogramUniform.hpp>

Public Member Functions

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

Protected Attributes

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

Constructor & Destructor Documentation

◆ histogramUniform() [1/3]

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

Default c'tor, does not allocate.

Must call setup before use

Definition at line 58 of file histogramUniform.hpp.

◆ histogramUniform() [2/3]

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

C'tor to setup the histogram, performing allocations.

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

Definition at line 63 of file histogramUniform.hpp.

References m_max, m_min, m_width, and reset().

◆ histogramUniform() [3/3]

template<typename realT>
mx::math::histogramUniform< realT >::histogramUniform ( realT mn,
realT mx,
realT w,
const std::vector< realT > & vals,
bool normalize = false )
inline

C'tor to setup the histogram, performing allocations, and accumulate from a vector of values.

Optionally normalizes the histogram

Parameters
[in]mnthe minimum bin location
[in]mxthe maximum bin location
[in]wthe bin width
[in]valsThe vector of values to accumulate
[in]normalize[opt] whether or not to normalize after accumulation

Definition at line 76 of file histogramUniform.hpp.

References accum(), m_max, m_min, m_width, normalize(), and 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 112 of file histogramUniform.hpp.

References m_freqs, m_min, and m_width.

Referenced by histogramUniform(), and 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 128 of file histogramUniform.hpp.

References 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 149 of file histogramUniform.hpp.

References m_min, and 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 155 of file histogramUniform.hpp.

References m_min, and 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 161 of file histogramUniform.hpp.

References m_min, and 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 143 of file histogramUniform.hpp.

References m_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 m_freqs[i].
Parameters
[in]ithe bin number

Definition at line 137 of file histogramUniform.hpp.

References m_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 170 of file histogramUniform.hpp.

References m_freqs, and m_width.

Referenced by histogramUniform().

◆ reset()

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

Resize and 0 the frequency vector. Assumes m_min, m_max, and m_width are set.

Definition at line 106 of file histogramUniform.hpp.

References m_freqs, m_max, m_min, and m_width.

Referenced by histogramUniform(), histogramUniform(), and setup().

◆ 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 93 of file histogramUniform.hpp.

References m_max, m_min, m_width, and reset().

Member Data Documentation

◆ m_freqs

template<typename realT>
std::vector<realT> mx::math::histogramUniform< realT >::m_freqs
protected

The frequencies, one for each bin.

Definition at line 52 of file histogramUniform.hpp.

Referenced by accum(), bins(), freq(), normalize(), and reset().

◆ m_max

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

The maximum bin location.

Definition at line 49 of file histogramUniform.hpp.

Referenced by histogramUniform(), histogramUniform(), reset(), and setup().

◆ m_min

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

The mininum bin location.

Definition at line 48 of file histogramUniform.hpp.

Referenced by histogramUniform(), histogramUniform(), accum(), binLeft(), binMid(), binRight(), reset(), and setup().

◆ m_width

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

The bin width.

Definition at line 50 of file histogramUniform.hpp.

Referenced by histogramUniform(), histogramUniform(), accum(), binLeft(), binMid(), binRight(), normalize(), reset(), and setup().


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