⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix.h

📁 一个bp的VC源码
💻 H
字号:
// 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 ----> 矩阵的子矩阵返回的结果
	//		[in]	nStartX ----> 子矩阵在矩阵中的起始坐标,对应行,索引从1开始
	//		[in]	nStartY ----> 子矩阵在矩阵中的起始坐标,对应列,索引从1开始
	//
	void CopySubMatrix(CMatrix& cMatrix,unsigned int nStartX,unsigned int nStartY);
	
	/////////////////////////////////////////////////////////////////////////
	// Copy Matrix
	//	Parameter:
	//		[in]	cMatrix ----> be copied matrix
	//
	void CopyMatrix(CMatrix& cMatrix);
	
	
	/////////////////////////////////////////////////////////////////////////
	// 对矩阵中所有的元素进行一次非线性变换:
	//		变换后的值y与变换前的值的关系是:
	//			y = f(x) = 1 / (1 + exp(-x))	( 0 < f(x) < 1)
	//
	CMatrix Sigmoid();
	
	
	/////////////////////////////////////////////////////////////////////////
	// Get System Error
	//
	double	GetSystemError() const;
	
	/////////////////////////////////////////////////////////////////////////
	// 对矩阵进行拓展
	//	实现功能:
	//		对矩阵的列数进行拓展,nTimes是每列拓展的次数
	//
	void nncpyi(CMatrix &cMatrix, unsigned int nTimes);
	

	
private:
	
	unsigned int m_nRow;			// 矩阵所拥有的行数
	unsigned int m_nCol;			// 矩阵所拥有的列数
	
	
	/////////////////////////////////////////////////////////////////////////
	// 注意:
	//		在重新设置矩阵的行数和列数后,矩阵中的元素被重新初始化为0
	/////////////////////////////////////////////////////////////////////////
	
	/////////////////////////////////////////////////////////////////////////
	// 设置矩阵的行数
	//
	void SetMatrixRowNumber(unsigned int nRow);
	
	/////////////////////////////////////////////////////////////////////////
	// 设置矩阵的列数
	//
	void SetMatrixColNumber(unsigned int nCol);
	
	/////////////////////////////////////////////////////////////////////////
	// 设置矩阵的行列数
	//
	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_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -