mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
A histogram with uniform bin spacing.
Calculates the frequency in bins with uniform spacing.
realT | the 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... | |
|
inline |
Default c'tor, does not allocate.
Must call setup before use
Definition at line 55 of file histogramUniform.hpp.
|
inline |
Setup the histogram, performing allocations.
[in] | mn | the new minimum bin location |
[in] | mx | the new maximum bin location |
[in] | w | the bin width |
Definition at line 58 of file histogramUniform.hpp.
References mx::math::histogramUniform< realT >::reset().
|
inline |
Accumulate a value in the appropriate bin.
[in] | val | The 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().
|
inline |
Accumulate a vector of values.
[in] | vals | The vector of values to accumulate |
Definition at line 97 of file histogramUniform.hpp.
References mx::math::histogramUniform< realT >::accum().
|
inline |
Get the value of the left-edge of the i-th bin.
[in] | i | the bin number |
Definition at line 115 of file histogramUniform.hpp.
References mx::math::histogramUniform< realT >::m_min, and mx::math::histogramUniform< realT >::m_width.
|
inline |
Get the value of the middle of the i-th bin.
[in] | i | the bin number |
Definition at line 121 of file histogramUniform.hpp.
References mx::math::histogramUniform< realT >::m_min, and mx::math::histogramUniform< realT >::m_width.
|
inline |
Get the value of the right edge of the i-th bin.
[in] | i | the bin number |
Definition at line 127 of file histogramUniform.hpp.
References mx::math::histogramUniform< realT >::m_min, and mx::math::histogramUniform< realT >::m_width.
|
inline |
Get the number of bins.
Definition at line 109 of file histogramUniform.hpp.
References mx::math::histogramUniform< realT >::_freqs.
|
inline |
Get the frequency in the i-th bin.
[in] | i | the bin number |
Definition at line 103 of file histogramUniform.hpp.
References mx::math::histogramUniform< realT >::_freqs.
|
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.
[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.
|
inline |
Resize and 0 the frequency vector. Assumes m_min, m_max, and m_width are set.
Definition at line 80 of file histogramUniform.hpp.
References mx::math::histogramUniform< realT >::_freqs, mx::math::histogramUniform< realT >::m_max, mx::math::histogramUniform< realT >::m_min, and mx::math::histogramUniform< realT >::m_width.
Referenced by mx::math::histogramUniform< realT >::histogramUniform(), and mx::math::histogramUniform< realT >::setup().
|
inline |
Setup the histogram, performing allocations.
[in] | mn | the new minimum bin location |
[in] | mx | the new maximum bin location |
[in] | w | the 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().
std::vector<realT> mx::math::histogramUniform< realT >::_freqs |
The frequencies, one for each bin.
Definition at line 51 of file histogramUniform.hpp.
Referenced by mx::math::histogramUniform< realT >::accum(), mx::math::histogramUniform< realT >::bins(), mx::math::histogramUniform< realT >::freq(), mx::math::histogramUniform< realT >::normalize(), and mx::math::histogramUniform< realT >::reset().
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().
realT mx::math::histogramUniform< realT >::m_min {0} |
The mininum bin location.
Definition at line 47 of file histogramUniform.hpp.
Referenced by mx::math::histogramUniform< realT >::accum(), mx::math::histogramUniform< realT >::binLeft(), mx::math::histogramUniform< realT >::binMid(), mx::math::histogramUniform< realT >::binRight(), mx::math::histogramUniform< realT >::reset(), and mx::math::histogramUniform< realT >::setup().
realT mx::math::histogramUniform< realT >::m_width {0} |
The bin width.
Definition at line 49 of file histogramUniform.hpp.
Referenced by mx::math::histogramUniform< realT >::accum(), mx::math::histogramUniform< realT >::binLeft(), mx::math::histogramUniform< realT >::binMid(), mx::math::histogramUniform< realT >::binRight(), mx::math::histogramUniform< realT >::normalize(), mx::math::histogramUniform< realT >::reset(), and mx::math::histogramUniform< realT >::setup().