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 43 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 56 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 61 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::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 74 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::accum(), mx::math::histogramUniform< realT >::normalize(), mx::math::histogramUniform< realT >::reset(), and mx::math::six_fifths().

Member Function Documentation

◆ accum() [1/2]

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

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

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

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

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

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

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

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

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

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

References mx::math::histogramUniform< realT >::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 135 of file histogramUniform.hpp.

References mx::math::histogramUniform< realT >::m_freqs, and mx::math::six_fifths().

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

References mx::math::histogramUniform< realT >::m_freqs, mx::math::histogramUniform< realT >::m_width, and mx::math::six_fifths().

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

◆ reset()

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

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

Member Data Documentation

◆ m_freqs

◆ m_max

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

The maximum bin location.

Definition at line 47 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: