📄 test.cpp
字号:
// Test.cpp : implementation file
//
#include "stdafx.h"
#include "probp.h"
#include "Test.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTest property page
IMPLEMENT_DYNCREATE(CTest, CPropertyPage)
CTest::CTest() : CPropertyPage(CTest::IDD)
{
//{{AFX_DATA_INIT(CTest)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
netExist=false;
netConstruct=false;
}
CTest::~CTest()
{
}
void CTest::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTest)
DDX_Control(pDX, IDC_testLIST, m_testList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTest, CPropertyPage)
//{{AFX_MSG_MAP(CTest)
ON_BN_CLICKED(IDC_opentestData, OnopentestData)
ON_BN_CLICKED(IDC_openNet, OnopenNet)
ON_BN_CLICKED(IDC_begin, OnbeginTest)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest message handlers
void CTest::OnopentestData()
{ if (!netExist) AfxMessageBox(_T("请先打开已学习的网络"));
else
{
CFileDialog dlg(TRUE,"test","*.test");
if(dlg.DoModal()==IDOK)
{
testfilename=dlg.GetPathName();
netConstruct=true;
}
}
}
void CTest::OnopenNet()
{
CFileDialog dlg(TRUE,"bp","*.bp");
if(dlg.DoModal()==IDOK)
{
m_Neural=new NeuralB;
m_Neural->Net_Design.realtesting=true;
m_Neural->Test_Data.realtesting=true;
netExist=true;
m_testList.SetColumnWidth(4000);
CString temp;
temp=dlg.GetPathName();
lstrcpy(m_Neural->Net_Design.bpfilename,temp);
m_Neural->Net_Design.upload_network();
m_Neural->establish_backprop_network();
m_Neural->Net_Design.upload_network();
}
// TODO: Add your control notification handler code here
}
void CTest::OnbeginTest()
{while (m_testList.GetCount()!=0)
{m_testList.DeleteString(0);}
if (netConstruct)
{ m_Neural->prepareRealTest((LPCTSTR)testfilename);
m_Neural->Test_Data.testsampleNum=0;
while ((m_Neural->Test_Data.testsampleNum)<(m_Neural->Test_Data.sample_number))
{
m_Neural->realtest();
m_Neural->Test_Data.testsampleNum++;
disptestresult();
}
}
else AfxMessageBox(_T("请先打开测试数据"));// TODO: Add your control notification handler code here
}
void CTest::disptestresult()
{ CString result;
result.Format("s%d ",m_Neural->Test_Data.testsampleNum);
CString tp;
for(int dim=0;dim<(m_Neural->Net_Design.nodes_in_output_layer);dim++)
{ tp.Format("d%d ",dim+1);
result=result+tp;
tp.Format("t%f ",m_Neural->Test_Data.targetoutput[dim]);
result=result+tp;
tp.Format("n%f ",m_Neural->Test_Data.netoutput[dim]);
result=result+tp;
double err;
if (m_Neural->Test_Data.targetoutput[dim]==0) err=1;
else
err=
fabs((m_Neural->Test_Data.targetoutput[dim]-m_Neural->Test_Data.netoutput[dim])/
m_Neural->Test_Data.targetoutput[dim]);
tp.Format("e%f ",err);
result=result+tp;
}
m_testList.AddString(result);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -