📄 dlgbprem.cpp
字号:
// DlgBPRem.cpp : implementation file
//
#include "stdafx.h"
#include "ANN.h"
#include "DlgBPRem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern tx1[4][4],ty1[3];
extern tx2[4][4],ty2[3];
extern tx3[4][4],ty3[3];
extern double W[16][8]; //输入层到中间层的连接权
extern double V[8][3]; //中间层到输出层的连接权
extern double t1[8]; //中间层的阈值
extern double t2[3]; //输出层的阈值
/////////////////////////////////////////////////////////////////////////////
// CDlgBPRem dialog
CDlgBPRem::CDlgBPRem(CWnd* pParent /*=NULL*/)
: CDialog(CDlgBPRem::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgBPRem)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDlgBPRem::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgBPRem)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgBPRem, CDialog)
//{{AFX_MSG_MAP(CDlgBPRem)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON_rem, OnBUTTONrem)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgBPRem message handlers
void CDlgBPRem::OnButton1()
{
// TODO: Add your control notification handler code here
int i,j,t,nID;
CString s;
nID=IDC_EDIT1;
for( i=0; i<4; i++){
for( j=0; j<4; j++){
s.Format("%d",tx1[i][j]);
this->SetDlgItemText(nID+4*i+j,s);
}
}
nID=IDC_EDIT17;
for( t=0; t<3; t++){
s.Format("%d",ty1[t]);
this->SetDlgItemText(nID+t,s);
}
for( t=3; t<6; t++){
this->SetDlgItemText(nID+t,"");
}
CButton *pBtn;
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_rem);
pBtn->EnableWindow(TRUE);
}
void CDlgBPRem::OnButton2()
{
// TODO: Add your control notification handler code here
int i,j,t,nID;
CString s;
nID=IDC_EDIT1;
for( i=0; i<4; i++){
for( j=0; j<4; j++){
s.Format("%d",tx2[i][j]);
this->SetDlgItemText(nID+4*i+j,s);
}
}
nID=IDC_EDIT17;
for( t=0; t<3; t++){
s.Format("%d",ty2[t]);
this->SetDlgItemText(nID+t,s);
}
for( t=3; t<6; t++){
this->SetDlgItemText(nID+t,"");
}
CButton *pBtn;
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_rem);
pBtn->EnableWindow(TRUE);
}
void CDlgBPRem::OnButton3()
{
// TODO: Add your control notification handler code here
int i,j,t,nID;
CString s;
nID=IDC_EDIT1;
for( i=0; i<4; i++){
for( j=0; j<4; j++){
s.Format("%d",tx3[i][j]);
this->SetDlgItemText(nID+4*i+j,s);
}
}
nID=IDC_EDIT17;
for( t=0; t<3; t++){
s.Format("%d",ty3[t]);
this->SetDlgItemText(nID+t,s);
}
for( t=3; t<6; t++){
this->SetDlgItemText(nID+t,"");
}
CButton *pBtn;
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_rem);
pBtn->EnableWindow(TRUE);
}
void CDlgBPRem::OnBUTTONrem()
{
// TODO: Add your control notification handler code here
CButton *pBtn;
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_rem);
pBtn->EnableWindow(FALSE);
int x[16];
double bj[8]; //中间层的输出
double ct[3]; //输出层的输出
double y[16]; //临时数组
double xy;
int i,j,t,n,p,q;
n=16; p=8; q=3;
CString s;
//获取输入值
for(i=0; i<n; i++){
this->GetDlgItemText(IDC_EDIT1+i,s);
sscanf(s,"%d",&x[i]);
}
//计算中间层的激活值;
for(j=0; j<p; j++){
y[j]=0;
}
for(j=0; j<p; j++){
for(i=0; i<n; i++){
xy=W[i][j]*x[i];
y[j]=y[j]+xy;
}
}
//计算中间层的输出值;
for(j=0; j<p; j++){
y[j]=y[j]-t1[j];
bj[j]=1/( 1+exp(-y[j]) );
}
//计算输出层的激活值;
for(t=0; t<q; t++){
y[t]=0;
}
for(t=0; t<q; t++){
for(j=0; j<p; j++ ){
xy=V[j][t]*bj[j];
y[t]=y[t]+xy;
}
}
//计算输出层的输出值;
for(t=0; t<q; t++){
y[t]=y[t]-t2[t];
ct[t]=1/( 1+exp(-y[t]) );
}
int nID=IDC_EDIT20;
for(t=0; t<q; t++){
s.Format("%f",ct[t]);
this->SetDlgItemText(nID+t,s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -