Helios++
Helios software for LiDAR simulations
|
Class for representation and handling of 1D histograms. More...
#include <Histogram.hpp>
Public Member Functions | |
Histogram (vector< T > x, size_t n=256, bool relative=true, bool density=true) | |
Build a histogram from given vector of values \(\vec{x}\) and requested number of bins \(n\). More... | |
Histogram (T xmin, T xmax, vector< T > x, size_t n=256, bool relative=true, bool density=true) | |
Build a histogram starting at xmin and ending at xmax populated by given vector of values \(\vec{x}\) and with requested number of bins \(n\). More... | |
virtual | ~Histogram ()=default |
Virtual destructor for the histogram. | |
GaussianFunction< T > | estimateGaussian () |
Estimate a gaussian function from the histogram. Notice this method MUST NOT be called if histogram's density is not available. More... | |
T | findCutPoint (double p) |
Obtain the cut point (value) \(\tau\) so approximately \(100p \%\) of the elements are greater than it. More... | |
size_t | absCumsum (size_t const start, size_t const end) |
Compute the cumulative sum of absolute frequencies inside given index interval. More... | |
T | absCumsum () |
Like absCumsum(size_t const, size_t const) but for the entire histogram. More... | |
Public Attributes | |
size_t | m |
The number of elements considered to build the histogram. | |
size_t | n |
The number of bins. | |
T | xmin |
The minimum value on data used to build the histogram. | |
T | xmax |
The maximum value on data used to build the histogram. | |
T | delta |
The difference between maximum and minimum value. | |
T | step |
The step between bins. It can also be understood as the bin size. | |
T | norm |
The norm for the unitary area histogram. More... | |
vector< size_t > | c |
The absolute frequency, it is number of elements in each bin. More... | |
vector< double > | r |
The relative frequency for each bin. | |
vector< double > | d |
The density for each bin corresponding to the unitary area version of the histogram. More... | |
vector< T > | a |
The start value for each bin. More... | |
vector< T > | b |
Private Member Functions | |
template<typename Archive > | |
void | serialize (Archive &ar, const unsigned int version) |
Serialize a Histogram to a stream of bytes. More... | |
void | extractMinMax (vector< T > const &x) |
Extract min and max values from vector of values. More... | |
void | computeBinningIntervals () |
Compute the \([a, b]\) interval for each bin. | |
void | recount (vector< T > const &x) |
Count the number of elements in each bin, considering given vector of values \(\vec{x}\). More... | |
void | computeRelativeFrequencies () |
Compute the relative frequencies for each bin. More... | |
void | computeDensity () |
Compute the density (or normalized) histogram. More... | |
Friends | |
class | boost::serialization::access |
Class for representation and handling of 1D histograms.
T | Type of element |
SurfaceInspector::maths::Histogram< T >::Histogram | ( | vector< T > | x, |
size_t | n = 256 , |
||
bool | relative = true , |
||
bool | density = true |
||
) |
Build a histogram from given vector of values \(\vec{x}\) and requested number of bins \(n\).
x | The vector of values |
n | Requested number of bins |
relative | Compute the relative frequencies if true. Skip their computation if false |
density | Compute the density if true. Skip its computation if false |
SurfaceInspector::maths::Histogram< T >::Histogram | ( | T | xmin, |
T | xmax, | ||
vector< T > | x, | ||
size_t | n = 256 , |
||
bool | relative = true , |
||
bool | density = true |
||
) |
Build a histogram starting at xmin and ending at xmax populated by given vector of values \(\vec{x}\) and with requested number of bins \(n\).
xmin | Where the histogram must start |
xmax | Where the histogram must end |
x | The vector of values |
n | Requested number of bins |
relative | Compute the relative frequencies if true. Skip their computation if false |
density | Compute the density if true. Skip its computation if false |
|
inline |
Like absCumsum(size_t const, size_t const) but for the entire histogram.
size_t SurfaceInspector::maths::Histogram< T >::absCumsum | ( | size_t const | start, |
size_t const | end | ||
) |
Compute the cumulative sum of absolute frequencies inside given index interval.
\[ \sum_{i=\alpha}^{\beta-1}{c_i} \]
start | The inclusive start index of absolute cumsum \(\alpha\) |
end | The exclusive end index of absolute cumsum \(\beta\) |
|
private |
Compute the density (or normalized) histogram.
Let \(h\) be the step or bin size, and \(c_i\) the count for i-th bin. Now the norm \(\lambda\) can be defined as:
\[ \lambda = \sum_{i=1}^{n} h c_i \]
Then, the unitary area density (AKA normalized frequency) for each i-th bin \(d_i\) can be calculated.
\[ d_i = \frac{c_i}{\lambda} \]
|
private |
Compute the relative frequencies for each bin.
Let \(m\) be the number of considered data points when building the histogram and \(c_i\) the count of elements at i-th bin. Thus, the relative frequency for i-th bin \(r_i\) is:
\[ r_i = \frac{c_i}{m} \]
GaussianFunction<T> SurfaceInspector::maths::Histogram< T >::estimateGaussian | ( | ) |
Estimate a gaussian function from the histogram. Notice this method MUST NOT be called if histogram's density is not available.
|
private |
Extract min and max values from vector of values.
x | The vector of values |
T SurfaceInspector::maths::Histogram< T >::findCutPoint | ( | double | p | ) |
Obtain the cut point (value) \(\tau\) so approximately \(100p \%\) of the elements are greater than it.
Notice this method MUST NOT be called if histogram's relative frequencies are not available.
p | Percentage in \(\left[0, 1\right]\) interval |
|
private |
Count the number of elements in each bin, considering given vector of values \(\vec{x}\).
Let \(\Delta = max\left(\vec{x}\right) - min\left(\vec{x}\right)\) so:
\[ \forall x \in \vec{x}, \hat{x} = \frac{x-min\left(\vec{x}\right)}{\Delta} \]
Now for any \(i\) bin, its count \(c_i\) can be defined as follows:
\[ c_i = \left|\left\{ \hat{x} : \left\lfloor n\hat{x}\right\rfloor = i \right\}\right| \]
x | the Vector of values |
|
inlineprivate |
vector<T> SurfaceInspector::maths::Histogram< T >::a |
The start value for each bin.
\(a_i = x\) means x is the start value for i-th bin
vector<T> SurfaceInspector::maths::Histogram< T >::b |
@briet The end value for each bin
\(b_i = x\) means y is the end value for i-th bin
vector<size_t> SurfaceInspector::maths::Histogram< T >::c |
The absolute frequency, it is number of elements in each bin.
\(c_i = k\) means there are k elements in the i-th bin
vector<double> SurfaceInspector::maths::Histogram< T >::d |
The density for each bin corresponding to the unitary area version of the histogram.
T SurfaceInspector::maths::Histogram< T >::norm |
The norm for the unitary area histogram.