📄 nnbpdlg.cpp
字号:
m_ctrlComboArithmetic.SetCurSel (-1);
m_ctrlComboFunc.SetCurSel (-1);
hWnd = ::GetDlgItem (this->m_hWnd, IDC_DEMO_DATA_INPUT);
::SetWindowText (hWnd, _T(""));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_DEMO_SAVE_NETWORK);
::SetWindowText (hWnd, _T(""));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_DEMO_SAVE_RESULT);
::SetWindowText (hWnd, _T(""));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_SYSTEM_ERROR);
::SetWindowText (hWnd, _T("0"));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_TRAIN_TIMES);
::SetWindowText (hWnd, _T("0"));
}
else // Fail to accomplish the task
{
// 释放全局变量所占的内存
m_matrixDemoDataInput.InitializeZero ();
m_matrixInputLayerValue.InitializeZero ();
m_matrixInputToHideWeightValue.InitializeZero ();
m_matrixHideLayerValveValue.InitializeZero ();
m_matrixHideLayerOutput.InitializeZero ();
m_matrixHideToOutputWeightValue.InitializeZero ();
m_matrixOutputLayerValveValue.InitializeZero ();
m_matrixOutputLayerOutput.InitializeZero ();
// ReInitialize the global value
m_nInputLayerNumber = 0;
m_nHideLayerNumber = 0;
m_nOutputLayerNumber = 0;
m_nComboFunc = -1;
m_nComboArithmetic = -1;
m_nSystemError = 0;
m_nTrainTimes = 0;
m_nSystemErrorLevel = SYSTEM_ERROR_LEVEL;
m_nMaxTrainTimes = LOOP_MAX_TIMES;
m_SystemErrorNew = MAX_SYSTEM_ERROR;
m_SystemErrorOld = MAX_SYSTEM_ERROR;
m_nStep = INIT_STEP;
m_strDemoDataInput = TEXT("");
m_strDemoSaveNetwork = TEXT("");
m_strDemoSaveResult = TEXT("");
::MessageBox (this->m_hWnd, _T("很抱歉,我未能完成您交给我的任务."), _T(":("),MB_OK | MB_ICONERROR);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
//*******************************************************************
// handle the UI
//
CString strSystemErrorLevel;
strSystemErrorLevel.Format ("%lf", m_nSystemErrorLevel);
HWND hWnd = ::GetDlgItem (this->m_hWnd, IDC_SYSTEM_LEVEL);
::SetWindowText (hWnd, (LPCTSTR)strSystemErrorLevel);
CString strMaxTrainTimes;
strMaxTrainTimes.Format ("%u", m_nMaxTrainTimes);
hWnd = ::GetDlgItem (this->m_hWnd, IDC_MAX_TRAIN_TIMES);
::SetWindowText (hWnd, (LPCTSTR)strMaxTrainTimes);
hWnd = ::GetDlgItem (this->m_hWnd, IDC_INPUT_LAYER_NUMBER);
::SetWindowText (hWnd, _T("0"));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_HIDE_LAYER_NUMBER);
::SetWindowText (hWnd, _T("0"));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_OUTPUT_LAYER_NUMBER);
::SetWindowText (hWnd, _T("0"));
m_ctrlComboArithmetic.SetCurSel (-1);
m_ctrlComboFunc.SetCurSel (-1);
hWnd = ::GetDlgItem (this->m_hWnd, IDC_DEMO_DATA_INPUT);
::SetWindowText (hWnd, _T(""));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_DEMO_SAVE_NETWORK);
::SetWindowText (hWnd, _T(""));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_DEMO_SAVE_RESULT);
::SetWindowText (hWnd, _T(""));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_SYSTEM_ERROR);
::SetWindowText (hWnd, _T("0"));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_TRAIN_TIMES);
::SetWindowText (hWnd, _T("0"));
return false;
}
return true;
}
bool CNNBPDlg::SimulateData()
{
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(FALSE);
if(!m_bSimulateDataFlag)
{
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
if(m_strSimuNetworkFold.IsEmpty ())
{
::MessageBox (this->m_hWnd, _T("你还没选取提供网络参数的文件的装载路径!"), _T(":("),MB_OK | MB_ICONWARNING);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
if(m_strSimuDataInput.IsEmpty ())
{
::MessageBox (this->m_hWnd, _T("你还没选取用来仿真的数据文件的装载路径!"), _T(":("),MB_OK | MB_ICONWARNING);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
if(m_strSimuResult.IsEmpty ())
{
::MessageBox (this->m_hWnd, _T("你还没选取最终仿真结果的数据文件的存放路径!"), _T(":("),MB_OK | MB_ICONWARNING);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
// 装载网络参数文件
m_matrixSimuNetwork.LoadDataFromFileSpecial(m_strSimuNetworkFold,
m_matrixInputToHideWeightValue,
m_matrixHideLayerValveValue,
m_matrixHideToOutputWeightValue,
m_matrixOutputLayerValveValue,
m_nInputLayerNumber,
m_nHideLayerNumber,
m_nOutputLayerNumber,
m_nComboArithmetic,
m_nComboFunc);
// 装载仿真数据文件
m_matrixDemoDataInput.LoadDataFromFile (m_strSimuDataInput);
if( m_matrixDemoDataInput.GetMatrixColNumber () != m_nInputLayerNumber )
{
::MessageBox (this->m_hWnd, _T("待仿真数据文件的输入层数目与网络中的输入层数目不相等!!!"), _T("错误!"), MB_OK | MB_ICONERROR);
// 释放全局变量所占的内存
m_matrixSimuNetwork.InitializeZero ();
m_matrixInputToHideWeightValue.InitializeZero ();
m_matrixHideLayerValveValue.InitializeZero ();
m_matrixHideToOutputWeightValue.InitializeZero ();
m_matrixOutputLayerValveValue.InitializeZero ();
m_matrixDemoDataInput.InitializeZero ();
m_strSimuNetworkFold = TEXT("");
m_strSimuDataInput = TEXT("");
m_strSimuResult = TEXT("");
m_nInputLayerNumber = 0;
m_nHideLayerNumber = 0;
m_nOutputLayerNumber = 0;
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
//*******************************************************************
// Update the UI
//
HWND hWnd = ::GetDlgItem (this->m_hWnd, IDC_SIMU_NETWORK_FOLD);
::SetWindowText (hWnd, _T(""));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_SIMU_DATA_INPUT);
::SetWindowText (hWnd, _T(""));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_SIMU_RESULT);
::SetWindowText (hWnd, _T(""));
return false;
}
else // Successful!!!
{
// 前向计算
switch(m_nComboArithmetic)
{
case 0: // LM Arithmetic Selected
LMForwardCalculate( m_nInputLayerNumber,
m_nHideLayerNumber,
m_nOutputLayerNumber,
m_bSimulateDataFlag,
m_nComboFunc,
m_matrixDemoDataInput,
m_matrixInputLayerValue,
m_matrixInputToHideWeightValue,
m_matrixHideLayerValveValue,
m_matrixHideLayerOutput,
m_matrixHideToOutputWeightValue,
m_matrixOutputLayerOutput,
m_matrixOutputLayerValveValue
);
break;
case 1: // BP Arithmetic Selected
BPForwardCalculate2(m_nInputLayerNumber,
m_nHideLayerNumber,
m_nOutputLayerNumber,
m_bSimulateDataFlag,
m_nComboFunc,
m_matrixDemoDataInput,
m_matrixInputLayerValue,
m_matrixInputToHideWeightValue,
m_matrixHideLayerValveValue,
m_matrixHideLayerOutput,
m_matrixHideToOutputWeightValue,
m_matrixOutputLayerOutput,
m_matrixOutputLayerValveValue
);
break;
default: // No Arithmetic Selected
return false;
}
// 存储模拟结果
(m_matrixOutputLayerOutput.Transpose()).SaveDataToFile(m_strSimuResult);
// 释放全局变量所占的内存
m_matrixSimuNetwork.InitializeZero ();
m_matrixInputToHideWeightValue.InitializeZero ();
m_matrixHideLayerValveValue.InitializeZero ();
m_matrixHideToOutputWeightValue.InitializeZero ();
m_matrixOutputLayerValveValue.InitializeZero ();
m_matrixDemoDataInput.InitializeZero ();
m_matrixHideLayerOutput.InitializeZero ();
m_matrixOutputLayerOutput.InitializeZero ();
m_strSimuNetworkFold = _T("");
m_strSimuDataInput = _T("");
m_strSimuResult = _T("");
m_nComboFunc = -1;
m_nInputLayerNumber = 0;
m_nHideLayerNumber = 0;
m_nOutputLayerNumber = 0;
::MessageBox (this->m_hWnd, _T("数据仿真结果保存成功!"), _T("恭喜!"), MB_OK);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
//*******************************************************************
// Update the UI
//
HWND hWnd = ::GetDlgItem (this->m_hWnd, IDC_SIMU_NETWORK_FOLD);
::SetWindowText (hWnd, _T(""));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_SIMU_DATA_INPUT);
::SetWindowText (hWnd, _T(""));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_SIMU_RESULT);
::SetWindowText (hWnd, _T(""));
}
return true;
}
void CNNBPDlg::ForwardCalculateInit()
{
LMForwardCalculateInit( m_nInputLayerNumber,
m_nHideLayerNumber,
m_nOutputLayerNumber,
m_matrixDemoDataInput,
m_matrixInputLayerValue,
m_matrixInputToHideWeightValue,
m_matrixHideLayerValveValue,
m_matrixHideToOutputWeightValue,
m_matrixOutputLayerValveValue
);
}
bool CNNBPDlg::DemoDataTrainRepeat()
{
bool bReturn = false;
switch( m_nComboArithmetic)
{
case 0: // LM Arithmetic Selected
bReturn = LMDemoDataTrainRepeat ( m_nInputLayerNumber,
m_nHideLayerNumber,
m_nOutputLayerNumber,
m_bSimulateDataFlag,
m_nComboFunc,
m_SystemErrorOld,
m_SystemErrorNew,
m_nSystemErrorLevel,
m_nSystemError,
m_nStep,
m_nMaxTrainTimes,
m_nTrainTimes,
IDC_SYSTEM_ERROR,
IDC_TRAIN_TIMES,
this->m_hWnd,
m_matrixDemoDataInput,
m_matrixInputLayerValue,
m_matrixInputToHideWeightValue,
m_matrixHideLayerValveValue,
m_matrixHideLayerOutput,
m_matrixHideToOutputWeightValue,
m_matrixOutputLayerOutput,
m_matrixOutputLayerValveValue
);
break;
case 1: // BP Arithmetic Selected
bReturn = BPDemoDataTrainRepeat ( m_nInputLayerNumber,
m_nHideLayerNumber,
m_nOutputLayerNumber,
m_bSimulateDataFlag,
m_nComboFunc,
m_SystemErrorOld,
m_SystemErrorNew,
m_nSystemErrorLevel,
m_nSystemError,
m_nStep,
m_nMaxTrainTimes,
m_nTrainTimes,
IDC_SYSTEM_ERROR,
IDC_TRAIN_TIMES,
this->m_hWnd,
m_matrixDemoDataInput,
m_matrixInputLayerValue,
m_matrixInputToHideWeightValue,
m_matrixHideLayerValveValue,
m_matrixHideLayerOutput,
m_matrixHideToOutputWeightValue,
m_matrixOutputLayerOutput,
m_matrixOutputLayerValveValue
);
break;
default: // No Arithmetic Selected
return bReturn;
}
return bReturn;
}
bool CNNBPDlg::SaveConstantStringToFile(CString& strFileName,CString& strConstantData)
{
// Convert CString to LPCTSTR
LPCTSTR lpszFileName = "";
strFileName.TrimLeft ();
strFileName.TrimRight ();
lpszFileName = (LPCTSTR)strFileName;
CStdioFile dataFile;
if(!dataFile.Open (lpszFileName, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite | CFile::typeText))
{
::MessageBox(this->m_hWnd, _T("不能创建存储网络参数的文件!"), _T("错误!"), MB_OK | MB_ICONERROR);
dataFile.Close ();
return FALSE;
}
dataFile.SeekToEnd ();
// Write data into the file
char *pBuffer = new char[strConstantData.GetLength ()];
memcpy(pBuffer,strConstantData,strConstantData.GetLength ());
dataFile.Write (pBuffer,strConstantData.GetLength ());
dataFile.Close ();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// 工作线程过程
//
/////////////////////////////////////////////////////////////////////////////
ULONG __stdcall WorkThreadProc(LPVOID lParam)
{
if(lParam == NULL)
return -1;
STHREADDATA *pData = (STHREADDATA *)lParam;
// Set the flag
pData->pDlg->m_bStartFlag = true;
if(pData->pDlg->m_bSimulateDataFlag)
{
pData->pDlg->SimulateData();
}
else
{
pData->pDlg->TrainingDemo();
}
pData->pDlg->m_bStartFlag = false;
delete pData;
pData = 0;
return 0;
}
void CAboutDlg::OnHelpdocument()
{
// TODO: Add your control notification handler code here
DWORD nBufferLength=256;
TCHAR lpBuffer[256];
CString m_strPath;
GetCurrentDirectory(nBufferLength,lpBuffer);
m_strPath = lpBuffer;
m_strPath = m_strPath + '\\' + TEXT("Help.chm");
HINSTANCE hHelpFile = ShellExecute (NULL,"open", m_strPath, NULL, NULL, SW_SHOWNORMAL);
if((long)hHelpFile == ERROR_FILE_NOT_FOUND)
{
::MessageBox(this->m_hWnd, _T("帮助文件没有找到,你是不是把它给删了?"), _T("没找到"), MB_ICONEXCLAMATION | MB_OK );
return ;
}
}
void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnOK ();
//CDialog::OnLButtonDown(nFlags, point);
}
void CNNBPDlg::OnStopTrain()
{
// TODO: Add your control notification handler code here
DWORD dwExitCode = 0;
::GetExitCodeThread (m_hThread, &dwExitCode);
if(dwExitCode == STILL_ACTIVE)
{
::TerminateThread (m_hThread, (DWORD)0);
CloseHandle (m_hThread);
m_hThread = NULL;
HWND hWnd = ::GetDlgItem (this->m_hWnd, IDC_SYSTEM_ERROR);
::SetWindowText (hWnd, _T("0"));
hWnd = ::GetDlgItem (this->m_hWnd, IDC_TRAIN_TIMES);
::SetWindowText (hWnd, _T("0"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -