www.pudn.com > NNBP.rar > NNBPDlg.cpp
// NNBPDlg.cpp : implementation file
//
#include "stdafx.h"
#include "NNBP.h"
#include "NNBPDlg.h"
//***************************************************************************
// Add the user-defined header file
#include "AllDef.h"
//***************************************************************************
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CButtonST m_btnHelpDocument;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
afx_msg void OnHelpdocument();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_HELPDOCUMENT, m_btnHelpDocument);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_BN_CLICKED(IDC_HELPDOCUMENT, OnHelpdocument)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNNBPDlg dialog
CNNBPDlg::CNNBPDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNNBPDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNNBPDlg)
m_strDemoDataInput = _T("");
m_strDemoSaveResult = _T("");
m_nInputLayerNumber = 0;
m_nHideLayerNumber = 0;
m_nOutputLayerNumber = 0;
m_nComboFunc = -1;
m_nSystemError = 0.0;
m_nTrainTimes = 0;
m_nSystemErrorLevel = SYSTEM_ERROR_LEVEL;
m_nMaxTrainTimes = LOOP_MAX_TIMES;
m_strDemoSaveNetwork = _T("");
m_strSimuNetworkFold = _T("");
m_strSimuDataInput = _T("");
m_strSimuResult = _T("");
m_nComboArithmetic = -1;
m_nStep = INIT_STEP;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
// Initialize the member variables
m_bStartFlag = false;
m_bSimulateDataFlag = false;
m_SystemErrorNew = MAX_SYSTEM_ERROR;
m_SystemErrorOld = MAX_SYSTEM_ERROR;
m_hThread = NULL;
}
void CNNBPDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNNBPDlg)
DDX_Control(pDX, IDC_COMBO_ARITHMETIC, m_ctrlComboArithmetic);
DDX_Control(pDX, IDC_COMBO_FUNC, m_ctrlComboFunc);
DDX_Control(pDX, IDC_STATIC_TITLE, m_staticTextTitle);
DDX_Control(pDX, IDC_STATE, m_btnState);
DDX_Control(pDX, IDC_SIMU_RESULT_BROWSER, m_btnSimuResultBrowser);
DDX_Control(pDX, IDC_SIMU_NETWORK_FOLD_BROWSER, m_btnSimuNetworkFoldBrowser);
DDX_Control(pDX, IDC_SIMU_DATA_INPUT_BROWSER, m_btnSimuDataInputBrowser);
DDX_Control(pDX, IDC_DEMO_SAVE_RESULT_BROWSER, m_btnDemoSaveResultBrowser);
DDX_Control(pDX, IDC_DEMO_SAVE_NETWORK_BROWSER, m_btnDemoSaveNetworkBrowser);
DDX_Control(pDX, IDC_DEMO_DATA_INPUT_BROWSER, m_btnDemoDataInputBrowser);
DDX_Control(pDX, IDC_STOP_TRAIN, m_btnStopTrain);
DDX_Control(pDX, IDC_EXIT, m_btnExit);
DDX_Control(pDX, IDC_ABOUT_US, m_btnAboutUs);
DDX_Control(pDX, IDC_BEGIN_TRAIN, m_btnBeginTrain);
DDX_Text(pDX, IDC_DEMO_DATA_INPUT, m_strDemoDataInput);
DDX_Text(pDX, IDC_DEMO_SAVE_RESULT, m_strDemoSaveResult);
DDX_Text(pDX, IDC_INPUT_LAYER_NUMBER, m_nInputLayerNumber);
DDX_Text(pDX, IDC_HIDE_LAYER_NUMBER, m_nHideLayerNumber);
DDX_Text(pDX, IDC_OUTPUT_LAYER_NUMBER, m_nOutputLayerNumber);
DDX_CBIndex(pDX, IDC_COMBO_FUNC, m_nComboFunc);
DDX_Text(pDX, IDC_SYSTEM_ERROR, m_nSystemError);
DDX_Text(pDX, IDC_TRAIN_TIMES, m_nTrainTimes);
DDX_Text(pDX, IDC_SYSTEM_LEVEL, m_nSystemErrorLevel);
DDX_Text(pDX, IDC_MAX_TRAIN_TIMES, m_nMaxTrainTimes);
DDX_Text(pDX, IDC_DEMO_SAVE_NETWORK, m_strDemoSaveNetwork);
DDX_Text(pDX, IDC_SIMU_NETWORK_FOLD, m_strSimuNetworkFold);
DDX_Text(pDX, IDC_SIMU_DATA_INPUT, m_strSimuDataInput);
DDX_Text(pDX, IDC_SIMU_RESULT, m_strSimuResult);
DDX_CBIndex(pDX, IDC_COMBO_ARITHMETIC, m_nComboArithmetic);
DDX_Text(pDX, IDC_STEP, m_nStep);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNNBPDlg, CDialog)
//{{AFX_MSG_MAP(CNNBPDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_ABOUTUS, OnAboutus)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_DEMO_DATA_INPUT_BROWSER, OnDemoDataInputBrowser)
ON_BN_CLICKED(IDC_DEMO_SAVE_NETWORK_BROWSER, OnDemoSaveNetworkBrowser)
ON_BN_CLICKED(IDC_DEMO_SAVE_RESULT_BROWSER, OnDemoSaveResultBrowser)
ON_BN_CLICKED(IDC_SIMU_NETWORK_FOLD_BROWSER, OnSimuNetworkFoldBrowser)
ON_BN_CLICKED(IDC_SIMU_DATA_INPUT_BROWSER, OnSimuDataInputBrowser)
ON_BN_CLICKED(IDC_SIMU_RESULT_BROWSER, OnSimuResultBrowser)
ON_BN_CLICKED(IDC_BEGIN_TRAIN, OnBeginTrain)
ON_BN_CLICKED(IDC_STATE, OnState)
ON_BN_CLICKED(IDC_STOP_TRAIN, OnStopTrain)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNNBPDlg message handlers
BOOL CNNBPDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// Set the Graphic Title
{
m_staticTextTitle.Initialise( RGB(160,180,220) );
m_staticTextTitle.SetAlignCentre();
m_staticTextTitle.SetDrawShadow();
CFont font;
font.CreateFont(36,0,0,0,FW_BOLD,0,0,0,GB2312_CHARSET,0,0,0,0,TEXT("黑体"));
LOGFONT logfont;
font.GetLogFont(&logfont);
m_staticTextTitle.SetMainTextLogFont(logfont);
}
// "浏览"按钮的资源的装入
// For Demo Data Input Browser Button
m_btnDemoDataInputBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
m_btnDemoDataInputBrowser.SetIcon ( IDI_FILEOPEN);
m_btnDemoDataInputBrowser.SetActiveBgColor (RGB(160,180,220));
m_btnDemoDataInputBrowser.SetInactiveBgColor (RGB(160,180,220));
m_btnDemoDataInputBrowser.AddToolTip(TEXT("浏览"));
// For Demo Save Network Browser Button
m_btnDemoSaveNetworkBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
m_btnDemoSaveNetworkBrowser.SetIcon ( IDI_FILEOPEN);
m_btnDemoSaveNetworkBrowser.SetActiveBgColor (RGB(160,180,220));
m_btnDemoSaveNetworkBrowser.SetInactiveBgColor (RGB(160,180,220));
m_btnDemoSaveNetworkBrowser.AddToolTip(TEXT("浏览"));
// For Demo Save Result Browser Button
m_btnDemoSaveResultBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
m_btnDemoSaveResultBrowser.SetIcon ( IDI_FILEOPEN);
m_btnDemoSaveResultBrowser.SetActiveBgColor (RGB(160,180,220));
m_btnDemoSaveResultBrowser.SetInactiveBgColor (RGB(160,180,220));
m_btnDemoSaveResultBrowser.AddToolTip(TEXT("浏览"));
// For Simu Data Input Browser Button
m_btnSimuDataInputBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
m_btnSimuDataInputBrowser.SetIcon ( IDI_FILEOPEN);
m_btnSimuDataInputBrowser.SetActiveBgColor (RGB(160,180,220));
m_btnSimuDataInputBrowser.SetInactiveBgColor (RGB(160,180,220));
m_btnSimuDataInputBrowser.AddToolTip(TEXT("浏览"));
// For Simu Network Fold Browser Button
m_btnSimuNetworkFoldBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
m_btnSimuNetworkFoldBrowser.SetIcon ( IDI_FILEOPEN);
m_btnSimuNetworkFoldBrowser.SetActiveBgColor (RGB(160,180,220));
m_btnSimuNetworkFoldBrowser.SetInactiveBgColor (RGB(160,180,220));
m_btnSimuNetworkFoldBrowser.AddToolTip(TEXT("浏览"));
// For Simu Result Browser Button
m_btnSimuResultBrowser.SubclassDlgItem (IDI_FILEOPEN,this);
m_btnSimuResultBrowser.SetIcon ( IDI_FILEOPEN);
m_btnSimuResultBrowser.SetActiveBgColor (RGB(160,180,220));
m_btnSimuResultBrowser.SetInactiveBgColor (RGB(160,180,220));
m_btnSimuResultBrowser.AddToolTip(TEXT("浏览"));
// "开始训练"按钮的资源的装入
m_btnBeginTrain.SubclassDlgItem ( IDI_START,this);
m_btnBeginTrain.SetIcon ( IDI_START);
m_btnBeginTrain.SetActiveBgColor (RGB(160,180,220));
m_btnBeginTrain.SetInactiveBgColor (RGB(160,180,220));
m_btnBeginTrain.AddToolTip(TEXT("开始训练"));
// "停止训练"按钮的资源的装入
m_btnStopTrain.SubclassDlgItem ( IDI_STOP,this);
m_btnStopTrain.SetIcon ( IDI_STOP);
m_btnStopTrain.SetActiveBgColor (RGB(160,180,220));
m_btnStopTrain.SetInactiveBgColor (RGB(160,180,220));
m_btnStopTrain.AddToolTip(TEXT("停止训练"));
// "显示程序状态"按钮的资源的装入
m_btnState.SubclassDlgItem ( IDI_TRAINING,this);
m_btnState.SubclassDlgItem ( IDI_SIMULATOR,this);
m_btnState.SetIcon ( IDI_TRAINING);
m_btnState.SetActiveBgColor (RGB(160,180,220));
m_btnState.SetInactiveBgColor (RGB(160,180,220));
m_btnState.AddToolTip (TEXT("样本训练状态"));
// "关于我们"按钮的资源的装入
m_btnAboutUs.SubclassDlgItem (IDI_ABOUT,this);
m_btnAboutUs.SetIcon (IDI_ABOUT);
m_btnAboutUs.SetActiveBgColor (RGB(160,180,220));
m_btnAboutUs.SetInactiveBgColor (RGB(160,180,220));
m_btnAboutUs.AddToolTip (TEXT("关于我们"));
// "退出程序"按钮的资源的装入--->Yes
m_btnExit.SubclassDlgItem (IDI_EXIT,this);
m_btnExit.SetIcon (IDI_EXIT);
m_btnExit.SetActiveBgColor (RGB(160,180,220));
m_btnExit.SetInactiveBgColor (RGB(160,180,220));
m_btnExit.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);
//
// End of initializing the state of the controls on the CNNBPDlg
/////////////////////////////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
void CNNBPDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CNNBPDlg::OnPaint()
{
// Draw the title label
m_staticTextTitle.SetMainTextColour (RGB(0,128,192));
m_staticTextTitle.Display (TEXT("神经网络仿真工具"),TEXT(""),0);
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CNNBPDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CNNBPDlg::OnExit()
{
// TODO: Add your control notification handler code here
DWORD dwExitCode = 0;
if(::GetExitCodeThread (m_hThread, &dwExitCode))
{
if(dwExitCode == STILL_ACTIVE)
{
::TerminateThread (m_hThread, (DWORD)0);
}
CloseHandle (m_hThread);
m_hThread = NULL;
}
CDialog::OnOK ();
}
void CNNBPDlg::OnAboutus()
{
// TODO: Add your control notification handler code here
CAboutDlg dlg;
if(dlg.DoModal () == IDOK)
return;
}
void CNNBPDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnTimer(nIDEvent);
}
void CNNBPDlg::OnDemoDataInputBrowser()
{
// 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 to load the data
CFileDialog dlg(TRUE,
lpszDefExt,
NULL,
OFN_READONLY |
OFN_FILEMUSTEXIST |
OFN_PATHMUSTEXIST,
szFilter,
this);
if(dlg.DoModal () == IDOK)
{
m_strDemoDataInput = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd,IDC_DEMO_DATA_INPUT);
::SetWindowText (hWnd,m_strDemoDataInput);
}
else
{
return;
}
}
void CNNBPDlg::OnDemoSaveNetworkBrowser()
{
// 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 to save the network
CFileDialog dlg(FALSE,
lpszDefExt,
NULL,
OFN_HIDEREADONLY |
OFN_CREATEPROMPT |
OFN_OVERWRITEPROMPT,
szFilter,
this );
if(dlg.DoModal ()==IDOK)
{
m_strDemoSaveNetwork = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd,IDC_DEMO_SAVE_NETWORK);
::SetWindowText (hWnd,m_strDemoSaveNetwork);
}
else
{
return;
}
}
void CNNBPDlg::OnDemoSaveResultBrowser()
{
// 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 to save the result
CFileDialog dlg(FALSE,
lpszDefExt,
NULL,
OFN_HIDEREADONLY |
OFN_CREATEPROMPT |
OFN_OVERWRITEPROMPT,
szFilter,
this);
if(dlg.DoModal ()==IDOK)
{
m_strDemoSaveResult = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd , IDC_DEMO_SAVE_RESULT);
::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"));
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"));
}
}