DGtal 1.4.0
Loading...
Searching...
No Matches
DGtal::MultiStatistics Class Reference

Aim: This class stores a set of sample values for several variables and can then compute different statistics, like sample mean, sample variance, sample unbiased variance, etc. More...

#include <DGtal/math/MultiStatistics.h>

Public Member Functions

 ~MultiStatistics ()
 
 MultiStatistics (const unsigned int size, const bool storeSamples=false)
 
unsigned int nb () const
 
unsigned int samples (const unsigned int k) const
 
double mean (const unsigned int k) const
 
double variance (const unsigned int k) const
 
double unbiasedVariance (const unsigned int k) const
 
double max (const unsigned int k) const
 
unsigned int maxIndice (unsigned int k) const
 
double min (const unsigned int k) const
 
unsigned int minIndice (const unsigned int k) const
 
double value (const unsigned int k, const unsigned int i) const
 
void addValue (unsigned int k, double v)
 
template<class Iter >
void addValues (const unsigned int k, Iter b, Iter e)
 
void terminate ()
 
void init (unsigned int size, bool storeSamples)
 
void clear ()
 
void erase ()
 
double covariance (const unsigned int x, const unsigned int y, const unsigned int s=0, unsigned int e=0) const
 
std::pair< double, double > linearRegression (const unsigned int x, const unsigned int y) const
 
double median (const unsigned int k)
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Static Public Member Functions

static void read (std::istream &in, MultiStatistics &samples, const std::vector< unsigned int > &indices)
 

Protected Member Functions

 MultiStatistics ()
 

Private Member Functions

 MultiStatistics (const MultiStatistics &other)
 
MultiStatisticsoperator= (const MultiStatistics &other)
 

Private Attributes

unsigned int myNb
 
unsigned int * mySamples
 
double * myExp
 
double * myExp2
 
double * myVar
 
double * myUnbiasedVar
 
double * myMax
 
unsigned int * myIndiceMax
 
double * myMin
 
unsigned int * myIndiceMin
 
bool myStoreSamples
 
std::vector< double > * myValues
 
bool myIsTerminate
 

Detailed Description

Aim: This class stores a set of sample values for several variables and can then compute different statistics, like sample mean, sample variance, sample unbiased variance, etc.

Description of class 'MultiStatistics'

Note
the method terminate() should be called before accessing to the quantities like mean, variance, etc.

The proposed implementation is mainly a backport from ImaGene with some various refactoring.

Definition at line 66 of file MultiStatistics.h.

Constructor & Destructor Documentation

◆ ~MultiStatistics()

DGtal::MultiStatistics::~MultiStatistics ( )

Destructor.

◆ MultiStatistics() [1/3]

DGtal::MultiStatistics::MultiStatistics ( const unsigned int size,
const bool storeSamples = false )

Creates an object for computing [size] statistics.

Parameters
[in]sizethe number of statistical variables.
[in]storeSampleswhen 'true', stores each given sample, default is 'false'

◆ MultiStatistics() [2/3]

DGtal::MultiStatistics::MultiStatistics ( )
protected

Constructor. Forbidden by default (protected to avoid g++ warnings).

◆ MultiStatistics() [3/3]

DGtal::MultiStatistics::MultiStatistics ( const MultiStatistics & other)
private

Copy constructor.

Parameters
otherthe object to clone. Forbidden by default.

Member Function Documentation

◆ addValue()

void DGtal::MultiStatistics::addValue ( unsigned int k,
double v )

Adds a new sample value [v] for the variable [k].

Parameters
[in]kthe statistical variable.
[in]vthe new sample value.

Referenced by TEST_CASE().

◆ addValues()

template<class Iter >
void DGtal::MultiStatistics::addValues ( const unsigned int k,
Iter b,
Iter e )

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

Exemple:

vector<double> x;
MultiStatistics stats( 1, true );
stats.addValue( x + 4, x + 10 );
Aim: This class stores a set of sample values for several variables and can then compute different st...
Parameters
[in]kthe statistical variable.
[in]ban iterator on the starting point.
[in]ean iterator after the last point.

Referenced by TEST_CASE().

◆ clear()

void DGtal::MultiStatistics::clear ( )

Clears the object from all given samples. The object still represents 'nb()' statistical variables.

◆ covariance()

double DGtal::MultiStatistics::covariance ( const unsigned int x,
const unsigned int y,
const unsigned int s = 0,
unsigned int e = 0 ) const

Computes the covariance of the [x],[y] variables. The 'MultiStatistics' object should have stored its values and 'terminate' should have been called.

Parameters
[in]xthe index of the statistics to be used as the x-variable (should be valid)
[in]ythe index of the statistics to be used as the y-variable (should be valid)
[in]sthe starting value index (default is 0 )
[in]ethe after-the-end value index (default is 0, meaning all )
Returns
the covariance of [x],[y] from indices [s] to [e].

◆ erase()

void DGtal::MultiStatistics::erase ( )

Erases the object as if it was just created. The user must call 'init()' before any other method.

See also
init

◆ init()

void DGtal::MultiStatistics::init ( unsigned int size,
bool storeSamples )

Reinitializes the object to contain [size] statistical variables. All preceding sample values and statistics are lost. Calls 'erase()'.

Parameters
[in]sizethe number of statistical variables.
[in]storeSampleswhen 'true', stores each given sample,
See also
erase

◆ isValid()

bool DGtal::MultiStatistics::isValid ( ) const

Checks the validity/consistency of the object.

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

◆ linearRegression()

std::pair< double, double > DGtal::MultiStatistics::linearRegression ( const unsigned int x,
const unsigned int y ) const

Computes the linear regression of the ([x],[y]) variables. The 'MultiStatistics' object should have stored its values and 'terminate' should have been called.

Parameters
[in]xthe index of the x-variable (should be valid )
[in]ythe index of the y-variable (should be valid )
Returns
the pair (slope, shift at origin )

◆ max()

double DGtal::MultiStatistics::max ( const unsigned int k) const
inline
Parameters
[in]kthe statistical variable.
Returns
the maximal value for this variable.
Precondition
method 'terminate' must have been called.
See also
terminate

Referenced by TEST_CASE().

◆ maxIndice()

unsigned int DGtal::MultiStatistics::maxIndice ( unsigned int k) const
inline
Parameters
[in]kthe statistical variable.
Returns
the indice of the maximal value for this variable.
Precondition
method 'terminate' must have been called.
See also
terminate

◆ mean()

double DGtal::MultiStatistics::mean ( const unsigned int k) const
inline
Parameters
[in]kthe statistical variable.
Returns
the sample mean for this variable.
Precondition
method 'terminate' must have been called.
See also
terminate

Referenced by TEST_CASE().

◆ median()

double DGtal::MultiStatistics::median ( const unsigned int k)

Computes the median value for a variable k. The 'MultiStatistics' object should have stored its values and 'terminate' should have been called.

Parameters
[in]kthe statistical variable.
Returns
the median value for the variable k.

Referenced by TEST_CASE().

◆ min()

double DGtal::MultiStatistics::min ( const unsigned int k) const
inline
Parameters
[in]kthe statistical variable.
Returns
the minimal value for this variable.
Precondition
method 'terminate' must have been called.
See also
terminate

Referenced by TEST_CASE().

◆ minIndice()

unsigned int DGtal::MultiStatistics::minIndice ( const unsigned int k) const
inline
Parameters
[in]kthe statistical variable.
Returns
the indice of the minimal value for this variable.
Precondition
method 'terminate' must have been called.
See also
terminate

◆ nb()

unsigned int DGtal::MultiStatistics::nb ( ) const
inline
Returns
the number of statistical variables.

◆ operator=()

MultiStatistics & DGtal::MultiStatistics::operator= ( const MultiStatistics & other)
private

Assignment.

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

◆ read()

static void DGtal::MultiStatistics::read ( std::istream & in,
MultiStatistics & samples,
const std::vector< unsigned int > & indices )
static

Reads the input stream [in] line by line, excluding line beginning with '#' and selects some columns according to [indices] to fill the array of samples [samples]. For instance, if indices == { 3, 4, 1 }, then samples( 0 ) will contain the third column, samples( 1 ), the fourth column and samples( 2 ) the first column.

Parameters
[out]in(modified) the input stream.
[out]samples(updates) stores the data.
[in]indicesspecifies in which columns data are read.

◆ samples()

unsigned int DGtal::MultiStatistics::samples ( const unsigned int k) const
inline
Parameters
[in]kthe statistical variable.
Returns
the number of samples for this variable.

◆ selfDisplay()

void DGtal::MultiStatistics::selfDisplay ( std::ostream & out) const

Writes/Displays the object on an output stream.

Parameters
[out]outthe output stream where the object is written.

◆ terminate()

void DGtal::MultiStatistics::terminate ( )

Once all sample values have been added to this object, computes meaningful statistics like sample mean, variance and unbiased variance.

See also
mean, variance, unbiasedVariance, min, max

Referenced by TEST_CASE().

◆ unbiasedVariance()

double DGtal::MultiStatistics::unbiasedVariance ( const unsigned int k) const
inline
Parameters
kthe statistical variable.
Returns
the unbiased sample variance for this variable.
Precondition
method 'terminate' must have been called.
See also
terminate

◆ value()

double DGtal::MultiStatistics::value ( const unsigned int k,
const unsigned int i ) const
inline

Returns a stored sample value that was added before. The object should have been initialized with 'store_samples = true'.

Parameters
[in]kthe statistical variable.
[in]ithe index of the sample value, '0<=i<samples(k)'.
Returns
the [i]-th value for this variable.
See also
MultiStatistics, init

◆ variance()

double DGtal::MultiStatistics::variance ( const unsigned int k) const
inline
Parameters
[in]kthe statistical variable.
Returns
the sample variance for this variable.
Precondition
method 'terminate' must have been called.
See also
terminate

Field Documentation

◆ myExp

double* DGtal::MultiStatistics::myExp
private

For each variable, stores the sum of sample values for computing sample mean.

Definition at line 354 of file MultiStatistics.h.

◆ myExp2

double* DGtal::MultiStatistics::myExp2
private

For each variable, stores the sum of squared sample values for computing sample variance.

Definition at line 360 of file MultiStatistics.h.

◆ myIndiceMax

unsigned int* DGtal::MultiStatistics::myIndiceMax
private

For each variable, stores the indice of the maximal sample value.

Definition at line 380 of file MultiStatistics.h.

◆ myIndiceMin

unsigned int* DGtal::MultiStatistics::myIndiceMin
private

For each variable, stores the indice of the minimal sample value.

Definition at line 390 of file MultiStatistics.h.

◆ myIsTerminate

bool DGtal::MultiStatistics::myIsTerminate
private

To prevent that terminate() is called before using statistics like mean, variance etc.

Definition at line 407 of file MultiStatistics.h.

◆ myMax

double* DGtal::MultiStatistics::myMax
private

For each variable, stores the maximal sample value.

Definition at line 375 of file MultiStatistics.h.

◆ myMin

double* DGtal::MultiStatistics::myMin
private

For each variable, stores the minimal sample value.

Definition at line 385 of file MultiStatistics.h.

◆ myNb

unsigned int DGtal::MultiStatistics::myNb
private

Number of statistical variables.

Definition at line 343 of file MultiStatistics.h.

◆ mySamples

unsigned int* DGtal::MultiStatistics::mySamples
private

For each variable, number of samples

Definition at line 348 of file MultiStatistics.h.

◆ myStoreSamples

bool DGtal::MultiStatistics::myStoreSamples
private

Tells if values must be stored or not.

Definition at line 395 of file MultiStatistics.h.

◆ myUnbiasedVar

double* DGtal::MultiStatistics::myUnbiasedVar
private

For each variable, stores the unbiased sample variance.

Definition at line 370 of file MultiStatistics.h.

◆ myValues

std::vector<double>* DGtal::MultiStatistics::myValues
private

For each variable, stores the sample values if [myStoreSamples] is 'true'.

Definition at line 401 of file MultiStatistics.h.

◆ myVar

double* DGtal::MultiStatistics::myVar
private

For each variable, stores the sample variance.

Definition at line 365 of file MultiStatistics.h.


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