last update 20 Sep 2009 |
#include <cvrSecondOrderStatistics.h>
Classes | |
class | parameters |
the parameters for the class secondOrderStatistics More... | |
Public Types | |
enum | eVarianceType { Empirical = 0, Maxlikely = 1 } |
Public Member Functions | |
secondOrderStatistics (eDataRepresentationType dataRep=Rows) | |
secondOrderStatistics (const secondOrderStatistics &other) | |
secondOrderStatistics (const parameters ¶m) | |
virtual | ~secondOrderStatistics () |
secondOrderStatistics & | copy (const secondOrderStatistics &other) |
secondOrderStatistics & | operator= (const secondOrderStatistics &other) |
const std::string & | name () const |
virtual secondOrderStatistics * | clone () const |
virtual secondOrderStatistics * | newInstance () const |
const parameters & | getParameters () const |
bool | apply (const vector< T > &src, U &mean, U &variance) const |
bool | apply (const matrix< T > &src, U &mean, U &variance) const |
bool | apply (const matrix< T > &src, vector< U > &mean, vector< U > &variance) const |
bool | apply (const matrix< T > &src, vector< U > &mean, matrix< U > &cov) const |
bool | mean (const vector< T > &src, U &mean) const |
bool | mean (const matrix< T > &src, vector< U > &mean, eDataRepresentationType dataRep=Rows) const |
bool | variance (const vector< T > &src, U &variance) const |
bool | variance (const matrix< T > &src, vector< U > &variance, eDataRepresentationType dataRep=Rows) const |
bool | covarianceMatrix (const matrix< T > &src, matrix< U > &covMat, eDataRepresentationType dataRep=Rows) const |
Protected Member Functions | |
bool | applyRows (const matrix< T > &src, vector< U > &mu, vector< U > &var) const |
bool | applyColumns (const matrix< T > &src, vector< U > &mu, vector< U > &var) const |
bool | applyRows (const matrix< T > &src, vector< U > &mu, matrix< U > &cov) const |
bool | applyColumns (const matrix< T > &src, vector< U > &mu, matrix< U > &cov) const |
void | covar2corrcoef (matrix< U > &cv) const |
Correlations can be obtained as well.
The first template parameter (T) represents the type of the input data, and the second (U) the type of the output data, which defaults to T if not specified. The user should ensure that the result values fit into U, that is, T*T should be assignable to a U without loss of precision.
The following example clarifies the usage of eDataRepresentationType. Given the data matrix
| 5 6 10 2 | | 1 -2 4 4 | | 3 2 1 -3 |
With the default parameters (Rows, Empirical, no correlation) calling variance() yields (4 8 21 13). Switching to Maxlikely yields (2.667 5.333 14 8.667).
When the data samples are set to be in Columns the empirical variance is (8.667 4.667 2)^T. The Maxlikely variance is (6.5 3.5 1.5)^T.
To obtain a correlation matrix instead of a covariance matrix set parameters::useCorrelation to true.
Besides the mandatory apply-methods, this functor also offers a number of shortcuts to calculate only first or second order statistics. However, if both are needed it is always faster to call an apply() method that serves your purpose.
enum cvr::secondOrderStatistics::eVarianceType |
cvr::secondOrderStatistics< T, U >::secondOrderStatistics | ( | eDataRepresentationType | dataRep = Rows |
) |
Default constructor.
cvr::secondOrderStatistics< T, U >::secondOrderStatistics | ( | const secondOrderStatistics< T, U > & | other | ) |
cvr::secondOrderStatistics< T, U >::secondOrderStatistics | ( | const parameters & | param | ) |
virtual cvr::secondOrderStatistics< T, U >::~secondOrderStatistics | ( | ) | [virtual] |
Destructor.
bool cvr::secondOrderStatistics< T, U >::apply | ( | const matrix< T > & | src, | |
vector< U > & | mean, | |||
matrix< U > & | cov | |||
) | const |
Computes the mean vector and the covariance matrix for the data samples given in src.
The representation of data sample (point) as Rows or Columns of src can be chosen via parameters::dataRepresentationType but is usually the default: Rows.
In this case each dimension of mean corresponds to the mean value of the corresponding column of src. The covMatrix has dimension src.columns() x src.columns().
Depending on the value of parameters::varianceType the Empirical of Maxlikely variances are calculated.
If parameters::useCorrelation is true the correlation coefficients are calculated instead of the covariances.
src | matrix<T> with the source data. | |
mean | mean vector of src rows or columns | |
cov | covariance matrix |
bool cvr::secondOrderStatistics< T, U >::apply | ( | const matrix< T > & | src, | |
vector< U > & | mean, | |||
vector< U > & | variance | |||
) | const |
Computes the mean vector and each dimension's variance for the data samples given in src.
The representation of data sample (point) as Rows or Columns of src can be chosen via parameters::dataRepresentationType but is usually the default: Rows.
In this case each dimension of mean and variance corresponds to the mean value and variance of the corresponding column of src.
Depending on the value of parameters::varianceType the Empirical of Maxlikely variances are calculated.
src | matrix<T> with the source data. | |
mean | mean vector of src rows or columns | |
variance | variances of each sample dimension |
bool cvr::secondOrderStatistics< T, U >::apply | ( | const matrix< T > & | src, | |
U & | mean, | |||
U & | variance | |||
) | const |
Computes the mean and variance of the elements in the given matrix.
src | matrix<T> with the source data. | |
mean | mean value of src elements | |
variance | variance of the elements of src |
bool cvr::secondOrderStatistics< T, U >::apply | ( | const vector< T > & | src, | |
U & | mean, | |||
U & | variance | |||
) | const |
Computes the mean and variance of the given vector.
src | vector<T> with the source data. | |
mean | mean value of src elements | |
variance | variance of the elements of src |
bool cvr::secondOrderStatistics< T, U >::applyColumns | ( | const matrix< T > & | src, | |
vector< U > & | mu, | |||
matrix< U > & | cov | |||
) | const [protected] |
bool cvr::secondOrderStatistics< T, U >::applyColumns | ( | const matrix< T > & | src, | |
vector< U > & | mu, | |||
vector< U > & | var | |||
) | const [protected] |
bool cvr::secondOrderStatistics< T, U >::applyRows | ( | const matrix< T > & | src, | |
vector< U > & | mu, | |||
matrix< U > & | cov | |||
) | const [protected] |
bool cvr::secondOrderStatistics< T, U >::applyRows | ( | const matrix< T > & | src, | |
vector< U > & | mu, | |||
vector< U > & | var | |||
) | const [protected] |
virtual secondOrderStatistics* cvr::secondOrderStatistics< T, U >::clone | ( | ) | const [virtual] |
secondOrderStatistics& cvr::secondOrderStatistics< T, U >::copy | ( | const secondOrderStatistics< T, U > & | other | ) |
void cvr::secondOrderStatistics< T, U >::covar2corrcoef | ( | matrix< U > & | cv | ) | const [protected] |
bool cvr::secondOrderStatistics< T, U >::covarianceMatrix | ( | const matrix< T > & | src, | |
matrix< U > & | covMat, | |||
eDataRepresentationType | dataRep = Rows | |||
) | const |
Computes only the covariance matrix covMat of the given src data.
Do not use this function if you also need the mean vector, as the combined calculation via apply() is much faster.
Data samples in src can either be in Rows (default) or Columns. This can be set in dataRep. Other parameters are used as set in this functor's parameters (see apply()).
src | the source data. | |
covMat | covariance matrix of src | |
dataRep | data representation, Rows or Columns |
const parameters& cvr::secondOrderStatistics< T, U >::getParameters | ( | ) | const |
bool cvr::secondOrderStatistics< T, U >::mean | ( | const matrix< T > & | src, | |
vector< U > & | mean, | |||
eDataRepresentationType | dataRep = Rows | |||
) | const |
Computes only the mean vector of the given src data.
Do not use this function if you also need the variances, as the combined calculation via apply() is much faster.
Data samples in src can either be in Rows (default) or Columns. This can be set in dataRep.
src | the source data. | |
mean | mean vector of src | |
dataRep | data representation, Rows or Columns |
bool cvr::secondOrderStatistics< T, U >::mean | ( | const vector< T > & | src, | |
U & | mean | |||
) | const |
Computes only the mean value of the given src vector.
Do not use this function if you also need the variances, as the combined calculation via apply() is much faster.
src | vector<T> with the source data. | |
mean | mean value of src elements |
const std::string& cvr::secondOrderStatistics< T, U >::name | ( | ) | const [virtual] |
virtual secondOrderStatistics* cvr::secondOrderStatistics< T, U >::newInstance | ( | ) | const [virtual] |
secondOrderStatistics& cvr::secondOrderStatistics< T, U >::operator= | ( | const secondOrderStatistics< T, U > & | other | ) |
bool cvr::secondOrderStatistics< T, U >::variance | ( | const matrix< T > & | src, | |
vector< U > & | variance, | |||
eDataRepresentationType | dataRep = Rows | |||
) | const |
Computes only the variance vector of the given src data.
Do not use this function if you also need the mean vector, as the combined calculation via apply() is much faster.
Data samples in src can either be in Rows (default) or Columns. This can be set in dataRep. Other parameters are used as set in this functor's parameters (see apply()).
src | the source data. | |
variance | variance of each dimension of src | |
dataRep | data representation, Rows or Columns |
bool cvr::secondOrderStatistics< T, U >::variance | ( | const vector< T > & | src, | |
U & | variance | |||
) | const |
Computes only the variance of the given src vector.
Do not use this function if you also need the mean value, as the combined calculation via apply() is much faster.
src | vector<T> with the source data. | |
variance | variance of the elements of src |