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>
|
| ~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 |
|
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.
◆ ~MultiStatistics()
DGtal::MultiStatistics::~MultiStatistics |
( |
| ) |
|
◆ MultiStatistics() [1/3]
DGtal::MultiStatistics::MultiStatistics |
( |
const unsigned int |
size, |
|
|
const bool |
storeSamples = false |
|
) |
| |
Creates an object for computing [size] statistics.
- Parameters
-
[in] | size | the number of statistical variables. |
[in] | storeSamples | when '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]
Copy constructor.
- Parameters
-
other | the object to clone. Forbidden by default. |
◆ addValue()
void DGtal::MultiStatistics::addValue |
( |
unsigned int |
k, |
|
|
double |
v |
|
) |
| |
Adds a new sample value [v] for the variable [k].
- Parameters
-
[in] | k | the statistical variable. |
[in] | v | the 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;
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] | k | the statistical variable. |
[in] | b | an iterator on the starting point. |
[in] | e | an 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] | x | the index of the statistics to be used as the x-variable (should be valid) |
[in] | y | the index of the statistics to be used as the y-variable (should be valid) |
[in] | s | the starting value index (default is 0 ) |
[in] | e | the 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] | size | the number of statistical variables. |
[in] | storeSamples | when '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] | x | the index of the x-variable (should be valid ) |
[in] | y | the 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] | k | the 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] | k | the 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] | k | the 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] | k | the 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] | k | the 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] | k | the 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=()
Assignment.
- Parameters
-
- 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] | indices | specifies in which columns data are read. |
◆ samples()
unsigned int DGtal::MultiStatistics::samples |
( |
const unsigned int |
k | ) |
const |
|
inline |
- Parameters
-
[in] | k | the 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] | out | the output stream where the object is written. |
◆ terminate()
void DGtal::MultiStatistics::terminate |
( |
| ) |
|
◆ unbiasedVariance()
double DGtal::MultiStatistics::unbiasedVariance |
( |
const unsigned int |
k | ) |
const |
|
inline |
- Parameters
-
k | the 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] | k | the statistical variable. |
[in] | i | the 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] | k | the statistical variable. |
- Returns
- the sample variance for this variable.
- Precondition
- method 'terminate' must have been called.
- See also
- terminate
◆ 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 |
◆ 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 |
◆ mySamples
unsigned int* DGtal::MultiStatistics::mySamples |
|
private |
◆ myStoreSamples
bool DGtal::MultiStatistics::myStoreSamples |
|
private |
◆ 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 |
The documentation for this class was generated from the following file: