?? matrix.h
字號(hào):
// Matrix.h: interface for the CMatrix class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MATRIX_H__2557403D_9657_492A_9076_4EBB632AC786__INCLUDED_)
#define AFX_MATRIX_H__2557403D_9657_492A_9076_4EBB632AC786__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <vector>
using namespace std;
typedef vector <double> VDOUBLE;
typedef vector <VDOUBLE> TMatrix;
class CMatrix
{
public:
bool LoadNetworkData(CString& strFileName,
CMatrix& cMatrixInputToHideWeightValue,
CMatrix& cMatrixHideLayerValveValue,
CMatrix& cMatrixHideToOutputWeightValue,
CMatrix& cMatrixOutputLayerValveValue,
unsigned int &nInputLayerNumber,
unsigned int &nHideLayerNumber,
unsigned int &nOutputLayerNumber);
bool SaveDataToFile (CString& strFileName);
/////////////////////////////////////////////////////////////////////////
// Construction and Destruction
CMatrix();
CMatrix(CMatrix& cMatrixB);
virtual ~CMatrix();
TMatrix m_pTMatrix; // 指向矩陣的頭指針
/////////////////////////////////////////////////////////////////////////
// According to the parameters nRow & nCol to construct a matrix
CMatrix(unsigned int nRow, unsigned int nCol);
/////////////////////////////////////////////////////////////////////////
// This function initialize the matrix :
// the matrix which has been initialized has 0 row & 0 column, and
// all elements in it is zeros.
//
void InitializeZero();
/////////////////////////////////////////////////////////////////////////
// To make random in the elements of the matrix and the elements of the
// matrix has been randomized between -1 and 1.These elements must be
// decimal fractions.
//
void RandomInitialize();
/////////////////////////////////////////////////////////////////////////
// Overload Operations
// 'CMatrix + CMatrix'
CMatrix operator + (CMatrix& cMatrixB);
// 'CMatrix - CMatrix'
CMatrix operator - (CMatrix& cMatrixB);
// 'CMatrix * CMatrix'
CMatrix operator * (CMatrix& cMatrixB);
// 'CMatrix * double'
CMatrix operator * (double nValue);
// 'CMatrix = CMatrix'
CMatrix& operator = (CMatrix& cMatrixB);
// 'CMatrix += CMatrix'
CMatrix& operator += (CMatrix& cMatrixB);
// 'CMatrix .* CMatrix'
CMatrix operator / (CMatrix& cMatrixB);
/////////////////////////////////////////////////////////////////////////
// Transpose the matrix
//
CMatrix Transpose();
/////////////////////////////////////////////////////////////////////////
// Load the data from the file and reset the rows and the colums of the
// matrix
//
bool LoadDataFromFile(CString& strFileName);
/////////////////////////////////////////////////////////////////////////
// Get the matrix Row Number
//
unsigned int GetMatrixRowNumber() const
{
return m_nRow;
}
/////////////////////////////////////////////////////////////////////////
// Get the matrix Colum Number
//
unsigned int GetMatrixColNumber() const
{
return m_nCol;
}
/////////////////////////////////////////////////////////////////////////
// Copy data from sub matrix to another matrix
// Parameter:
// [out] cMatrix ----> 矩陣的子矩陣返回的結(jié)果
// [in] nStartX ----> 子矩陣在矩陣中的起始坐標(biāo),對(duì)應(yīng)行,索引從1開(kāi)始
// [in] nStartY ----> 子矩陣在矩陣中的起始坐標(biāo),對(duì)應(yīng)列,索引從1開(kāi)始
//
void CopySubMatrix(CMatrix& cMatrix,unsigned int nStartX,unsigned int nStartY);
/////////////////////////////////////////////////////////////////////////
// Copy Matrix
// Parameter:
// [in] cMatrix ----> be copied matrix
//
void CopyMatrix(CMatrix& cMatrix);
/////////////////////////////////////////////////////////////////////////
// 對(duì)矩陣中所有的元素進(jìn)行一次非線性變換:
// 變換后的值y與變換前的值的關(guān)系是:
// y = f(x) = 1 / (1 + exp(-x)) ( 0 < f(x) < 1)
//
CMatrix Sigmoid();
/////////////////////////////////////////////////////////////////////////
// Get System Error
//
double GetSystemError() const;
/////////////////////////////////////////////////////////////////////////
// 對(duì)矩陣進(jìn)行拓展
// 實(shí)現(xiàn)功能:
// 對(duì)矩陣的列數(shù)進(jìn)行拓展,nTimes是每列拓展的次數(shù)
//
void nncpyi(CMatrix &cMatrix, unsigned int nTimes);
private:
unsigned int m_nRow; // 矩陣所擁有的行數(shù)
unsigned int m_nCol; // 矩陣所擁有的列數(shù)
/////////////////////////////////////////////////////////////////////////
// 注意:
// 在重新設(shè)置矩陣的行數(shù)和列數(shù)后,矩陣中的元素被重新初始化為0
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// 設(shè)置矩陣的行數(shù)
//
void SetMatrixRowNumber(unsigned int nRow);
/////////////////////////////////////////////////////////////////////////
// 設(shè)置矩陣的列數(shù)
//
void SetMatrixColNumber(unsigned int nCol);
/////////////////////////////////////////////////////////////////////////
// 設(shè)置矩陣的行列數(shù)
//
void SetMatrixRowAndCol(unsigned int nRow,unsigned int nCol);
/////////////////////////////////////////////////////////////////////////
// 交換矩陣的兩行
//
void SwapMatrixRow(unsigned int nRow1,unsigned int nRow2);
/////////////////////////////////////////////////////////////////////////
// 交換矩陣的兩列
//
void SwapMatrixCol(unsigned int nCol1,unsigned int nCol2);
};
/////////////////////////////////////////////////////////////////////////////
#endif // !defined(AFX_MATRIX_H__2557403D_9657_492A_9076_4EBB632AC786__INCLUDED_)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -