DGtal  0.9.3beta
Public Types | Public Member Functions | Private Attributes
DGtal::Statistic< TQuantity > Class Template Reference

#include <DGtal/math/Statistic.h>

Inheritance diagram for DGtal::Statistic< TQuantity >:
[legend]
Collaboration diagram for DGtal::Statistic< TQuantity >:
[legend]

Public Types

typedef TQuantity Quantity
 
typedef std::vector< QuantityContainer
 
typedef Container::const_iterator ConstIterator
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CCommutativeRing< Quantity >))
 
 ~Statistic ()
 
 Statistic (bool storeSample=false)
 
 Statistic (const Statistic &other)
 
Statisticoperator= (const Statistic &other)
 
Statisticoperator+= (const Statistic &other)
 
Statistic operator+ (const Statistic &other) const
 
ConstIterator begin () const
 
ConstIterator end () const
 
unsigned int samples () const
 
double mean () const
 
double variance () const
 
double unbiasedVariance () const
 
Quantity max () const
 
Quantity min () const
 
Quantity median ()
 
void addValue (Quantity v)
 
template<class Iter >
void addValues (Iter b, Iter e)
 
void clear ()
 
void terminate ()
 
void selfDisplay (std::ostream &that_stream) const
 
bool OK () const
 

Private Attributes

unsigned int mySamples
 
Quantity myExp
 
Quantity myExp2
 
Quantity myMax
 
Quantity myMin
 
Quantity myMedian
 
Container myValues
 
bool myStoreSamples
 
bool myIsTerminated
 

Detailed Description

template<typename TQuantity>
class DGtal::Statistic< TQuantity >

Aim: This class processes a set of sample values for one variable and can then compute different statistics, like sample mean, sample variance, sample unbiased variance, etc. It is minimalistic for space efficiency. For multiple variables, sample storage and others, see Statistics class.

Description of class 'Statistic'

Backported from ImaGene. [42]

See also
testStatistics.cpp
Template Parameters
TQuantityany model of CCommutativeRing.

Definition at line 69 of file Statistic.h.

Member Typedef Documentation

template<typename TQuantity>
typedef Container::const_iterator DGtal::Statistic< TQuantity >::ConstIterator

Definition at line 77 of file Statistic.h.

template<typename TQuantity>
typedef std::vector< Quantity > DGtal::Statistic< TQuantity >::Container

Definition at line 76 of file Statistic.h.

template<typename TQuantity>
typedef TQuantity DGtal::Statistic< TQuantity >::Quantity

Definition at line 74 of file Statistic.h.

Constructor & Destructor Documentation

template<typename TQuantity>
DGtal::Statistic< TQuantity >::~Statistic ( )

Destructor.

template<typename TQuantity>
DGtal::Statistic< TQuantity >::Statistic ( bool  storeSample = false)

Constructor.

template<typename TQuantity>
DGtal::Statistic< TQuantity >::Statistic ( const Statistic< TQuantity > &  other)

Copy constructor.

Parameters
otherthe object to clone.

Member Function Documentation

template<typename TQuantity>
void DGtal::Statistic< TQuantity >::addValue ( Quantity  v)
template<typename TQuantity>
template<class Iter >
void DGtal::Statistic< TQuantity >::addValues ( Iter  b,
Iter  e 
)

Adds a sequence of sample values, scanning a container from iterators [b] to [e].

Exemple:

vector<Quantity> x;
Statistic stats;
stats.addValue( x + 4, x + 10 );
Parameters
ban iterator on the starting point.
ean iterator after the last point.
template<typename TQuantity>
ConstIterator DGtal::Statistic< TQuantity >::begin ( ) const
Returns
an iterator on the first stored value (if storeSample was set).
template<typename TQuantity>
DGtal::Statistic< TQuantity >::BOOST_CONCEPT_ASSERT ( (concepts::CCommutativeRing< Quantity >)  )
template<typename TQuantity>
void DGtal::Statistic< TQuantity >::clear ( )

Clears the object. As if it has just been created.

template<typename TQuantity>
ConstIterator DGtal::Statistic< TQuantity >::end ( ) const
Returns
an iterator after the last stored value (if storeSample was set).
template<typename TQuantity>
Quantity DGtal::Statistic< TQuantity >::max ( ) const
Returns
the maximal value.
template<typename TQuantity>
double DGtal::Statistic< TQuantity >::mean ( ) const
Returns
the sample mean (given as double).
template<typename TQuantity>
Quantity DGtal::Statistic< TQuantity >::median ( )

Return the median value of the Statistic values. It can be given in two possible cases:

  • if the the values are stored in the 'Statistic' objects (not always a good solution). (complexity: linear on average)
  • if the values were first stored and computed by the function terminate().
    Returns
    the median value.
    See also
    terminate, Statistic
template<typename TQuantity>
Quantity DGtal::Statistic< TQuantity >::min ( ) const
Returns
the minimal value.
template<typename TQuantity>
bool DGtal::Statistic< TQuantity >::OK ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.
template<typename TQuantity>
Statistic DGtal::Statistic< TQuantity >::operator+ ( const Statistic< TQuantity > &  other) const

Adds two set of statistics (should be of the same variable).

Parameters
otherthe object to add.
Returns
a new object that is the union of these statistics.
template<typename TQuantity>
Statistic& DGtal::Statistic< TQuantity >::operator+= ( const Statistic< TQuantity > &  other)

Adds to self another set of statistics (should be of the same variable).

Parameters
otherthe object to add.
Returns
a reference on 'this'.
template<typename TQuantity>
Statistic& DGtal::Statistic< TQuantity >::operator= ( const Statistic< TQuantity > &  other)

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'.
template<typename TQuantity>
unsigned int DGtal::Statistic< TQuantity >::samples ( ) const
Returns
the number of samples.
template<typename TQuantity>
void DGtal::Statistic< TQuantity >::selfDisplay ( std::ostream &  that_stream) const

Writes/Displays the object on an output stream.

Parameters
that_streamthe output stream where the object is written.
template<typename TQuantity>
void DGtal::Statistic< TQuantity >::terminate ( )

Computes the median value of the statistics and switch to mode which does not save the statistics samples (myStoreSamples = false). Usefull only if the values are stored (specified in the the constructor) else it doest nothing.

See also
median, Statistic, myStoreSamples

Referenced by DGtal::CompareLocalEstimators< TFirstEsimator, TSecondEstimator >::compare(), and DGtal::CompareLocalEstimators< TFirstEsimator, TSecondEstimator >::compareVectors().

template<typename TQuantity>
double DGtal::Statistic< TQuantity >::unbiasedVariance ( ) const
Returns
the unbiased sample variance (given as double).
template<typename TQuantity>
double DGtal::Statistic< TQuantity >::variance ( ) const
Returns
the sample variance (given as double).

Field Documentation

template<typename TQuantity>
Quantity DGtal::Statistic< TQuantity >::myExp
private

stores the sum of sample values for computing sample mean.

Definition at line 251 of file Statistic.h.

template<typename TQuantity>
Quantity DGtal::Statistic< TQuantity >::myExp2
private

stores the sum of squared sample values for computing sample variance.

Definition at line 257 of file Statistic.h.

template<typename TQuantity>
bool DGtal::Statistic< TQuantity >::myIsTerminated
private

Tells if terminate was called. Usefull to return median value even if the m_values are no more stored (possible after serialisation which doest store the values.).

Definition at line 295 of file Statistic.h.

template<typename TQuantity>
Quantity DGtal::Statistic< TQuantity >::myMax
private

stores the maximal sample value.

Definition at line 262 of file Statistic.h.

template<typename TQuantity>
Quantity DGtal::Statistic< TQuantity >::myMedian
private

stores the median sample value.

Definition at line 273 of file Statistic.h.

template<typename TQuantity>
Quantity DGtal::Statistic< TQuantity >::myMin
private

stores the minimal sample value.

Definition at line 267 of file Statistic.h.

template<typename TQuantity>
unsigned int DGtal::Statistic< TQuantity >::mySamples
private

number of samples

Definition at line 246 of file Statistic.h.

template<typename TQuantity>
bool DGtal::Statistic< TQuantity >::myStoreSamples
private

Tells if values must be stored or not.

Definition at line 286 of file Statistic.h.

template<typename TQuantity>
Container DGtal::Statistic< TQuantity >::myValues
private

stores the sample to determine the median value

Definition at line 280 of file Statistic.h.


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