📄 bpnetdlg.cpp
字号:
}
fprintf(fp1,"\n%d %f",cnt,err_curr);
fprintf(fp1,"\n");
for(i=0;i<ninput;i++)
{
for(j=0;j<noutattr;j++)
fprintf(fp1,"%f",outpt[i][j]);
fprintf(fp1,"\n");
}
if((c=fclose(fp1))!=0)
exit(0);
}
////////////////
void CBPNetDlg::wtwrite(char *taskname)
{
int i,j,c,k;
char wt_file_name[20];
strcpy(wt_file_name,taskname);
strcat(wt_file_name,"_w.txt");
if((fp2=fopen(wt_file_name,"w+"))==NULL)
{
exit(0);
}
k=0;
for(i=0;i<nhlayer+1;i++)
for(j=0;j<(nunit[i]+1)*nunit[i+1];j++)
{
if(k==8)
{
k=0;
fprintf(fp2,"\n");
}
fprintf(fp2,"%f ",*(wtptr[i]+j));
k++;
}
if((c=fclose(fp2))!=0)
exit(0);
}
void CBPNetDlg::OnBeginLearn()
{
if(!m_bEnableLearn)
{
AfxMessageBox("请先输入数据!!!");
}
else
{
UpdateData(true);
eta=m_eta;
alpha=m_alpha;
maxe=m_error;
cnt_num=m_maxnum;
ninattr=m_ninattr;
noutattr=m_noutattr;
nhlayer=m_nhlayer;
nsample=m_nodehlayer;
ninput=m_nodehlayer;
learning();
}
}
////////////////
void CBPNetDlg::output_generation()
{
//仿真!!!
int i,m;
set_up();//设置网络
init();
wtread(task_name);
ifstream istrm;
istrm.open(m_INPUTFANGZHEN);//m_INPUTFANGZHEN
for(i=0;i<nsampleFangzhen;i++)//
for(m=0;m<ninattr;m++)
istrm>>input[i][m];
istrm.close();
if((fp1=fopen("output_sample.txt","w+"))==NULL)
{
exit(0);
}
for(i=0;i<nsampleFangzhen;i++)
{
forward(i);
for(m=0;m<noutattr;m++)
fprintf(fp1," %f\n",*(outptr[nhlayer+1]+m) );
}
if((i=fclose(fp1))!=0)
exit(0);
}
///////////////
void CBPNetDlg::wtread(char *taskname)
{
int i,j;
char wt_file_name[20];
strcpy(wt_file_name,taskname);
strcat(wt_file_name,"_w.txt");
// if((fp2=fopen(wt_file_name,"r"))==NULL)
// {
// exit(0);
// }
ifstream istrm;
istrm.open(wt_file_name);
for(i=0;i<nhlayer+1;i++)
{
for(j=0;j<(nunit[i]+1)*nunit[i+1];j++)
{
istrm>>*(wtptr[i]+j);
}
}
istrm.close();
// if((c=fclose(fp2))!=0)
// exit(0);
}
void CBPNetDlg::OnOutput()
{
if(!INPUTNETEMULATION&&!INPUTNETWEIGHT)
{
AfxMessageBox("请先输入训练好的网络数据!!!");
return;
}
else
{
CStdioFile m_File;
CFileException e;
if(!m_File.Open(m_INPUTFANGZHEN,CFile::modeRead, &e))
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
}
BOOL m_bEnd=TRUE;
CString m_strLine;
nsampleFangzhen=0;
while(m_bEnd)
{
m_bEnd=m_File.ReadString(m_strLine);
if(m_bEnd)//如果读出一行
{
nsampleFangzhen++;//计算仿镇数据的个数
}
}
m_File.Close();
output_generation();
AfxMessageBox("仿真结果已存入文件中!!!");
}
}
void CBPNetDlg::OnDataInputbrowse()
{
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_inputdata = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd,IDC_EDIT39);
::SetWindowText (hWnd,m_inputdata);
}
else
{
return;
}
m_bEnableLearn=true;
}
void CBPNetDlg::Oninputnetdata()
{
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_INPUTNET = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd,IDC_EDIT42);
::SetWindowText (hWnd,m_INPUTNET);
}
else
{
return;
}
INPUTNETWEIGHT=TRUE;
}
void CBPNetDlg::Oninputfangzhendata()
{
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_INPUTFANGZHEN = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd,IDC_EDIT43);
::SetWindowText (hWnd,m_INPUTFANGZHEN);
}
else
{
return;
}
INPUTNETEMULATION=TRUE;
}
void CBPNetDlg::OnchangeState()
{
m_bSimulateDataFlag = !m_bSimulateDataFlag;
if(m_bSimulateDataFlag)
{
// 程序处在数据仿真状态
// Disabled the following controls
/////////////////////////////////////////////////////////////////////
(CBPNetDlg *)GetDlgItem(IDC_EDIT31)->EnableWindow(FALSE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT32)->EnableWindow(FALSE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT33)->EnableWindow(FALSE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT34)->EnableWindow(FALSE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT35)->EnableWindow(FALSE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT36)->EnableWindow(FALSE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT37)->EnableWindow(FALSE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT38)->EnableWindow(FALSE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT39)->EnableWindow(FALSE);
// (CBPNetDlg *)GetDlgItem(IDC_EDIT40)->EnableWindow(FALSE);
// (CBPNetDlg *)GetDlgItem(IDC_EDIT41)->EnableWindow(FALSE);
(CBPNetDlg *)GetDlgItem(IDC_LEARN)->EnableWindow(FALSE);
// Enabled the following controls
/////////////////////////////////////////////////////////////////////
(CBPNetDlg *)GetDlgItem(IDC_EDIT42)->EnableWindow(TRUE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT43)->EnableWindow(TRUE);
(CBPNetDlg *)GetDlgItem(IDC_OUTPUT)->EnableWindow(TRUE);
}
else
{
// 程序处在样本训练状态
(CBPNetDlg *)GetDlgItem(IDC_EDIT31)->EnableWindow(TRUE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT32)->EnableWindow(TRUE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT33)->EnableWindow(TRUE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT34)->EnableWindow(TRUE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT35)->EnableWindow(TRUE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT36)->EnableWindow(TRUE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT37)->EnableWindow(TRUE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT38)->EnableWindow(TRUE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT39)->EnableWindow(TRUE);
// (CBPNetDlg *)GetDlgItem(IDC_EDIT40)->EnableWindow(TRUE);
// (CBPNetDlg *)GetDlgItem(IDC_EDIT41)->EnableWindow(TRUE);
(CBPNetDlg *)GetDlgItem(IDC_LEARN)->EnableWindow(TRUE);
// Enabled the following controls
/////////////////////////////////////////////////////////////////////
(CBPNetDlg *)GetDlgItem(IDC_EDIT42)->EnableWindow(FALSE);
(CBPNetDlg *)GetDlgItem(IDC_EDIT43)->EnableWindow(FALSE);
(CBPNetDlg *)GetDlgItem(IDC_OUTPUT)->EnableWindow(FALSE);
}
}
BOOL CBPNetDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//
// m_fntOk.CreateFont(MulDiv(38,GetDC()->GetDeviceCaps(LOGPIXELSY),72),
// 0,0,0,FW_NORMAL,0,0,0,ANSI_CHARSET,OUT_STROKE_PRECIS,
// CLIP_STROKE_PRECIS,DRAFT_QUALITY,VARIABLE_PITCH|FF_SWISS,_T("Arial"));
//
// //设置ok按钮的字体
// CWnd* pWnd = GetDlgItem(IDC_STATIC_TITLE);
// pWnd->SetFont(&m_fntOk);// Set small icon
m_eta=eta;
m_alpha=alpha;
m_error=maxe;
m_maxnum=cnt_num;
m_ninattr=ninattr;
m_noutattr=noutattr;
m_nhlayer=nhlayer;
m_nodehlayer=nsample;
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBPNetDlg::OnCancel()
{
CDialog::OnCancel();
CDialog::DestroyWindow();
}
void CBPNetDlg::OnDestroy()
{
CDialog::OnDestroy();
//delete this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -