CovMatrix Class Reference

Covariance matrix class. More...

#include <CovMatrix.hpp>

List of all members.

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.

Detailed Description

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.


Member Enumeration Documentation

regularization method.

Enumerator:
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.

type of covariance matrix.

Enumerator:
COV_FULL 

Full covariance matrix.

COV_DIAG 

diagonal covariance matrix.

COV_IID 

iid covariance matrix.

Definition at line 32 of file CovMatrix.hpp.


Constructor & Destructor Documentation

CovMatrix::CovMatrix ( int  n,
cov_type  covopt 
)

allocate a new covariance matrix.

Parameters:
n dimension of the matrix
covopt the covariance type
See also:
calculate, set

Definition at line 24 of file CovMatrix.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

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.

Parameters:
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].
See also:
set

Definition at line 50 of file CovMatrix.cpp.

Here is the caller graph for this function:

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.

Here is the caller graph for this function:

CovMatrix CovMatrix::inv (  )  const

calculate the inverse, and return it.

Returns:
the inverse (CovMatrix)
See also:
premultiply, postmultiply

Definition at line 288 of file CovMatrix.cpp.

Here is the caller graph for this function:

void CovMatrix::postmultiply ( const Mat &  src,
Mat &  dst 
) const

postmultiply the CovMatrix.

Parameters:
src source matrix
dst destination matrix: dst = cov*src
See also:
premultiply, inv

Definition at line 330 of file CovMatrix.cpp.

Here is the caller graph for this function:

void CovMatrix::premultiply ( const Mat &  src,
Mat &  dst 
) const

premultiply the CovMatrix.

Parameters:
src source matrix
dst destination matrix: dst = cov*src
See also:
postmultiply, inv

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.

Parameters:
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.

Here is the caller graph for this function:

void CovMatrix::regularize (  ) 

apply regularization.

See also:
setRegularizer, cov_reg_type

Definition at line 115 of file CovMatrix.cpp.

Here is the caller graph for this function:

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.

Parameters:
M matrix
See also:
calculate

Definition at line 204 of file CovMatrix.cpp.

void CovMatrix::setRegularizer ( cov_reg_type  regopt,
double  regval 
)

set the regularization method to be used.

Parameters:
regopt the regularization method
regval the regularization constant
See also:
regularize, cov_reg_type

Definition at line 99 of file CovMatrix.cpp.

Here is the caller graph for this function:

Mat CovMatrix::toFullMatrix (  )  const

convert a CovMatrix to a full matrix, and return it.

Returns:
the Mat

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.

Parameters:
fmtx destination matrix

Definition at line 179 of file CovMatrix.cpp.

Here is the caller graph for this function:


Friends And Related Function Documentation

ostream& operator<< ( ostream &  output,
const CovMatrix &  cov 
) [friend]

print CovMatrix to output stream.


Member Data Documentation

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.

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.


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

Generated on 18 Dec 2014 for libdt-OpenCV by  doxygen 1.6.1