📄 matrix.h
字号:
// Matrix1.h: interface for the CMatrix class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MATRIX1_H__35A217E3_A5E0_492C_B345_A1DE28E8658C__INCLUDED_)
#define AFX_MATRIX1_H__35A217E3_A5E0_492C_B345_A1DE28E8658C__INCLUDED_
//#include "BpNNet.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMatrix
{
public:
CMatrix(); // 基础构造函数
CMatrix(int nRows, int nCols); // 指定行列构造函数
CMatrix(int nRows, int nCols, double value[]); // 指定数据构造函数
CMatrix(int nSize); // 方阵构造函数
CMatrix(int nSize, double value[]); // 指定数据方阵构造函数
CMatrix(const CMatrix& other); // 拷贝构造函数
CMatrix GetMean(int mode,BOOL vec);
void SetCol(int nCol,double value[]);
void SetRow(int nRow,double value[]);
BOOL Init(int nRows, int nCols); // 初始化矩阵
BOOL MakeUnitMatrix(int nSize); // 将方阵初始化为单位矩阵
//
// 输入与显示
//
// 将字符串转换为矩阵数据
//BOOL FromString(CString s, const CString& sDelim = " ", BOOL bLineBreak = TRUE);
// 将矩阵转换为字符串
CString ToString(const CString& sDelim = " ", BOOL bLineBreak = TRUE) const;
// 将矩阵的指定行转换为字符串
CString RowToString(int nRow, const CString& sDelim = " ") const;
// 将矩阵的指定列转换为字符串
CString ColToString(int nCol, const CString& sDelim = " ") const;
//
// 元素与值操作
//
// 设置矩阵的值
void SetData(double value[]);
// 设置指定元素的值
BOOL SetElement(int nRow, int nCol, double value);
// 获取指定元素的值
double GetElement(int nRow, int nCol) const;
// 获取矩阵的列数
int GetNumColumns() const;
// 获取矩阵的行数
int GetNumRows() const;
// 获取矩阵的值
double * GetData() const;
// 获取矩阵的指定行矩阵
int GetRowVector(int nRow, double* pVector) const;
// 获取矩阵的指定列矩阵
int GetColVector(int nCol, double* pVector) const;
//
// 数学操作
//
CMatrix & operator=(const CMatrix& other);
BOOL operator==(const CMatrix& other) const;
BOOL operator!=(const CMatrix& other) const;
CMatrix operator+(const CMatrix& other) const;
CMatrix operator+(double value) const;
CMatrix operator^(double value) const;
CMatrix operator-(const CMatrix& other) const;
CMatrix operator*(double value) const;
CMatrix operator%(int value) const;
CMatrix operator/(double value) const;
CMatrix operator*(const CMatrix& other) const;
// 复矩阵乘法
CMul(const CMatrix& AR, const CMatrix& AI, const CMatrix& BR, const CMatrix& BI, CMatrix& CR, CMatrix& CI) const;
// 矩阵的转置
CMatrix Transpose() const;
//
// 算法
//
// 实矩阵求逆的全选主元高斯-约当法
BOOL InvertGaussJordan();
// 复矩阵求逆的全选主元高斯-约当法
BOOL InvertGaussJordan(CMatrix& mtxImag);
// 对称正定矩阵的求逆
BOOL InvertSsgj();
// 托伯利兹矩阵求逆的埃兰特方法
BOOL InvertTrench();
// 求行列式值的全选主元高斯消去法
double DetGauss();
// 求矩阵秩的全选主元高斯消去法
int RankGauss();
// 对称正定矩阵的乔里斯基分解与行列式的求值
BOOL DetCholesky(double* dblDet);
// 矩阵的三角分解
BOOL SplitLU(CMatrix& mtxL, CMatrix& mtxU);
// 一般实矩阵的QR分解
BOOL SplitQR(CMatrix& mtxQ);
// 一般实矩阵的奇异值分解
BOOL SplitUV(CMatrix& mtxU, CMatrix& mtxV, double eps = 0.000001);
void ppp(double a[], double e[], double s[], double v[], int m, int n);
void sss(double fg[2], double cs[2]);
// 求广义逆的奇异值分解法
BOOL GInvertUV(CMatrix& mtxAP, CMatrix& mtxU, CMatrix& mtxV, double eps = 0.000001);
// 约化对称矩阵为对称三对角阵的豪斯荷尔德变换法
BOOL MakeSymTri(CMatrix& mtxQ, CMatrix& mtxT, double dblB[], double dblC[]);
// 实对称三对角阵的全部特征值与特征向量的计算
BOOL SymTriEigenv(double dblB[], double dblC[], CMatrix& mtxQ, int nMaxIt = 60, double eps = 0.000001);
// 约化一般实矩阵为赫申伯格矩阵的初等相似变换法
void MakeHberg();
// 求赫申伯格矩阵全部特征值的QR方法
BOOL HBergEigenv(double dblU[], double dblV[], int nMaxIt = 60, double eps = 0.000001);
// 求实对称矩阵特征值与特征向量的雅可比法
BOOL JacobiEigenv(double dblEigenValue[], CMatrix& mtxEigenVector, int nMaxIt = 100, double eps = 0.0000001);
// 求实对称矩阵特征值与特征向量的雅可比过关法
BOOL JacobiEigenv2(double dblEigenValue[], CMatrix& mtxEigenVector, double eps = 0.0000001);
virtual ~CMatrix();
public:
double CalcIntegralImage(LONG x,LONG y);
double CalcIntegralImageSquare(LONG x,LONG y);
CMatrix LessThan(double value);
CMatrix GraterOrEqual(double value);
void SetCols(CMatrix Tmp,LONG nCols1,LONG nCols2);
void SetRows(CMatrix Tmp,LONG nRows1,LONG nRows2);
CMatrix Ones(int mode,int nSize1,int nSize2=0);
CMatrix KronecherProd(CMatrix Y);
CMatrix Find(const char *Expr);
CMatrix GetCols(LONG nCols1,LONG nCols2);
CMatrix GetRows(LONG nRows1,LONG nRows2);
BOOL MakeDiag(int nSize,double *v);
void GenIdentity(int nRows,int nColumns);
CMatrix Dot(const CMatrix& other) const;
int m_nNumColumns; // 矩阵列数
int m_nNumRows; // 矩阵行数
double * m_pData; // 矩阵数据缓冲区
BOOL m_Abs;
public:
LONG GetNumFourRectFeature();
LONG GetNumThreeRectFeature();
LONG GetNumTwoRectFeature();
double CalcIntegralImageRect(LONG x,LONG y,LONG width,LONG height);
CMatrix CalcIntegralImageSquare();
CMatrix CalcIntegralImage();
CMatrix ChangeSize(LONG height,LONG width);
void SortEigen(double EigenValue[],CMatrix& EigenVector,int mode=0,int left=0, int right=0,BOOL Abs=FALSE);
private:
double CalcCumulativeSum(LONG x,LONG y);
double CalcCumulativeSumSquare(LONG x,LONG y);
void SortEigenVal(double EigenValue[],CMatrix& EigenVector,int mode=0,int left=0, int right=0);
};
#endif // !defined(AFX_MATRIX1_H__35A217E3_A5E0_492C_B345_A1DE28E8658C__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -