Helios++
Helios software for LiDAR simulations
SurfaceInspector::maths::Histogram< T > Class Template Reference

Class for representation and handling of 1D histograms. More...

#include <Histogram.hpp>

Inheritance diagram for SurfaceInspector::maths::Histogram< T >:
Collaboration diagram for SurfaceInspector::maths::Histogram< T >:

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...
 
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...
 
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.
 
xmin
 The minimum value on data used to build the histogram.
 
xmax
 The maximum value on data used to build the histogram.
 
delta
 The difference between maximum and minimum value.
 
step
 The step between bins. It can also be understood as the bin size.
 
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
 

Detailed Description

template<typename T>
class SurfaceInspector::maths::Histogram< T >

Class for representation and handling of 1D histograms.

Author
Alberto M. Esmoris PEna
Version
1.0
Template Parameters
TType of element

Constructor & Destructor Documentation

◆ Histogram() [1/2]

template<typename T >
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\).

Parameters
xThe vector of values
nRequested number of bins
relativeCompute the relative frequencies if true. Skip their computation if false
densityCompute the density if true. Skip its computation if false

◆ Histogram() [2/2]

template<typename T >
SurfaceInspector::maths::Histogram< T >::Histogram ( xmin,
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\).

Parameters
xminWhere the histogram must start
xmaxWhere the histogram must end
xThe vector of values
nRequested number of bins
relativeCompute the relative frequencies if true. Skip their computation if false
densityCompute the density if true. Skip its computation if false

Member Function Documentation

◆ absCumsum() [1/2]

template<typename T >
T SurfaceInspector::maths::Histogram< T >::absCumsum ( )
inline

◆ absCumsum() [2/2]

template<typename T >
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} \]

Parameters
startThe inclusive start index of absolute cumsum \(\alpha\)
endThe exclusive end index of absolute cumsum \(\beta\)
Returns
Absoulte cumsum in index interval \([\alpha, \beta)\)

◆ computeDensity()

template<typename T >
void SurfaceInspector::maths::Histogram< T >::computeDensity ( )
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} \]

See also
Histogram::norm
Histogram::d

◆ computeRelativeFrequencies()

template<typename T >
void SurfaceInspector::maths::Histogram< T >::computeRelativeFrequencies ( )
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} \]

◆ estimateGaussian()

template<typename T >
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.

See also
SurfaceInspector::maths::functions::GaussianFunction

◆ extractMinMax()

template<typename T >
void SurfaceInspector::maths::Histogram< T >::extractMinMax ( vector< T > const &  x)
private

Extract min and max values from vector of values.

Parameters
xThe vector of values

◆ findCutPoint()

template<typename T >
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.

Parameters
pPercentage in \(\left[0, 1\right]\) interval
Returns
Cut point \(\tau\)

◆ recount()

template<typename T >
void SurfaceInspector::maths::Histogram< T >::recount ( vector< T > const &  x)
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| \]

Parameters
xthe Vector of values

◆ serialize()

template<typename T >
template<typename Archive >
void SurfaceInspector::maths::Histogram< T >::serialize ( Archive &  ar,
const unsigned int  version 
)
inlineprivate

Serialize a Histogram to a stream of bytes.

Template Parameters
ArchiveType of rendering
Parameters
arSpecific rendering for the stream of bytes
versionVerison number of Histogram

Member Data Documentation

◆ a

template<typename T >
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

◆ b

template<typename T >
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

◆ c

template<typename T >
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

◆ d

template<typename T >
vector<double> SurfaceInspector::maths::Histogram< T >::d

The density for each bin corresponding to the unitary area version of the histogram.

See also
Histogram::computeDensity

◆ norm

template<typename T >
T SurfaceInspector::maths::Histogram< T >::norm

The norm for the unitary area histogram.

See also
Histogram::computeDensity

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