DGtal  0.9.3beta
Public Types | Public Member Functions | Protected Attributes | Private Member Functions
DGtal::Histogram< TQuantity, TBinner > Class Template Reference

#include <DGtal/math/Histogram.h>

Collaboration diagram for DGtal::Histogram< TQuantity, TBinner >:
[legend]

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
 
Container myHistogram
 
Container myCumulativeHistogram
 

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

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

Definition at line 157 of file Histogram.h.

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

Definition at line 155 of file Histogram.h.

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

Definition at line 160 of file Histogram.h.

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

Definition at line 159 of file Histogram.h.

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

Definition at line 154 of file Histogram.h.

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

Definition at line 156 of file Histogram.h.

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

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.

Constructor & Destructor Documentation

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

Destructor.

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

Constructor. The object is not valid.

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

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.
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.
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)
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.
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.
template<typename TQuantity, typename TBinner = RegularBinner< TQuantity >>
DGtal::Histogram< TQuantity, TBinner >::BOOST_CONCEPT_ASSERT ( (concepts::CEuclideanRing< TQuantity >)  )
template<typename TQuantity, typename TBinner = RegularBinner< TQuantity >>
DGtal::Histogram< TQuantity, TBinner >::BOOST_CONCEPT_ASSERT ( (concepts::CBinner< TBinner >)  )
template<typename TQuantity, typename TBinner = RegularBinner< TQuantity >>
DGtal::Histogram< TQuantity, TBinner >::BOOST_STATIC_ASSERT ( (boost::is_same< TQuantity, typename TBinner::Quantity >::value)  )
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.
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.

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.

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.

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).

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.
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.
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.
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.
template<typename TQuantity, typename TBinner = RegularBinner< TQuantity >>
void DGtal::Histogram< TQuantity, TBinner >::prepare ( Bin  size)
private

Prepares container for further data.

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.
template<typename TQuantity, typename TBinner = RegularBinner< TQuantity >>
Bin DGtal::Histogram< TQuantity, TBinner >::size ( ) const
Returns
the number of bins.
template<typename TQuantity, typename TBinner = RegularBinner< TQuantity >>
void DGtal::Histogram< TQuantity, TBinner >::terminate ( )

Should be called when all values have been added.

Field Documentation

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.

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.

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: