CovMatrix.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef COVMATRIX_HPP
00012 #define COVMATRIX_HPP
00013
00014 using namespace cv;
00015 using namespace std;
00016
00027 class CovMatrix
00028 {
00029
00030 public:
00032 enum cov_type {COV_FULL,
00033 COV_DIAG,
00034 COV_IID
00035 };
00036
00038 enum cov_reg_type {COV_REG_NONE,
00039 COV_REG_MIN,
00040 COV_REG_ADD
00041 };
00042
00043 int n;
00044 Mat mtx;
00049 cov_type covopt;
00050 cov_reg_type regopt;
00051 double regval;
00058 CovMatrix(int n, cov_type covopt);
00059 CovMatrix(){sqrtmtx=NULL;}
00060 ~CovMatrix();
00061
00068 void calculate(const Mat &data, bool use_unbiased = true, bool assume_zero_mean = true);
00069
00078 void set(const Mat &M);
00079
00085 void setRegularizer(cov_reg_type regopt, double regval);
00086
00090 void regularize();
00091
00095 void toFullMatrix(Mat& fmtx) const;
00096
00100 Mat toFullMatrix() const;
00101
00102
00103
00104
00109 CovMatrix inv() const;
00110
00116 void premultiply(const Mat &src, Mat &dst) const;
00117
00123 void postmultiply(const Mat &src, Mat &dst) const;
00124
00125
00130 void randvec(Mat &X, RNG &rng);
00131
00132
00133
00135 static const char* cov_type_to_string(cov_type);
00136
00138 static const char* cov_reg_type_to_string(cov_reg_type);
00139
00141 friend ostream& operator <<(ostream &output, const CovMatrix &cov);
00142
00143 private:
00145 Mat *sqrtmtx;
00146 public:
00147 char* writeToMemory(char *);
00148 char* readFromMemory(char *);
00149 };
00150
00151 #endif