DGtal 1.3.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes
DGtal::Statistic< TQuantity > Class Template Reference

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

#include <DGtal/math/Statistic.h>

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
 
unsigned int size () const
 
double mean () const
 
double variance () const
 
double unbiasedVariance () const
 
Quantity max () const
 
Quantity min () const
 
Quantity median ()
 
Quantity operator[] (unsigned int i) const
 
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. [74]

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

Definition at line 69 of file Statistic.h.

Member Typedef Documentation

◆ ConstIterator

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

Definition at line 77 of file Statistic.h.

◆ Container

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

Definition at line 76 of file Statistic.h.

◆ Quantity

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

Definition at line 74 of file Statistic.h.

Constructor & Destructor Documentation

◆ ~Statistic()

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

Destructor.

◆ Statistic() [1/2]

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

Constructor.

◆ Statistic() [2/2]

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

Copy constructor.

Parameters
otherthe object to clone.

Member Function Documentation

◆ addValue()

template<typename TQuantity >
void DGtal::Statistic< TQuantity >::addValue ( Quantity  v)

◆ addValues()

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 );
Aim: This class processes a set of sample values for one variable and can then compute different stat...
Definition: Statistic.h:70
void addValue(Quantity v)
Parameters
ban iterator on the starting point.
ean iterator after the last point.

Referenced by DGtal::ShortcutsGeometry< TKSpace >::getStatistic().

◆ begin()

template<typename TQuantity >
ConstIterator DGtal::Statistic< TQuantity >::begin ( ) const
Returns
an iterator on the first stored value (if storeSample was set).

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

◆ BOOST_CONCEPT_ASSERT()

template<typename TQuantity >
DGtal::Statistic< TQuantity >::BOOST_CONCEPT_ASSERT ( (concepts::CCommutativeRing< Quantity >)  )

◆ clear()

template<typename TQuantity >
void DGtal::Statistic< TQuantity >::clear ( )

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

◆ end()

template<typename TQuantity >
ConstIterator DGtal::Statistic< TQuantity >::end ( ) const
Returns
an iterator after the last stored value (if storeSample was set).

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

◆ max()

template<typename TQuantity >
Quantity DGtal::Statistic< TQuantity >::max ( ) const
Returns
the maximal value.

Referenced by testStatistics(), and testStatisticsSaving().

◆ mean()

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

Referenced by main(), testStatistics(), and testStatisticsSaving().

◆ median()

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

Referenced by testStatisticsSaving().

◆ min()

template<typename TQuantity >
Quantity DGtal::Statistic< TQuantity >::min ( ) const
Returns
the minimal value.

Referenced by testStatistics(), and testStatisticsSaving().

◆ OK()

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.

◆ operator+()

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.

◆ operator+=()

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

◆ operator=()

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

Assignment.

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

◆ operator[]()

template<typename TQuantity >
Quantity DGtal::Statistic< TQuantity >::operator[] ( unsigned int  i) const
Parameters
[in]ia valid index
Returns
the corresponding value (if stored).

◆ samples()

template<typename TQuantity >
unsigned int DGtal::Statistic< TQuantity >::samples ( ) const
Returns
the number of samples.

Referenced by main().

◆ selfDisplay()

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.

◆ size()

template<typename TQuantity >
unsigned int DGtal::Statistic< TQuantity >::size ( ) const
Returns
the number of samples.

◆ terminate()

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(), DGtal::CompareLocalEstimators< TFirstEsimator, TSecondEstimator >::compareVectors(), DGtal::ShortcutsGeometry< TKSpace >::getStatistic(), main(), testHistogramGaussian(), testHistogramGaussian2(), testHistogramUniform(), testStatistics(), and testStatisticsSaving().

◆ unbiasedVariance()

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

◆ variance()

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

Referenced by main(), testStatistics(), and testStatisticsSaving().

Field Documentation

◆ myExp

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

stores the sum of sample values for computing sample mean.

Definition at line 258 of file Statistic.h.

◆ myExp2

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

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

Definition at line 264 of file Statistic.h.

◆ myIsTerminated

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 302 of file Statistic.h.

◆ myMax

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

stores the maximal sample value.

Definition at line 269 of file Statistic.h.

◆ myMedian

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

stores the median sample value.

Definition at line 280 of file Statistic.h.

◆ myMin

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

stores the minimal sample value.

Definition at line 274 of file Statistic.h.

◆ mySamples

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

number of samples

Definition at line 253 of file Statistic.h.

◆ myStoreSamples

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

Tells if values must be stored or not.

Definition at line 293 of file Statistic.h.

◆ myValues

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

stores the sample to determine the median value

Definition at line 287 of file Statistic.h.


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