?? 最近鄰法分類(lèi)器dlg.cpp
字號(hào):
int x1,x2,y1,y2;
x1=*(onep+0);x2=*(test+2*i);y1=*(onep+1);y2=*(test+2*i+1);
c1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
for(j=1;j<120;j++)
{
x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(c1>temp)
{c1=temp;
}
}
x1=*(towp+0);x2=*(test+2*i);y1=*(towp+1);y2=*(test+2*i+1);
c2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
for(j=1;j<130;j++)
{
x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(c2>temp)
{c2=temp;
}
}
x1=*(threep+0);x2=*(test+2*i);y1=*(threep+1);y2=*(test+2*i+1);
c3=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
for(j=1;j<150;j++)
{
x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(c3>temp)
{c3=temp;
}
}
if((c1>c2)||(c1>c3))count++;
}
int ty=0;
/////////////////////////////////////////////////////////////////////////
for( i=100;i<200;i++)
{
int c1,c2,c3;
int j=1;
int x1,x2,y1,y2;
x1=*(onep+0);x2=*(test+2*i);y1=*(onep+1);y2=*(test+2*i+1);
c1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
for(j=1;j<120;j++)
{
x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(c1>temp)
{c1=temp;
}
}
x1=*(towp+0);x2=*(test+2*i);y1=*(towp+1);y2=*(test+2*i+1);
c2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
for(j=1;j<130;j++)
{
x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(c2>temp)
{c2=temp;
}
}
x1=*(threep+0);x2=*(test+2*i);y1=*(threep+1);y2=*(test+2*i+1);
c3=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
for(j=1;j<150;j++)
{
x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(c3>temp)
{c3=temp;
}
}
if((c1<c2)||(c2>c3))count++;
}
//////////////////////////////////////////
ty=0;
for( i=200;i<300;i++)
{
int c1,c2,c3;
int j=1;
int x1,x2,y1,y2;
x1=*(onep+0);x2=*(test+2*i);y1=*(onep+1);y2=*(test+2*i+1);
c1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
for(j=1;j<120;j++)
{
x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(c1>temp)
{
c1=temp;
}
}
x1=*(towp+0);x2=*(test+2*i);y1=*(towp+1);y2=*(test+2*i+1);
c2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
for(j=1;j<130;j++)
{
x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(c2>temp)
{c2=temp;
}
}
x1=*(threep+0);x2=*(test+2*i);y1=*(threep+1);y2=*(test+2*i+1);
c3=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
for(j=1;j<150;j++)
{
x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(c3>temp)
{c3=temp;
}
}
if((c1<c3)||(c2<c3))count++;
}
double tt;
tt=((float)count)/300;
CRect rectldj;
GetDlgItem(IDC_STATIC3)->GetWindowRect(rectldj);ScreenToClient(rectldj);
f1=true;f2=false;f3=false;
strcpy(m_c1.mychar,"1-NNR分類(lèi)法");
CString temp1,temp,temp2;
temp="錯(cuò)誤率: ";
temp1.Format("%d", int(tt*100));
int t=int(tt*10000-(int(tt*100))*100+0.5);
temp2.Format("%d", t);
temp=temp+temp1+"."+temp2+"%";
strcpy(m_c1.mychar,"1-NNR分類(lèi)法");
strcpy(m_c3.mychar,temp);
temp="正確率: ";
temp1.Format("%d", int((1-tt)*100));
t=int((1-tt)*10000-(int((1-tt)*100))*100+0.5);
temp2.Format("%d", t);
temp=temp+temp1+"."+temp2+"%";
strcpy(m_c2.mychar,temp);
strcpy(m_c4.mychar,"拒判率:0%");
InvalidateRect(rectldj,true);
}
void CMyDlg::OnClass32()
{
// TODO: Add your command handler code here
m_l.ModifyStyle(WS_VISIBLE,0);
CDialogk dlg;
if(dlg.DoModal()==IDOK)
{
//////////////////////////////////
k=dlg.m_k;
int i=0;int count=0;
////////////////////////////////////
for(i=0;i<100;i++)
{
int l;
int c1[120];
int c2[130];
int c3[150];
int j=0;
for(j=0;j<120;j++)
{
int x1,x2,y1,y2;
x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
*(c1+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
for(l=0;l<k;l++)
{
for(j=119;j>l;j--)
{
if(c1[j]<c1[j-1])
{
int temp=c1[j-1];
c1[j-1]=c1[j];
c1[j]=temp;
}
}
}
for(j=0;j<130;j++)
{
int x1,x2,y1,y2;
x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
*(c2+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
for(l=0;l<k;l++)
{
for(j=129;j>l;j--)
{
if(c2[j]<c2[j-1])
{
int temp=c2[j-1];
c2[j-1]=c2[j];
c2[j]=temp;
}
}
}
for(j=0;j<150;j++)
{
int x1,x2,y1,y2;
x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
*(c3+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
for(l=0;l<k;l++)
{
for(j=149;j>l;j--)
{
if(c3[j]<c3[j-1])
{
int temp=c3[j-1];
c3[j-1]=c3[j];
c3[j]=temp;
}
}
}
int r1=0,r2=0,r3=0;
for(int h=0;h<k;h++)
{
if(h<120)
{
if(c1[r1]<c2[r2]&&c1[r1]<c3[r3])
{
r1++;
}
if(c2[r2]<c1[r1]&&c2[r2]<c3[r3])
{
r2++;
}
if(c3[r3]<c1[r1]&&c2[r2]>c3[r3])
{
r3++;
}
}
else
{
if(h<130)
{
if(c2[r2]<c3[r3])
{
r2++;
}
if(c2[r2]>c3[r3])
{
r3++;
}
}
else
r3++;
}
}
if(r1<r2||r1<r3)count++;
}
int tt3=0;
/////////////////////////////////
for(i=100;i<200;i++)
{
int l;
int c1[120];
int c2[130];
int c3[150];
int j=0;
for(j=0;j<120;j++)
{
int x1,x2,y1,y2;
x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
*(c1+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
for(l=0;l<k;l++)
{
for(j=119;j>l;j--)
{
if(c1[j]<c1[j-1])
{
int temp=c1[j-1];
c1[j-1]=c1[j];
c1[j]=temp;
}
}
}
for(j=0;j<130;j++)
{
int x1,x2,y1,y2;
x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
*(c2+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
for(l=0;l<k;l++)
{
for(j=129;j>l;j--)
{
if(c2[j]<c2[j-1])
{
int temp=c2[j-1];
c2[j-1]=c2[j];
c2[j]=temp;
}
}
}
for(j=0;j<150;j++)
{
int x1,x2,y1,y2;
x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
*(c3+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
for(l=0;l<k;l++)
{
for(j=149;j>l;j--)
{
if(c3[j]<c3[j-1])
{
int temp=c3[j-1];
c3[j-1]=c3[j];
c3[j]=temp;
}
}
}
int r1=0,r2=0,r3=0;
for(int h=0;h<k;h++)
{
if(h<120)
{
if(c1[r1]<c2[r2]&&c1[r1]<c3[r3])
{
r1++;
}
if(c2[r2]<c1[r1]&&c2[r2]<c3[r3])
{
r2++;
}
if(c3[r3]<c1[r1]&&c2[r2]>c3[r3])
{
r3++;
}
}
else
{
if(h<130)
{
if(c2[r2]<c3[r3])
{
r2++;
}
if(c2[r2]>c3[r3])
{
r3++;
}
}
else
r3++;
}
}
if(r2<r1||r2<r3)count++;
}
/////////////////////////////////
int tt5=0;
for(i=200;i<300;i++)
{
int l;
int c1[120];
int c2[130];
int c3[150];
int j=0;
for(j=0;j<120;j++)
{
int x1,x2,y1,y2;
x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
*(c1+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
for(l=0;l<k;l++)
{
for(j=119;j>l;j--)
{
if(c1[j]<c1[j-1])
{
int temp=c1[j-1];
c1[j-1]=c1[j];
c1[j]=temp;
}
}
}
for(j=0;j<130;j++)
{
int x1,x2,y1,y2;
x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
*(c2+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
for(l=0;l<k;l++)
{
for(j=129;j>l;j--)
{
if(c2[j]<c2[j-1])
{
int temp=c2[j-1];
c2[j-1]=c2[j];
c2[j]=temp;
}
}
}
for(j=0;j<150;j++)
{
int x1,x2,y1,y2;
x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
*(c3+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
for(l=0;l<k;l++)
{
for(j=149;j>l;j--)
{
if(c3[j]<c3[j-1])
{
int temp=c3[j-1];
c3[j-1]=c3[j];
c3[j]=temp;
}
}
}
int r1=0,r2=0,r3=0;
for(int h=0;h<k;h++)
{
if(h<120)
{
if(c1[r1]<c2[r2]&&c1[r1]<c3[r3])
{
r1++;
}
if(c2[r2]<c1[r1]&&c2[r2]<c3[r3])
{
r2++;
}
if(c3[r3]<c1[r1]&&c2[r2]>c3[r3])
{
r3++;
}
}
else
{
if(h<130)
{
if(c2[r2]<c3[r3])
{
r2++;
}
if(c2[r2]>c3[r3])
{
r3++;
}
}
else
r3++;
}
}
if(r3<r2||r3<r1)count++;
}
////////////////////////////////////
double tt;
tt=((float)count)/300+0.00005;
CRect rectldj;
GetDlgItem(IDC_STATIC3)->GetWindowRect(rectldj);ScreenToClient(rectldj);
f2=true;f1=false;f3=false;
CString ttemp1,ttemp2;
ttemp1="K-NNR分類(lèi)法,k=";
ttemp2.Format("%d", k);
ttemp1=ttemp1+ttemp2;
strcpy(m_c1.mychar,ttemp1);
CString temp1,temp,temp2;
temp="錯(cuò)誤率: ";
temp1.Format("%d", int(tt*100));
int t=int(tt*10000-(int(tt*100))*100);
temp2.Format("%d", t);
temp=temp+temp1+"."+temp2+"%";
tt=1-((float)count)/300+0.00005;
strcpy(m_c3.mychar,temp);
temp="正確率: ";
temp1.Format("%d", int((tt)*100));
t=int(tt*10000-(int(tt*100))*100);
temp2.Format("%d", t);
temp=temp+temp1+"."+temp2+"%";
strcpy(m_c2.mychar,temp);
strcpy(m_c4.mychar,"拒判率:0%");
InvalidateRect(rectldj,true);
/////////////////////////////////////////////
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -