?? nnbpdlg.cpp
字號:
::SetWindowText (hWnd, m_strDemoSaveResult);
}
else
{
return;
}
}
void CNNBPDlg::OnSimuNetworkFoldBrowser()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
static char BASED_CODE lpszDefExt[] = TEXT("txt");
//Create the dialog to select the network data file
CFileDialog dlg(TRUE,
lpszDefExt,
NULL,
OFN_READONLY |
OFN_FILEMUSTEXIST |
OFN_PATHMUSTEXIST,
szFilter,
this);
if(dlg.DoModal ()==IDOK)
{
m_strSimuNetworkFold = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd ,IDC_SIMU_NETWORK_FOLD);
::SetWindowText (hWnd, m_strSimuNetworkFold);
}
else
{
return;
}
}
void CNNBPDlg::OnSimuDataInputBrowser()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
static char BASED_CODE lpszDefExt[] = TEXT("txt");
//Create the dialog to select the simulate data file
CFileDialog dlg(TRUE,
lpszDefExt,
NULL,
OFN_READONLY |
OFN_FILEMUSTEXIST |
OFN_PATHMUSTEXIST,
szFilter,
this);
if(dlg.DoModal ()==IDOK)
{
m_strSimuDataInput = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd ,IDC_SIMU_DATA_INPUT);
::SetWindowText (hWnd,m_strSimuDataInput);
}
else
{
return;
}
}
void CNNBPDlg::OnSimuResultBrowser()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
static char BASED_CODE lpszDefExt[] = TEXT("txt");
//Create the dialog to select the demo data file
CFileDialog dlg(FALSE,
lpszDefExt,
NULL,
OFN_HIDEREADONLY |
OFN_CREATEPROMPT |
OFN_OVERWRITEPROMPT,
szFilter,
this);
if(dlg.DoModal ()==IDOK)
{
m_strSimuResult = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd ,IDC_SIMU_RESULT);
::SetWindowText (hWnd,m_strSimuResult);
}
else
{
return;
}
}
void CNNBPDlg::OnBeginTrain()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
STHREADDATA* pData = new STHREADDATA;
pData->pDlg = this;
DWORD dwExitCode = 0;
::GetExitCodeThread (m_hThread, &dwExitCode);
if(dwExitCode == STILL_ACTIVE)
{
::MessageBox (this->m_hWnd, _T("程序中的訓練線程仍然在運行中!"), _T("警告:"), MB_ICONWARNING | MB_OK);
return;
}
ULONG ulThreadID;
m_hThread = ::CreateThread (NULL,
0,
WorkThreadProc,
pData,
CREATE_SUSPENDED,
&ulThreadID
);
ResumeThread (m_hThread);
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// "使用說明"按鈕的資源的裝入
m_btnHelpDocument.SubclassDlgItem (IDI_HELP,this);
m_btnHelpDocument.SetIcon ( IDI_HELP);
m_btnHelpDocument.SetActiveBgColor (RGB(160,180,220));
m_btnHelpDocument.SetInactiveBgColor (RGB(160,180,220));
m_btnHelpDocument.AddToolTip (TEXT("使用說明"));
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CNNBPDlg::OnState()
{
// TODO: Add your control notification handler code here
/////////////////////////////////////////////////////////////////////////
// Change the button flag
m_bSimulateDataFlag = !m_bSimulateDataFlag;
if(m_bSimulateDataFlag)
{
// 程序處在數據仿真狀態
m_btnState.SetIcon (IDI_SIMULATOR);
m_btnState.AddToolTip (TEXT("數據仿真狀態"));
// the BeginTrain Button State
m_btnBeginTrain.AddToolTip(TEXT("開始仿真"));
/////////////////////////////////////////////////////////////////////
// Disabled the following controls
/////////////////////////////////////////////////////////////////////
(CNNBPDlg *)GetDlgItem(IDC_SYSTEM_LEVEL)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_MAX_TRAIN_TIMES)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_STEP)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_INPUT_LAYER_NUMBER)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_HIDE_LAYER_NUMBER)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_OUTPUT_LAYER_NUMBER)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_COMBO_TRAIN)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_COMBO_FUNC)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_DATA_INPUT)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_DATA_INPUT_BROWSER)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_NETWORK)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_NETWORK_BROWSER)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_RESULT)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_RESULT_BROWSER)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_STOP_TRAIN)->EnableWindow(FALSE);
/////////////////////////////////////////////////////////////////////
// Enabled the following controls
/////////////////////////////////////////////////////////////////////
(CNNBPDlg *)GetDlgItem(IDC_SIMU_NETWORK_FOLD)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_SIMU_NETWORK_FOLD_BROWSER)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_SIMU_DATA_INPUT)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_SIMU_DATA_INPUT_BROWSER)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_SIMU_RESULT)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_SIMU_RESULT_BROWSER)->EnableWindow(TRUE);
}
else
{
// 程序處在樣本訓練狀態
m_btnState.SetIcon (IDI_TRAINING);
m_btnState.AddToolTip (TEXT("樣本訓練狀態"));
// the BeginTrain Button State
m_btnBeginTrain.AddToolTip(TEXT("開始訓練"));
/////////////////////////////////////////////////////////////////////
// Disabled the following controls
/////////////////////////////////////////////////////////////////////
(CNNBPDlg *)GetDlgItem(IDC_SIMU_NETWORK_FOLD)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_SIMU_NETWORK_FOLD_BROWSER)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_SIMU_DATA_INPUT)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_SIMU_DATA_INPUT_BROWSER)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_SIMU_RESULT)->EnableWindow(FALSE);
(CNNBPDlg *)GetDlgItem(IDC_SIMU_RESULT_BROWSER)->EnableWindow(FALSE);
/////////////////////////////////////////////////////////////////////
// Enabled the following controls
/////////////////////////////////////////////////////////////////////
(CNNBPDlg *)GetDlgItem(IDC_SYSTEM_LEVEL)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_MAX_TRAIN_TIMES)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_STEP)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_INPUT_LAYER_NUMBER)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_HIDE_LAYER_NUMBER)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_OUTPUT_LAYER_NUMBER)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_COMBO_TRAIN)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_COMBO_FUNC)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_DATA_INPUT)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_DATA_INPUT_BROWSER)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_NETWORK)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_NETWORK_BROWSER)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_RESULT)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_DEMO_SAVE_RESULT_BROWSER)->EnableWindow(TRUE);
(CNNBPDlg *)GetDlgItem(IDC_STOP_TRAIN)->EnableWindow(TRUE);
}
}
bool CNNBPDlg::TrainingDemo()
{
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(FALSE);
if(m_bSimulateDataFlag)
{
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
if(m_nInputLayerNumber <= 0)
{
::MessageBox (this->m_hWnd, _T("輸入層數目必須為大于等于1的正整數!"), _T(":("), MB_OK);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
if(m_nHideLayerNumber <= 0)
{
::MessageBox (this->m_hWnd, _T("隱含層數目必須為大于等于1的正整數!"), _T(":("), MB_OK);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
if(m_nOutputLayerNumber <= 0)
{
::MessageBox (this->m_hWnd, _T("輸出層數目必須為大于等于1的正整數!"), _T(":("), MB_OK | MB_ICONINFORMATION);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
if(m_nComboArithmetic == -1)
{
::MessageBox (this->m_hWnd, _T("你還沒有選取用來訓練的算法!"), _T(":("), MB_OK | MB_ICONINFORMATION);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
if(m_nComboFunc == -1)
{
::MessageBox (this->m_hWnd, _T("你還沒有選取用來訓練的激活函數!"), _T(":("), MB_OK | MB_ICONINFORMATION);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
if(m_strDemoDataInput.IsEmpty ())
{
::MessageBox (this->m_hWnd, _T("你還沒選取用來訓練的樣本數據文件的裝載路徑!"), _T(":("), MB_OK | MB_ICONINFORMATION);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
if(m_strDemoSaveNetwork.IsEmpty ())
{
::MessageBox (this->m_hWnd, _T("你還沒選取最終模擬輸出網絡參數的文件的存放路徑!"), _T(":("), MB_OK | MB_ICONINFORMATION);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
if(m_strDemoSaveResult.IsEmpty ())
{
::MessageBox (this->m_hWnd, _T("你還沒選取最終模擬輸出結果的文件的存放路徑!"), _T(":("), MB_OK | MB_ICONINFORMATION);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return false;
}
// 裝載資源
m_matrixDemoDataInput.LoadDataFromFile (m_strDemoDataInput);
if((m_nInputLayerNumber + m_nOutputLayerNumber) != m_matrixDemoDataInput.GetMatrixColNumber () )
{
::MessageBox (this->m_hWnd, _T("所輸入的輸入層和輸出層數目之和與被讀取文件中的數目不相符!"), _T("錯誤!"), MB_OK | MB_ICONERROR);
(CNNBPDlg *)GetDlgItem(IDC_STATE)->EnableWindow(TRUE);
return FALSE;
}
// 第一次前向計算初始化
ForwardCalculateInit();
// 反復反饋運算
bool bSuccess = DemoDataTrainRepeat();
if(bSuccess) // Successful!
{
//////////////////////////////////////////////////////////////////////////////
// 定義存儲矩陣格式 //
//////////////////////////////////////////////////////////////////////////////
if(!(m_strDemoSaveNetwork.IsEmpty ()))
{
CString strDemoInputLayerNumber = _T("## 樣本的輸入層的數目: ##\n");
SaveConstantStringToFile(m_strDemoSaveNetwork, strDemoInputLayerNumber);
CString strInputLayerNumber;
strInputLayerNumber.Format ("%u", m_nInputLayerNumber);
SaveConstantStringToFile(m_strDemoSaveNetwork, strInputLayerNumber);
CString strDemoHideLayerNumber = _T("\n## 樣本的隱含層的數目: ##\n");
SaveConstantStringToFile(m_strDemoSaveNetwork, strDemoHideLayerNumber);
CString strHideLayerNumber;
strHideLayerNumber.Format ("%u", m_nHideLayerNumber);
SaveConstantStringToFile(m_strDemoSaveNetwork, strHideLayerNumber);
CString strDemoOutputLayerNumber = _T("\n## 樣本的輸出層的數目: ##\n");
SaveConstantStringToFile(m_strDemoSaveNetwork, strDemoOutputLayerNumber);
CString strOutputLayerNumber;
strOutputLayerNumber.Format ("%u", m_nOutputLayerNumber);
SaveConstantStringToFile(m_strDemoSaveNetwork, strOutputLayerNumber);
CString strSelectAlgorithm = _T("\n## 訓練網絡所采用的神經網絡算法: ##\n");
SaveConstantStringToFile(m_strDemoSaveNetwork, strSelectAlgorithm);
CString strComboArithmetic;
strComboArithmetic.Format ("%d", m_nComboArithmetic);
SaveConstantStringToFile(m_strDemoSaveNetwork, strComboArithmetic);
CString strSelectFunction = _T("\n## 網絡中使用的函數的索引值: ##\n");
SaveConstantStringToFile(m_strDemoSaveNetwork, strSelectFunction);
CString strComboFunc;
strComboFunc.Format ("%d", m_nComboFunc);
SaveConstantStringToFile(m_strDemoSaveNetwork, strComboFunc);
CString strSeparator = _T("\n## 輸入層到隱含層的權值矩陣 ##\n");
SaveConstantStringToFile(m_strDemoSaveNetwork, strSeparator);
// 存儲模擬過的輸入到隱含層的權值矩陣
m_matrixInputToHideWeightValue.SaveDataToFile (m_strDemoSaveNetwork);
strSeparator = _T("\n## 隱含層的閥值矩陣 ##\n");
SaveConstantStringToFile(m_strDemoSaveNetwork,strSeparator);
// 存儲模擬過的隱含層的閥值矩陣
m_matrixHideLayerValveValue.SaveDataToFile (m_strDemoSaveNetwork);
strSeparator = _T("\n## 隱含層到輸出層的權值矩陣 ##\n");
SaveConstantStringToFile(m_strDemoSaveNetwork,strSeparator);
// 存儲模擬過的隱含層到輸出層的權值矩陣
m_matrixHideToOutputWeightValue.SaveDataToFile (m_strDemoSaveNetwork);
strSeparator = _T("\n## 輸出層的閥值矩陣 ##\n");
SaveConstantStringToFile(m_strDemoSaveNetwork,strSeparator);
// 存儲模擬過的輸出層的閥值矩陣
m_matrixOutputLayerValveValue.SaveDataToFile (m_strDemoSaveNetwork);
}
// 存儲模擬過輸出層的輸出值矩陣
if(!(m_strDemoSaveResult.IsEmpty ()))
{
(m_matrixOutputLayerOutput.Transpose()).SaveDataToFile (m_strDemoSaveResult);
}
// 釋放全局變量所占的內存
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);
(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"));
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -