DGtal  1.5.beta
DGtal::Histogram< TQuantity, TBinner > Class Template Reference

Aim: Represents a typical histogram in statistics, which is a discrete estimate of the probability distribution of a continuous variable. More...

#include <DGtal/math/Histogram.h>

Public Types

enum  Formula { SquareRoot , Sturges , Rice , Scott }
 
typedef TQuantity Quantity
 
typedef TBinner Binner
 
typedef Histogram< Quantity, BinnerSelf
 
typedef Binner::Bin Bin
 
typedef DGtal::uint64_t Size
 
typedef std::vector< SizeContainer
 
typedef Container::const_iterator ConstIterator
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CEuclideanRing< TQuantity >))
 
 BOOST_CONCEPT_ASSERT ((concepts::CBinner< TBinner >))
 
 BOOST_STATIC_ASSERT ((boost::is_same< TQuantity, typename TBinner::Quantity >::value))
 
 ~Histogram ()
 
 Histogram ()
 
void clear ()
 
void init (Clone< Binner > binner)
 
void init (Formula formula, const Statistic< Quantity > &stat)
 
void init (Bin nbBins, const Statistic< Quantity > &stat)
 
void addValue (Quantity q)
 
template<typename TInputIterator >
void addValues (TInputIterator it, TInputIterator itE)
 
void terminate ()
 
Bin bin (Quantity q) const
 
Bin size () const
 
Size area () const
 
Size nb (Bin b) const
 
Size accumulation (Bin b) const
 
double pdf (Bin b) const
 
double cdf (Bin b) const
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Protected Attributes

const BinnermyBinner
 The binner that places quantities into a bin. More...
 
Container myHistogram
 The histogram data. More...
 
Container myCumulativeHistogram
 The cumulative histogram data. More...
 

Private Member Functions

 Histogram (const Histogram &other)
 
Histogramoperator= (const Histogram &other)
 
void prepare (Bin size)
 

Detailed Description

template<typename TQuantity, typename TBinner = RegularBinner< TQuantity >>
class DGtal::Histogram< TQuantity, TBinner >

Aim: Represents a typical histogram in statistics, which is a discrete estimate of the probability distribution of a continuous variable.

Description of template class 'Histogram'

std::vector<double> v;
...
Statistic<double> stats;
stats.addValues( v.begin(), v.end() );
stats.terminate(); // stats are computed.
Histogram<double> hist;
hist.init( Histogram<double>::Scott, stats );
hist.addValues( v.begin(), v.end() );
hist.terminate();
// Displays the estimated probability density function
for ( unsigned int i = 0; i < hist.size(); ++i )
std::cout << i << " " << hist.pdf( i ) << std::endl;
Template Parameters
TQuantityany model of CEuclideanRing listed in NumberTraits and that can be castToDouble.
TBinnerany model of CBinner that puts a quantity into a bin. Default is RegularBinner<TQuantity>.

Definition at line 145 of file Histogram.h.

Member Typedef Documentation

◆ Bin

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
typedef Binner::Bin DGtal::Histogram< TQuantity, TBinner >::Bin

Definition at line 157 of file Histogram.h.

◆ Binner

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
typedef TBinner DGtal::Histogram< TQuantity, TBinner >::Binner

Definition at line 155 of file Histogram.h.

◆ ConstIterator

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
typedef Container::const_iterator DGtal::Histogram< TQuantity, TBinner >::ConstIterator

Definition at line 160 of file Histogram.h.

◆ Container

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
typedef std::vector<Size> DGtal::Histogram< TQuantity, TBinner >::Container

Definition at line 159 of file Histogram.h.

◆ Quantity

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
typedef TQuantity DGtal::Histogram< TQuantity, TBinner >::Quantity

Definition at line 154 of file Histogram.h.

◆ Self

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
typedef Histogram< Quantity, Binner > DGtal::Histogram< TQuantity, TBinner >::Self

Definition at line 156 of file Histogram.h.

◆ Size

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
typedef DGtal::uint64_t DGtal::Histogram< TQuantity, TBinner >::Size

Definition at line 158 of file Histogram.h.

Member Enumeration Documentation

◆ Formula

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
enum DGtal::Histogram::Formula

Determines the number of bins k or the width h as a function of n (number of samples), s (variance of samples).

Enumerator
SquareRoot 

Rule is k=sqrt(n)

Sturges 

Rule is k=ceil(log_2(n)+1)

Rice 

Rule is k=ceil(n^(1/3))

Scott 

Rule is h=3.5s/(n^(1/3))

Definition at line 166 of file Histogram.h.

166  { SquareRoot ,
167  Sturges ,
168  Rice ,
169  Scott };

Constructor & Destructor Documentation

◆ ~Histogram()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
DGtal::Histogram< TQuantity, TBinner >::~Histogram ( )

Destructor.

◆ Histogram() [1/2]

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
DGtal::Histogram< TQuantity, TBinner >::Histogram ( )

Constructor. The object is not valid.

◆ Histogram() [2/2]

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
DGtal::Histogram< TQuantity, TBinner >::Histogram ( const Histogram< TQuantity, TBinner > &  other)
private

Copy constructor.

Parameters
otherthe object to clone. Forbidden by default.

Member Function Documentation

◆ accumulation()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
Size DGtal::Histogram< TQuantity, TBinner >::accumulation ( Bin  b) const
Parameters
bany bin in 0 .. size()-1
Returns
the total number of quantities in bins 0 to b (included).
Precondition
terminate() must be called before.

◆ addValue()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
void DGtal::Histogram< TQuantity, TBinner >::addValue ( Quantity  q)

Add the quantity q to the histogram.

Parameters
qany quantity.

◆ addValues()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
template<typename TInputIterator >
void DGtal::Histogram< TQuantity, TBinner >::addValues ( TInputIterator  it,
TInputIterator  itE 
)

Add the quantities stored in range [it,itE) to the histogram.

Template Parameters
TInputIteratorany model of boost::InputIterator on Quantity.
Parameters
itan iterator on the first element of the range [it,itE)
itEan iterator after the last element of the range [it,itE)

Referenced by testHistogramGaussian(), testHistogramGaussian2(), and testHistogramUniform().

◆ area()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
Size DGtal::Histogram< TQuantity, TBinner >::area ( ) const
Returns
the total number of samples in the histogram, i.e. the number of added quantities.
Precondition
terminate() must be called before.

◆ bin()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
Bin DGtal::Histogram< TQuantity, TBinner >::bin ( Quantity  q) const
Parameters
qany quantity
Returns
the bin in which quantity q would fall if added to this object.

◆ BOOST_CONCEPT_ASSERT() [1/2]

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
DGtal::Histogram< TQuantity, TBinner >::BOOST_CONCEPT_ASSERT ( (concepts::CBinner< TBinner >)  )

◆ BOOST_CONCEPT_ASSERT() [2/2]

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
DGtal::Histogram< TQuantity, TBinner >::BOOST_CONCEPT_ASSERT ( (concepts::CEuclideanRing< TQuantity >)  )

◆ BOOST_STATIC_ASSERT()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
DGtal::Histogram< TQuantity, TBinner >::BOOST_STATIC_ASSERT ( (boost::is_same< TQuantity, typename TBinner::Quantity >::value)  )

◆ cdf()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
double DGtal::Histogram< TQuantity, TBinner >::cdf ( Bin  b) const
Returns
the cumulative distribution function at bin b.
Precondition
terminate() must be called before.

Referenced by testHistogramGaussian(), testHistogramGaussian2(), and testHistogramUniform().

◆ clear()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
void DGtal::Histogram< TQuantity, TBinner >::clear ( )

The object is fully cleared. The object must be initialized in order to be valid.

◆ init() [1/3]

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
void DGtal::Histogram< TQuantity, TBinner >::init ( Bin  nbBins,
const Statistic< Quantity > &  stat 
)

Initialization from a number of bins and a statistic (min, max, samples, variance can typically be used).

◆ init() [2/3]

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
void DGtal::Histogram< TQuantity, TBinner >::init ( Clone< Binner binner)

Initialization from Binner. The binner is cloned into this object.

Referenced by testHistogramGaussian(), testHistogramGaussian2(), and testHistogramUniform().

◆ init() [3/3]

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
void DGtal::Histogram< TQuantity, TBinner >::init ( Formula  formula,
const Statistic< Quantity > &  stat 
)

Initialization from a statistic (min, max, samples, variance can typically be used) and a given formula.

◆ isValid()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
bool DGtal::Histogram< TQuantity, TBinner >::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

◆ nb()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
Size DGtal::Histogram< TQuantity, TBinner >::nb ( Bin  b) const
Parameters
bany bin in 0 .. size()-1
Returns
the number of quantities in bin b.

◆ operator=()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
Histogram& DGtal::Histogram< TQuantity, TBinner >::operator= ( const Histogram< TQuantity, TBinner > &  other)
private

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'. Forbidden by default.

◆ pdf()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
double DGtal::Histogram< TQuantity, TBinner >::pdf ( Bin  b) const
Returns
the probability density function in the whole bin b (constant).
Precondition
terminate() must be called before.

Referenced by testHistogramGaussian(), testHistogramGaussian2(), and testHistogramUniform().

◆ prepare()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
void DGtal::Histogram< TQuantity, TBinner >::prepare ( Bin  size)
private

Prepares container for further data.

◆ selfDisplay()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
void DGtal::Histogram< TQuantity, TBinner >::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

◆ size()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
Bin DGtal::Histogram< TQuantity, TBinner >::size ( ) const
Returns
the number of bins.

Referenced by testHistogramGaussian(), testHistogramGaussian2(), and testHistogramUniform().

◆ terminate()

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
void DGtal::Histogram< TQuantity, TBinner >::terminate ( )

Should be called when all values have been added.

Referenced by testHistogramGaussian(), testHistogramGaussian2(), and testHistogramUniform().

Field Documentation

◆ myBinner

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
const Binner* DGtal::Histogram< TQuantity, TBinner >::myBinner
protected

The binner that places quantities into a bin.

Definition at line 285 of file Histogram.h.

◆ myCumulativeHistogram

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
Container DGtal::Histogram< TQuantity, TBinner >::myCumulativeHistogram
protected

The cumulative histogram data.

Definition at line 289 of file Histogram.h.

◆ myHistogram

template<typename TQuantity , typename TBinner = RegularBinner< TQuantity >>
Container DGtal::Histogram< TQuantity, TBinner >::myHistogram
protected

The histogram data.

Definition at line 287 of file Histogram.h.


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