dialogms.cpp
来自「该程序是一个对于一个对于以某一直线为边界的两类进行分类」· C++ 代码 · 共 675 行
CPP
675 行
// DialogMS.cpp : implementation file
//
#include "stdafx.h"
#include "线性分类器.h"
#include "DialogMS.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialogMS dialog
#include"MyProgressCtrl.h"
CDialogMS::CDialogMS(CWnd* pParent /*=NULL*/)
: CDialog(CDialogMS::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialogMS)
m_w1 = _T("");
m_w2 = _T("");
m_w4 = 0.0;
//}}AFX_DATA_INIT
}
void CDialogMS::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialogMS)
DDX_Control(pDX, IDC_BUTTON2, m_b);
DDX_Control(pDX, IDC_LIST1, m_l);
DDX_Text(pDX, IDC_EDIT1, m_w1);
DDX_Text(pDX, IDC_EDIT3, m_w2);
DDX_Text(pDX, IDC_EDIT4, m_w4);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialogMS, CDialog)
//{{AFX_MSG_MAP(CDialogMS)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
ON_EN_CHANGE(IDC_EDIT4, OnChangeEdit4)
ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
ON_EN_KILLFOCUS(IDC_EDIT3, OnKillfocusEdit3)
ON_EN_KILLFOCUS(IDC_EDIT4, OnKillfocusEdit4)
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialogMS message handlers
BOOL CDialogMS::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
mybitmap.LoadBitmap(IDB_BITMAP1);
m_l.SetExtendedStyle (LVS_OWNERDRAWFIXED);
CRect ClientRect;
int w;
GetDlgItem(IDC_LIST1)->GetClientRect(&ClientRect);
w=ClientRect.Width()+1-(5*ClientRect.Width()) / 6;
m_l.InsertColumn (0, " 记录号");
m_l.InsertColumn (1, " W1");
m_l.InsertColumn (2, " W2");
m_l.InsertColumn (3, "学习方式");
m_l.InsertColumn (4, "迭代次数");
m_l.InsertColumn (5, " 识别率");;
m_l.SetColumnWidth (0, (ClientRect.Width() / 6)-1);
m_l.SetColumnWidth (1, (ClientRect.Width() / 6)-1);
m_l.SetColumnWidth (2, (ClientRect.Width() / 6));
m_l.SetColumnWidth (3, (ClientRect.Width()/6)+2);
m_l.SetColumnWidth (4, ClientRect.Width()/6);
m_l.SetColumnWidth (5, w);
for(int i=0;i<5;i++)
{
m_l.InsertItem (i, " ");
}
m_w4=1.0;
m_w1="1";
m_w2="1";
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDialogMS::OnButton2()
{
// TODO: Add your control notification handler code here
CMyProgressCtrl myprogress;
AfxGetApp()->BeginWaitCursor();
CRect rect,rect1;
GetClientRect(rect);
int temp=rect.left+rect.Width()/2;
rect.left=temp-250;
rect.right=temp+250;
GetDlgItem(IDC_BUTTON2)->GetWindowRect(rect1);
ScreenToClient(rect1);
rect.top=rect1.top-50;
rect.bottom=rect.top+20;
myprogress.Create(WS_CHILD|WS_VISIBLE,rect,this,1820);
myprogress.SetRange(0,200);
myprogress.SetPos(10);
double w1,w2,w4;
w1=(double)atoi(m_w1);
w2=(double)atoi(m_w2);
w4=0;
if(w2<0)
{
w1=-w1;
w2=-w2;
w4=-w4;
}
double a=m_w4;
//////////////////////////////////////////////
BOOL ft=true;
bool fe=true;
int count=0;
int t=0;
while(fe)
{
ft=true;
for(int i=0;i<100;i++)
{
///////////////
if(i<50)
{
double xt,yt,z;
xt=((double)(*(onep+2*i)))/10;
yt=((double)(*(onep+2*i+1)))/10;
z=xt*w1+yt*w2+w4;
if(z<=0)
{
ft=false;
BOOL ft1=true;
w1=w1+a*xt;
w2=w2+a*yt;
w4=w4+a;
}
}
else
{
if(i>=50&&i<100)
{
double xt,yt,z;
xt=((double)(*(towp+2*(i-50))))/10;
yt=((double)(*(towp+2*(i-50)+1)))/10;
z=xt*w1+yt*w2+w4;
if(z>=0)
{
ft=false;
w1=w1-a*xt;
w2=w2-a*yt;
w4=w4-a;
}
}
}//
////////////////
}
if(ft)
{
fe=false;
}
count++;
}
/////////////////////////
myprogress.SetPos(50);
Sleep(500);
t=0;
for(int i1=0;i1<200;i1++)
{
double xt,yt,z;
if(i1<100)
{
xt=((double)(*(onetp+2*i1)))/10;
yt=((double)(*(onetp+2*i1+1)))/10;
if(w2>0)
{
z=w1*xt+w2*yt+w4;
}
else
{
z=-w1*xt-w2*yt-w4;
}
if(z<=0)
{
t++;
}
}
else
{
if(i1<200)
{
xt=((double)(*(towtp+2*(i1-100))))/10;
yt=((double)(*(towtp+2*(i1-100)+1)))/10;
if(w2>0)
{
z=w1*xt+w2*yt+w4;
}
else
{
z=-w1*xt-w2*yt-w4;
}
if(z>=0)
{
t++;
}
}
}
}
/////////////////////////
CString cc;
cc.Format("%d", count);
CString temp1;
double rate;
rate=((double)(200-t))/200;
int intn=int(rate*100);
temp1.Format("%d", intn);
temp1=temp1+".";
CString temp11;
int dot=int(rate*100000-intn*1000+0.5);
temp11.Format("%d", dot);
temp1=temp1+temp11+"%";
///////////////////////////////
m_l.SetItemText (0, 0, "1");
m_l.SetItemText (0, 1, m_w1);
m_l.SetItemText (0, 2, m_w2);
m_l.SetItemText (0, 3, "T1->T2");
m_l.SetItemText (0, 4, cc);
m_l.SetItemText (0, 5, temp1);
myprogress.SetPos(90);
Sleep(500);
//////////////////////////////////////////////
w1=(double)atoi(m_w1);
w2=(double)atoi(m_w2);
w4=0;
if(w2<0)
{
w1=-w1;
w2=-w2;
w4=-w4;
}
ft=true;
fe=true;
count=0;
t=0;
///////////////////////////
while(fe)
{
ft=true;
for(int i=0;i<100;i++)
{
///////////////
if(i<50)
{
double xt,yt,z;
xt=((double)(*(towp+2*i)))/10;
yt=((double)(*(towp+2*i+1)))/10;
z=xt*w1+yt*w2+w4;
if(z>=0)
{
ft=false;
BOOL ft1=true;
w1=w1-a*xt;
w2=w2-a*yt;
w4=w4-a;
}
}
else
{
if(i>=50&&i<100)
{
double xt,yt,z;
xt=((double)(*(onep+2*(i-50))))/10;
yt=((double)(*(onep+2*(i-50)+1)))/10;
z=xt*w1+yt*w2+w4;
if(z<=0)
{
ft=false;
w1=w1+a*xt;
w2=w2+a*yt;
w4=w4+a;
}
}
}//
////////////////
}
if(ft)
{
fe=false;
}
count++;
}
//////////////////////////////r
/////////////////////////
myprogress.SetPos(110);
Sleep(500);
t=0;
for(int i11=0;i11<200;i11++)
{
double xt,yt,z;
if(i11<100)
{
xt=((double)(*(onetp+2*i11)))/10;
yt=((double)(*(onetp+2*i11+1)))/10;
if(w2>0)
{
z=w1*xt+w2*yt+w4;
}
else
{
z=-w1*xt-w2*yt-w4;
}
if(z<=0)
{
t++;
}
}
else
{
if(i1<200)
{
xt=((double)(*(towtp+2*(i1-100))))/10;
yt=((double)(*(towtp+2*(i1-100)+1)))/10;
if(w2>0)
{
z=w1*xt+w2*yt+w4;
}
else
{
z=-w1*xt-w2*yt-w4;
}
if(z>=0)
{
t++;
}
}
}
}
/////////////////////////
CString cc1;
cc1.Format("%d", count);
CString temp21;
rate=((double)(200-t))/200;
intn=int(rate*100);
temp21.Format("%d", intn);
temp21=temp21+".";
CString temp211;
dot=int(rate*100000-intn*1000+0.5);
temp211.Format("%d", dot);
temp21=temp21+temp211+"%";
///////////////////////////////
m_l.SetItemText (1, 0, "2");
m_l.SetItemText (1, 1, m_w1);
m_l.SetItemText (1, 2, m_w2);
m_l.SetItemText (1, 3, "T2->T1");
m_l.SetItemText (1, 4, cc1);
m_l.SetItemText (1, 5, temp21);
myprogress.SetPos(140);
Sleep(500);
///////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
w1=(double)atoi(m_w1);
w2=(double)atoi(m_w2);
w4=0;ft=true;fe=true;count=0;
while(fe)
{
////////////////////////////////////////
for(int t=0;t<100;t++)
{
ft=true;
if(t%2==0)
{
double xt,yt,z;
xt=((double)(*(onep+t)))/10;
yt=((double)(*(onep+t+1)))/10;
z=xt*w1+yt*w2+w4;
if(z<=0)
{
ft=false;
w1=w1+a*xt;
w2=w2+a*yt;
w4=w4+a;
}
}
else
{
double xt,yt,z;
xt=((double)(*(towp+(t-1))))/10;
yt=((double)(*(towp+t)))/10;
z=xt*w1+yt*w2+w4;
if(z>=0)
{
ft=false;
w1=w1-a*xt;
w2=w2-a*yt;
w4=w4-a;
}
}
}
if(ft)
{
fe=false;
}
////////////////////////////////////////
count++;
}
//////////////////////////////
myprogress.SetPos(170);
Sleep(500);
t=0;
for(int i3=0;i3<200;i3++)
{
double xt,yt,z;
if(i3<100)
{
xt=((double)(*(onetp+2*i3)))/10;
yt=((double)(*(onetp+2*i3+1)))/10;
if(w2>0)
{
z=w1*xt+w2*yt+w4;
}
else
{
z=-w1*xt-w2*yt-w4;
}
if(z<=0)
{
t++;
}
}
else
{
if(i3<200)
{
xt=((double)(*(towtp+2*(i3-100))))/10;
yt=((double)(*(towtp+2*(i3-100)+1)))/10;
if(w2>0)
{
z=w1*xt+w2*yt+w4;
}
else
{
z=-w1*xt-w2*yt-w4;
}
if(z>=0)
{
t++;
}
}
}
}
CString cc3;
cc3.Format("%d", count);
CString temp3;
rate=((double)(200-t))/200;
intn=int(rate*100);
temp3.Format("%d", intn);
temp3=temp3+".";
CString temp31;
dot=int(rate*100000-intn*1000+0.5);
temp31.Format("%d", dot);
temp3=temp3+temp31+"%";
m_l.SetItemText (2, 0, "3");
m_l.SetItemText (2, 1, m_w1);
m_l.SetItemText (2, 2, m_w2);
m_l.SetItemText (2, 3, "T2->T1->T2");
m_l.SetItemText (2, 4, cc3);
m_l.SetItemText (2, 5, temp3);
myprogress.SetPos(200);
}
void CDialogMS::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
CString temp=m_w1;
UpdateData(true);
if((m_w1=="0")&&(m_w2=="0"))
{
m_w1=temp; UpdateData(false);
}
// TODO: Add your control notification handler code here
}
void CDialogMS::OnChangeEdit3()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
CString temp=m_w2;
UpdateData(true);
if((m_w1=="0")&&(m_w2=="0"))
{
m_w2=temp; UpdateData(false);
}
}
void CDialogMS::OnChangeEdit4()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
double tp=m_w4;
UpdateData(true);
if(m_w4==0)
{
m_w4=tp; UpdateData(false);
}
}
void CDialogMS::OnKillfocusEdit1()
{
// TODO: Add your control notification handler code here
if (m_w1.IsEmpty( ))
{
m_w1="1";UpdateData(false);
}
}
void CDialogMS::OnKillfocusEdit3()
{
// TODO: Add your control notification handler code here
if (m_w2.IsEmpty( ))
{
m_w2="0";UpdateData(false);
}
}
void CDialogMS::OnKillfocusEdit4()
{
// TODO: Add your control notification handler code here
if (m_w4==0)
{
m_w4=1;UpdateData(false);
}
}
BOOL CDialogMS::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetClientRect(rect);
//////////////////////////////////////////////////////
CDC memdc;
BITMAP bm1;
mybitmap.GetObject(sizeof(BITMAP),&bm1);
memdc.CreateCompatibleDC(pDC);
CBitmap* oldbitmap=memdc.SelectObject(&mybitmap);
int wide=rect.Width()/3;
int mheight=rect.Height()/3;
for (int j=0;j<3;j++)
{
for(int i=0;i<3;i++)
{
pDC->StretchBlt(rect.left,rect.top,wide,mheight,&memdc,0,0,bm1.bmWidth,bm1.bmHeight,SRCCOPY);
rect.left+= wide;
}
rect.left-=wide*3;
rect.top+=mheight;
}
return true;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?