stringresolution.h
来自「vc编程实现bp神经网络」· C头文件 代码 · 共 275 行
H
275 行
// StringResolution.h: interface for the CStringResolution class.
#include "my.h"//error process,otherwise no compile error,but no error information
#include "Matrix.h"
#if !defined(AFX_STRINGRESOLUTION_H__69522ED3_1E49_404E_8D5E_1261F7D732DD__INCLUDED_)
#define AFX_STRINGRESOLUTION_H__69522ED3_1E49_404E_8D5E_1261F7D732DD__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <stack>
//***************************************************************************zdh
/////////////////////////////////////////////////////////////////////////////
// Levenberg-Marquart ----> 第一次前向计算初始化 //
/////////////////////////////////////////////////////////////////////////////
__declspec (dllimport) void LMForwardCalculateInit( int nInputLayerNumber,
int nHideLayerNumber,
int nOutputLayerNumber,
CMatrix &matrixDemoDataInput,
CMatrix &matrixInputLayerValue,
CMatrix &matrixInputToHideWeightValue,
CMatrix &matrixHideLayerValveValue,
CMatrix &matrixHideToOutputWeightValue,
CMatrix &matrixOutputLayerValveValue
);
/////////////////////////////////////////////////////////////////////////////
// Levenberg-Marquart ----> 前向计算 //
/////////////////////////////////////////////////////////////////////////////
__declspec(dllimport) void LMForwardCalculate ( int nInputLayerNumber,
int nHideLayerNumber,
int nOutputLayerNumber,
bool bSimulateDataFlag,
int nComboFunc,
CMatrix &matrixDemoDataInput,
CMatrix &matrixInputLayerValue,
CMatrix &matrixInputToHideWeightValue,
CMatrix &matrixHideLayerValveValue,
CMatrix &matrixHideLayerOutput,
CMatrix &matrixHideToOutputWeightValue,
CMatrix &matrixOutputLayerOutput,
CMatrix &matrixOutputLayerValveValue
);
/////////////////////////////////////////////////////////////////////////////
// Levenberg-Marquart ----> 反馈计算 //
/////////////////////////////////////////////////////////////////////////////
__declspec(dllimport) bool LMDemoDataTrainRepeat ( int nInputLayerNumber,
int nHideLayerNumber,
int nOutputLayerNumber,
bool bSimulateDataFlag,
int nComboFunc,
double nSystemErrorOld,
double nSystemErrorNew,
double nSystemErrorLevel,
double nSystemError,
double nStep,
UINT nMaxTrainTimes,
UINT nTrainTimes,
DWORD ID_SYSTEM_ERROR,
DWORD ID_TRAIN_TIMES,
HWND hWnd,
CMatrix &matrixDemoDataInput,
CMatrix &matrixInputLayerValue,
CMatrix &matrixInputToHideWeightValue,
CMatrix &matrixHideLayerValveValue,
CMatrix &matrixHideLayerOutput,
CMatrix &matrixHideToOutputWeightValue,
CMatrix &matrixOutputLayerOutput,
CMatrix &matrixOutputLayerValveValue
);
/////////////////////////////////////////////////////////////////////////////
// Back propagation ----> 前向计算(Only for Training) //
/////////////////////////////////////////////////////////////////////////////
__declspec(dllexport) void BPForwardCalculate ( int nInputLayerNumber,
int nHideLayerNumber,
int nOutputLayerNumber,
bool bSimulateDataFlag,
int nComboFunc,
CMatrix &matrixDemoDataInput,
CMatrix &matrixInputLayerValue,
CMatrix &matrixInputToHideWeightValue,
CMatrix &matrixHideLayerValveValue,
CMatrix &matrixHideLayerOutput,
CMatrix &matrixHideToOutputWeightValue,
CMatrix &matrixOutputLayerOutput,
CMatrix &matrixOutputLayerValveValue,
CMatrix &cMatrixExHideLayerValveValue,
CMatrix &cMatrixExOutputLayerValveValue
);
/////////////////////////////////////////////////////////////////////////////
// Back propagation ----> 前向计算(Only for Simulating) //
/////////////////////////////////////////////////////////////////////////////
__declspec(dllimport) void BPForwardCalculate2( int nInputLayerNumber,
int nHideLayerNumber,
int nOutputLayerNumber,
bool bSimulateDataFlag,
int nComboFunc,
CMatrix &matrixDemoDataInput,
CMatrix &matrixInputLayerValue,
CMatrix &matrixInputToHideWeightValue,
CMatrix &matrixHideLayerValveValue,
CMatrix &matrixHideLayerOutput,
CMatrix &matrixHideToOutputWeightValue,
CMatrix &matrixOutputLayerOutput,
CMatrix &matrixOutputLayerValveValue
);
/////////////////////////////////////////////////////////////////////////////
// Back propagation ----> 反馈计算 //
/////////////////////////////////////////////////////////////////////////////
__declspec(dllimport) bool BPDemoDataTrainRepeat ( int nInputLayerNumber,
int nHideLayerNumber,
int nOutputLayerNumber,
bool bSimulateDataFlag,
int nComboFunc,
double nSystemErrorOld,
double nSystemErrorNew,
double nSystemErrorLevel,
double nSystemError,
double nStep,
UINT nMaxTrainTimes,
UINT nTrainTimes,
DWORD ID_SYSTEM_ERROR,
DWORD ID_TRAIN_TIMES,
HWND hWnd,
CMatrix &matrixDemoDataInput,
CMatrix &matrixInputLayerValue,
CMatrix &matrixInputToHideWeightValue,
CMatrix &matrixHideLayerValveValue,
CMatrix &matrixHideLayerOutput,
CMatrix &matrixHideToOutputWeightValue,
CMatrix &matrixOutputLayerOutput,
CMatrix &matrixOutputLayerValveValue
);
//***************************************************************************zdh
using namespace std;
#define LEVELS 6
#define DERROR 0.0000001
#define BIGNUMBER 9999999.0
#define UNARY 0
#define BINARY 1
class COperator
{
public:
COperator();
~COperator();
CString m_operator;//operator name
WORD m_level;//+,- : 0 level; *,/ :1 level; ^: 2 level; function:3 level.
//level add LEVELS if operator in a bracket.
WORD m_type;//0--unary operator, 1--binary operator,...
WORD m_startIndex;// start index which in formula
};
class COperand
{
public:
COperand();
~COperand();
BOOL operator ==(const COperand&od);//judge two operand are equal or not
CString m_name;//digital string or variant name
BOOL m_IsConst;//TRUE when it is digital, FALSE otherwise
WORD m_startIndex;//start index which in formula
};
typedef stack<COperator*> OperatorStack;
typedef stack<COperand*> OperandStack;
class CStringResolution
{
public:
void Destroy();
BOOL ExpressionIsError();//TRUE when expression has errors,FALSE otherwise.But when no include my.h,always FALSE.
CString GetDigitalString(double* variantValue=0,int num=-1);//replace variant as it's value
int GetErrorNumber();//get error number,always 0 when no include my.h
CString GetErrorInformation();//get the error description,
//always "There is no error information." when no include my.h
double computer(double variantValue[],int num);//evaluate variant(s) in m_oprandA by variantValue,then computing.
void SetFormula(char*formula);//reset formula
CStringResolution(char*formula=0);//constructor
int GetVariantTableSize(){return m_oprandANum;}//get variant number
const COperand* GetVariantTable();// get variant table
~CStringResolution();//destructor
protected:
#ifdef _ERROR_INFO_H_
DECLEAR_CATCH_ERROR
#endif
int m_oprandNum;//operand number
int m_oprandANum;//variant number
int m_operatorNum;//operator number
CString m_formula;//formula string
COperator*m_operator;//pointer points to operators set
COperand*m_oprand;//pointer points to operands set
COperand*m_oprandA;//pointer points to variants set
int IsFormula();//formula is availability or not.
BOOL GetStack(OperatorStack &Op, OperandStack &Od);//get operators stack and operands stack.
BOOL Initialize();//initialize variant member by m_formula.
double Computer(OperatorStack &Operator, OperandStack &Oprand);//computing by stack.
BOOL EmptyStack(OperatorStack st);//empty stack
BOOL EmptyStack(OperandStack st);//
BOOL GetOperandStack(OperandStack&Oprand,CString&string);//get operator stack in formula.
BOOL GetOperatorStack(OperatorStack&Operator,CString &s);//get operand stack after GetOperandStack.
double computing(const COperator*op,const COperand*oprand);//unary computing
double computing(const COperator*op,const COperand*Loprand,const COperand*Roprand);//binary computing
private:
// 前向计算初始化
void ForwardCalculateInit();
// 反复训练
bool DemoDataTrainRepeat();
// 用于存储输入的样本数据的矩阵
CMatrix m_matrixDemoDataInput;
// 样本的输入层的数值矩阵
CMatrix m_matrixInputLayerValue;
// 输入层到隐含层的权值矩阵
CMatrix m_matrixInputToHideWeightValue;
// 隐含层的阀值矩阵
CMatrix m_matrixHideLayerValveValue;
// 隐含层到输出层的权值矩阵
CMatrix m_matrixHideToOutputWeightValue;
// 输出层的阀值矩阵
CMatrix m_matrixOutputLayerValveValue;
// 隐含层的输出值的矩阵
CMatrix m_matrixHideLayerOutput;
// 输出层的输出值的矩阵
CMatrix m_matrixOutputLayerOutput;
// 用来仿真时输入的网络参数矩阵
CMatrix m_matrixSimuNetwork;
// 用来存放仿真数据结果的矩阵
CMatrix m_matrixSimuResult;
public:
CString m_strSimuNetworkFold;
UINT m_nInputLayerNumber;
UINT m_nHideLayerNumber;
UINT m_nOutputLayerNumber;
int m_nComboArithmetic;
int m_nComboFunc;
};
#endif // !defined(AFX_STRINGRESOLUTION_H__69522ED3_1E49_404E_8D5E_1261F7D732DD__INCLUDED_)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?