Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Attributes | List of all members
Euclid::Histogram::Histogram< VarType, WeightType > Class Template Reference

#include <Histogram.h>

Collaboration diagram for Euclid::Histogram::Histogram< VarType, WeightType >:
Collaboration graph
[legend]

Classes

struct  ComputationImpl
 
struct  ComputationInterface
 
struct  ConstantWeight
 

Public Member Functions

template<typename IterType , typename BinType , typename = typename std::enable_if<std::is_move_constructible<BinType>::value>::type>
 Histogram (IterType begin, IterType end, BinType &&bin_type)
 
template<typename IterType , typename WeightIterType , typename BinType , typename = typename std::enable_if<std::is_move_constructible<BinType>::value>::type>
 Histogram (IterType begin, IterType end, WeightIterType wbegin, ELEMENTS_UNUSED WeightIterType wend, BinType &&bin_type)
 
 Histogram (const Histogram &other)
 
 Histogram (Histogram &&)=default
 
Histogramoperator= (const Histogram &)=default
 
Histogramoperator= (Histogram &&)=default
 
size_t size () const
 
std::vector< WeightType > getCounts () const
 
std::vector< VarType > getEdges () const
 
std::vector< VarType > getBins () const
 
std::pair< VarType, VarType > getBinEdges (size_t i) const
 
void clip (VarType min, VarType max)
 
std::tuple< VarType, VarType, VarType > getStats () const
 

Private Attributes

std::unique_ptr< ComputationInterfacem_binning_concept
 

Detailed Description

template<typename VarType, typename WeightType = float>
class Euclid::Histogram::Histogram< VarType, WeightType >

Histogram

Template Parameters
VarTypeThe type of the continuous variable. Must be an arithmetic type (either integral or floating point)
WeightTypeThe type used for the counts, which is the same as the one accepted for the weights.

Definition at line 138 of file Histogram.h.

Constructor & Destructor Documentation

◆ Histogram() [1/4]

template<typename VarType , typename WeightType = float>
template<typename IterType , typename BinType , typename = typename std::enable_if<std::is_move_constructible<BinType>::value>::type>
Euclid::Histogram::Histogram< VarType, WeightType >::Histogram ( IterType  begin,
IterType  end,
BinType &&  bin_type 
)
inline

Constructor

Template Parameters
IterTypeIterator type for both the edges and the values of the variable
BinTypeA concrete movable implementation of BinStrategy
Parameters
beginBeginning of the data
endEnd of the data
bin_typeAn instance of BinType. It will be taken ownership of by the Histogram

Definition at line 158 of file Histogram.h.

References Euclid::Histogram::Histogram< VarType, WeightType >::m_binning_concept, and std::move().

Here is the call graph for this function:

◆ Histogram() [2/4]

template<typename VarType , typename WeightType = float>
template<typename IterType , typename WeightIterType , typename BinType , typename = typename std::enable_if<std::is_move_constructible<BinType>::value>::type>
Euclid::Histogram::Histogram< VarType, WeightType >::Histogram ( IterType  begin,
IterType  end,
WeightIterType  wbegin,
ELEMENTS_UNUSED WeightIterType  wend,
BinType &&  bin_type 
)
inline

Constructor

Template Parameters
IterTypeIterator type for both the edges and the values of the variable
WeightIterTypeIterator type for the weights
BinTypeA concrete movable implementation of BinStrategy
Parameters
beginBeginning of the data
endEnd of the data
wbeginBeginning of the weights
wendEnd of the weights
bin_typeAn instance of BinType. It will be taken ownership of by the Histogram
Note
The number of values and weights must match

Definition at line 187 of file Histogram.h.

References Euclid::Histogram::Histogram< VarType, WeightType >::m_binning_concept, and std::move().

Here is the call graph for this function:

◆ Histogram() [3/4]

template<typename VarType , typename WeightType = float>
Euclid::Histogram::Histogram< VarType, WeightType >::Histogram ( const Histogram< VarType, WeightType > &  other)
inline

Copy constructor

Definition at line 198 of file Histogram.h.

References Euclid::Histogram::Histogram< VarType, WeightType >::m_binning_concept.

◆ Histogram() [4/4]

template<typename VarType , typename WeightType = float>
Euclid::Histogram::Histogram< VarType, WeightType >::Histogram ( Histogram< VarType, WeightType > &&  )
default

Move constructor

Member Function Documentation

◆ clip()

template<typename VarType , typename WeightType = float>
void Euclid::Histogram::Histogram< VarType, WeightType >::clip ( VarType  min,
VarType  max 
)
inline

Clip the histogram to the given range

Parameters
minMinimum value to keep
maxMaximum value to keep

Definition at line 272 of file Histogram.h.

References Euclid::Histogram::Histogram< VarType, WeightType >::m_binning_concept.

◆ getBinEdges()

template<typename VarType , typename WeightType = float>
std::pair< VarType, VarType > Euclid::Histogram::Histogram< VarType, WeightType >::getBinEdges ( size_t  i) const
inline
Parameters
iBin index
Returns
The edges for the given bin

Definition at line 261 of file Histogram.h.

References Euclid::Histogram::Histogram< VarType, WeightType >::m_binning_concept.

◆ getBins()

template<typename VarType , typename WeightType = float>
std::vector< VarType > Euclid::Histogram::Histogram< VarType, WeightType >::getBins ( ) const
inline
Returns
The center of the bins

Definition at line 248 of file Histogram.h.

References std::vector< T >::begin(), std::vector< T >::end(), std::generate(), and Euclid::Histogram::Histogram< VarType, WeightType >::m_binning_concept.

Here is the call graph for this function:

◆ getCounts()

template<typename VarType , typename WeightType = float>
std::vector< WeightType > Euclid::Histogram::Histogram< VarType, WeightType >::getCounts ( ) const
inline
Returns
The counts of the histogram

Definition at line 229 of file Histogram.h.

References Euclid::Histogram::Histogram< VarType, WeightType >::m_binning_concept.

◆ getEdges()

template<typename VarType , typename WeightType = float>
std::vector< VarType > Euclid::Histogram::Histogram< VarType, WeightType >::getEdges ( ) const
inline
Returns
The edges of the bins
Note
The number of edges is equal to the number of bins + 1

Definition at line 240 of file Histogram.h.

References Euclid::Histogram::Histogram< VarType, WeightType >::m_binning_concept.

◆ getStats()

template<typename VarType , typename WeightType = float>
std::tuple< VarType, VarType, VarType > Euclid::Histogram::Histogram< VarType, WeightType >::getStats ( ) const
inline

Compute the mean, the median and the standard deviation of the histogram

\[ \mu = \frac{\sum_{i=0}^{n} \mathit{bin}_i * \mathit{cnt}_i}{\sum_{i=0}^{n}cnt_i} \]

\[ \sigma = \sqrt{\frac{\sum_{i=0}^n \mathit{cnt}_i \times (\mathit{center}_i - \mu)^2}{\sum_{i=0}^n \mathit{cnt}_i}} \]

To find the median, a second pass is done over the bins, computing the cumulative distribution until the bin where it is greater or equal to 0.5. The median is then interpolated between the lower and higher edges.

Returns
A tuple (mean, median, sigma)

Definition at line 291 of file Histogram.h.

References Euclid::Histogram::Histogram< VarType, WeightType >::m_binning_concept.

◆ operator=() [1/2]

template<typename VarType , typename WeightType = float>
Histogram & Euclid::Histogram::Histogram< VarType, WeightType >::operator= ( const Histogram< VarType, WeightType > &  )
default

Assignment operator

◆ operator=() [2/2]

template<typename VarType , typename WeightType = float>
Histogram & Euclid::Histogram::Histogram< VarType, WeightType >::operator= ( Histogram< VarType, WeightType > &&  )
default

Move assignment operator

◆ size()

template<typename VarType , typename WeightType = float>
size_t Euclid::Histogram::Histogram< VarType, WeightType >::size ( ) const
inline
Returns
The number of bins on the histogram

Definition at line 221 of file Histogram.h.

References Euclid::Histogram::Histogram< VarType, WeightType >::m_binning_concept.

Member Data Documentation

◆ m_binning_concept

template<typename VarType , typename WeightType = float>
std::unique_ptr<ComputationInterface> Euclid::Histogram::Histogram< VarType, WeightType >::m_binning_concept
private

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