DGtal  0.9.3beta
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
DGtal::MultiStatistics Class Reference

#include <DGtal/math/MultiStatistics.h>

Collaboration diagram for DGtal::MultiStatistics:
[legend]

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 67 of file MultiStatistics.h.

Constructor & Destructor Documentation

DGtal::MultiStatistics::~MultiStatistics ( )

Destructor.

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'
DGtal::MultiStatistics::MultiStatistics ( )
protected

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

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

Copy constructor.

Parameters
otherthe object to clone. Forbidden by default.

Member Function Documentation

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.
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 );
Parameters
[in]kthe statistical variable.
[in]ban iterator on the starting point.
[in]ean iterator after the last point.
void DGtal::MultiStatistics::clear ( )

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

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].
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
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
bool DGtal::MultiStatistics::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.
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 )
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
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
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
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.
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
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
unsigned int DGtal::MultiStatistics::nb ( ) const
inline
Returns
the number of statistical variables.
MultiStatistics& DGtal::MultiStatistics::operator= ( const MultiStatistics other)
private

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'. Forbidden by default.
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.
unsigned int DGtal::MultiStatistics::samples ( const unsigned int  k) const
inline
Parameters
[in]kthe statistical variable.
Returns
the number of samples for this variable.
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.
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
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
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
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

double* DGtal::MultiStatistics::myExp
private

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

Definition at line 355 of file MultiStatistics.h.

double* DGtal::MultiStatistics::myExp2
private

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

Definition at line 361 of file MultiStatistics.h.

unsigned int* DGtal::MultiStatistics::myIndiceMax
private

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

Definition at line 381 of file MultiStatistics.h.

unsigned int* DGtal::MultiStatistics::myIndiceMin
private

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

Definition at line 391 of file MultiStatistics.h.

bool DGtal::MultiStatistics::myIsTerminate
private

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

Definition at line 408 of file MultiStatistics.h.

double* DGtal::MultiStatistics::myMax
private

For each variable, stores the maximal sample value.

Definition at line 376 of file MultiStatistics.h.

double* DGtal::MultiStatistics::myMin
private

For each variable, stores the minimal sample value.

Definition at line 386 of file MultiStatistics.h.

unsigned int DGtal::MultiStatistics::myNb
private

Number of statistical variables.

Definition at line 344 of file MultiStatistics.h.

unsigned int* DGtal::MultiStatistics::mySamples
private

For each variable, number of samples

Definition at line 349 of file MultiStatistics.h.

bool DGtal::MultiStatistics::myStoreSamples
private

Tells if values must be stored or not.

Definition at line 396 of file MultiStatistics.h.

double* DGtal::MultiStatistics::myUnbiasedVar
private

For each variable, stores the unbiased sample variance.

Definition at line 371 of file MultiStatistics.h.

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

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

Definition at line 402 of file MultiStatistics.h.

double* DGtal::MultiStatistics::myVar
private

For each variable, stores the sample variance.

Definition at line 366 of file MultiStatistics.h.


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