Covariance matrix class. More...
#include <CovMatrix.hpp>
Public Types | |
| enum | cov_type { COV_FULL, COV_DIAG, COV_IID } |
type of covariance matrix. More... | |
| enum | cov_reg_type { COV_REG_NONE, COV_REG_MIN, COV_REG_ADD } |
regularization method. More... | |
Public Member Functions | |
| CovMatrix (int n, cov_type covopt) | |
| allocate a new covariance matrix. | |
| void | calculate (const Mat &data, bool use_unbiased=true, bool assume_zero_mean=true) |
| calculate the covariance of a data matrix, and save it into this CovMatrix instance. | |
| void | set (const Mat &M) |
| copy a Mat into a CovMatrix. | |
| void | setRegularizer (cov_reg_type regopt, double regval) |
| set the regularization method to be used. | |
| void | regularize () |
| apply regularization. | |
| void | toFullMatrix (Mat &fmtx) const |
| convert a CovMatrix to a full matrix, and store in a destination Mat. | |
| Mat | toFullMatrix () const |
| convert a CovMatrix to a full matrix, and return it. | |
| CovMatrix | inv () const |
| calculate the inverse, and return it. | |
| void | premultiply (const Mat &src, Mat &dst) const |
| premultiply the CovMatrix. | |
| void | postmultiply (const Mat &src, Mat &dst) const |
| postmultiply the CovMatrix. | |
| void | randvec (Mat &X, RNG &rng) |
| generate a random vector(s) according to the covariance matrix. | |
| char * | writeToMemory (char *) |
| char * | readFromMemory (char *) |
Static Public Member Functions | |
| static const char * | cov_type_to_string (cov_type) |
| debugging: convert cov_type to a string. | |
| static const char * | cov_reg_type_to_string (cov_reg_type) |
| debugging: convert cov_reg_type to a string. | |
Public Attributes | |
| int | n |
| dimension of the (square) covariance matrix. | |
| Mat | mtx |
| storage for the covariance matrix. | |
| cov_type | covopt |
| type of covariance matrix | |
| cov_reg_type | regopt |
| type of regularization to be used | |
| double | regval |
| regularization value | |
Private Attributes | |
| Mat * | sqrtmtx |
| cache the matrix square-root of the covariance matrix. | |
Friends | |
| ostream & | operator<< (ostream &output, const CovMatrix &cov) |
| print CovMatrix to output stream. | |
Covariance matrix class.
Class for creating different types of covariance matrices, such as full, diagonal, and iid covariance matrices. Also provides utility functions for: 1) calculating covariances; 2) applying regularization; 3) multiplying and inverting covariance matrices; 4) sampling random vectors. In general, the class will automatically handle the various types of covariances internally.
Definition at line 27 of file CovMatrix.hpp.
regularization method.
| COV_REG_NONE |
no regularization |
| COV_REG_MIN |
enforce a minimum eigenvalue of regval |
| COV_REG_ADD |
add a constant regval to the diagonal |
Definition at line 38 of file CovMatrix.hpp.
| enum CovMatrix::cov_type |
type of covariance matrix.
| COV_FULL |
Full covariance matrix. |
| COV_DIAG |
diagonal covariance matrix. |
| COV_IID |
iid covariance matrix. |
Definition at line 32 of file CovMatrix.hpp.
| CovMatrix::CovMatrix | ( | int | n, | |
| cov_type | covopt | |||
| ) |
allocate a new covariance matrix.
| n | dimension of the matrix | |
| covopt | the covariance type |
Definition at line 24 of file CovMatrix.cpp.
| void CovMatrix::calculate | ( | const Mat & | data, | |
| bool | use_unbiased = true, |
|||
| bool | assume_zero_mean = true | |||
| ) |
calculate the covariance of a data matrix, and save it into this CovMatrix instance.
| data | data matrix, each column is a data vector. | |
| use_unbiased | if true, use unbiased estimator (divide by N-1). otherwise, use standard estimator (divide by N). | |
| assume_zero_mean | if true, assume data vectors have zero mean. [non-zero is currently not supported]. |
Definition at line 50 of file CovMatrix.cpp.
| const char * CovMatrix::cov_reg_type_to_string | ( | cov_reg_type | opt | ) | [static] |
debugging: convert cov_reg_type to a string.
Definition at line 363 of file CovMatrix.cpp.
| const char * CovMatrix::cov_type_to_string | ( | cov_type | opt | ) | [static] |
debugging: convert cov_type to a string.
Definition at line 352 of file CovMatrix.cpp.
| CovMatrix CovMatrix::inv | ( | ) | const |
calculate the inverse, and return it.
Definition at line 288 of file CovMatrix.cpp.
| void CovMatrix::postmultiply | ( | const Mat & | src, | |
| Mat & | dst | |||
| ) | const |
postmultiply the CovMatrix.
| src | source matrix | |
| dst | destination matrix: dst = cov*src |
Definition at line 330 of file CovMatrix.cpp.
| void CovMatrix::premultiply | ( | const Mat & | src, | |
| Mat & | dst | |||
| ) | const |
premultiply the CovMatrix.
| src | source matrix | |
| dst | destination matrix: dst = cov*src |
Definition at line 308 of file CovMatrix.cpp.
| void CovMatrix::randvec | ( | Mat & | X, | |
| RNG & | rng | |||
| ) |
generate a random vector(s) according to the covariance matrix.
| X | destination Mat, an [n x R] matrix, where R is the number of samples desired. | |
| rng | the random number generator to use. |
Definition at line 242 of file CovMatrix.cpp.
| void CovMatrix::regularize | ( | ) |
apply regularization.
Definition at line 115 of file CovMatrix.cpp.
| void CovMatrix::set | ( | const Mat & | M | ) |
copy a Mat into a CovMatrix.
if M is [n x n]: 1) if full covariance, copies the whole matrix; 2) if diagonal covariance, copies just the diagonal; 3) if iid covariance, copies the mean of the diagonal. Currently only supports these cases.
| M | matrix |
Definition at line 204 of file CovMatrix.cpp.
| void CovMatrix::setRegularizer | ( | cov_reg_type | regopt, | |
| double | regval | |||
| ) |
set the regularization method to be used.
| regopt | the regularization method | |
| regval | the regularization constant |
Definition at line 99 of file CovMatrix.cpp.
| Mat CovMatrix::toFullMatrix | ( | ) | const |
convert a CovMatrix to a full matrix, and return it.
Definition at line 197 of file CovMatrix.cpp.
| void CovMatrix::toFullMatrix | ( | Mat & | fmtx | ) | const |
convert a CovMatrix to a full matrix, and store in a destination Mat.
| fmtx | destination matrix |
Definition at line 179 of file CovMatrix.cpp.
| ostream& operator<< | ( | ostream & | output, | |
| const CovMatrix & | cov | |||
| ) | [friend] |
print CovMatrix to output stream.
| Mat CovMatrix::mtx |
storage for the covariance matrix.
full matrix is [n x n]; diagonal matrix is [n x 1]; iid matrix is [1 x 1].
Definition at line 44 of file CovMatrix.hpp.
| int CovMatrix::n |
dimension of the (square) covariance matrix.
Definition at line 43 of file CovMatrix.hpp.
Mat* CovMatrix::sqrtmtx [private] |
cache the matrix square-root of the covariance matrix.
Definition at line 145 of file CovMatrix.hpp.
1.6.1