⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 最近邻法分类器dlg.cpp

📁 本程序是一个最近邻分类算法的演示程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	}
}

void CMyDlg::OnClass33() 
{
	// TODO: Add your command handler code here
	m_l.ModifyStyle(0,LVS_OWNERDRAWFIXED|WS_VISIBLE );
    CDialogkk dlg;
	if(dlg.DoModal()==IDOK)
	{
	/////////////////////////////////////////////////////
		k=dlg.m_k1;
		k1=dlg.m_k2;
	//////////////////////////////////////////////////////
         int i=0;int count1=0,count2=0,count3=0,rjcount1=0,rjcount2=0,rjcount3=3;
		////////////////////////////////////
		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;int h;
		  for( h=0;h<k;h++)
		  {
             if(h<120)
			 {
			  if(c1[r1]<c2[r2])
			 {
				 r1++;
			 }
             if(c2[r2]<c1[r1])
			 {
				 r2++;
			 }
			 if(c1[r1]==c2[r2])
			 {
				 r1++;r2++;h++;
			 }
			 }
			 else
			 {
				 r2++;
			 }
         }
		  if(r1<k1&&r2<k1)rjcount1++;
		  if(r2>=k1)count1++;
		  r1=0;r2=0;r3=0;
         for(h=0;h<k;h++)
		  {
             if(h<120)
			 {
			  if(c1[r1]<c3[r3])
			  {
				 r1++;
			  }
              if(c3[r3]<c1[r1])
			  {
				 r3++;
			  }
              if(c1[r1]==c3[r3])
			  {
				 r1++;r3++;h++;
			  }
			}
			 else
			 {
				 r3++;
			 }
         }
		  if(r1<k1&&r3<k1)rjcount2++;
		  if(r3>=k1)count2++;
		 
		}
		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;int h;
		  for(h=0;h<k;h++)
		  {
             if(h<130)
			 {
			  if(c1[r1]<c2[r2])
			 {
				 r1++;
			 }
             if(c2[r2]<c1[r1])
			 {
				 r2++;
			 }
			 }
			 else
				 r1++;
         }
		  if(r1<k1&&r2<k1)rjcount1++;
		  if(r1>=k1)count1++;
		  r1=0;r2=0;r3=0;
         for( h=0;h<k;h++)
		  {
             if(h<130)
			 {
			 if(c2[r2]<c3[r3])
			 {
				 r2++;
			 }
             if(c3[r3]<c2[r2])
			 {
				 r3++;
			 }
			 }
			 else
				 r3++;
         }
		  if(r2<k1&&r3<k1)rjcount3++;
		  if(r3>=k1)count3++;
		}
		/////////////////////////////////
		 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;int h;
		  for(h=0;h<k;h++)
		  {
             if(c1[r1]<c3[r3])
			 {
				 r1++;
			 }
             if(c3[r3]<c1[r1])
			 {
				 r3++;
			 }
         }
		  if(r1<k1&&r3<k1)rjcount2++;
		  if(r1>=k1)count2++;
		  r1=0;r2=0;r3=0;
         for(h=0;h<k;h++)
		  {
             if(c2[r2]<c3[r3])
			 {
				 r2++;
			 }
             if(c3[r3]<c2[r2])
			 {
				 r3++;
			 }
         }
		  if(r2<k1&&r3<k1)rjcount3++;
		  if(r2>=k1)count3++;
		}
	///////////////////////////////////////////////////////
    f1=false;f2=false;f3=true;

	CString ttemp1,ttemp2;
	ttemp1="(K,K`)NNR分类法,k=";
    ttemp2.Format("%d", k);
    ttemp1=ttemp1+ttemp2+", k`=";
    ttemp2.Format("%d", k1);
    ttemp1=ttemp1+ttemp2;
    strcpy(m_c1.mychar,ttemp1);
	/////////////////////////////////////
    m_l.SetItemText (0, 0, "准确率:");
    m_l.SetItemText (1, 0, "错误率:");
    m_l.SetItemText (2, 0, "拒判率:");
	/////////////////////////////////////
	CString li;
	double tt;
	tt=(double)(count1)/200;
   li.Format("%3.4f",tt*100);
   li=li+"%";
m_l.SetItemText (1, 1, li);
	tt=(double)(count2)/200;
   li.Format("%3.4f",tt*100);
   li=li+"%";
m_l.SetItemText (1, 2, li);
	tt=(double)(count3)/200;
   li.Format("%3.4f",tt*100);
   li=li+"%";
m_l.SetItemText (1, 3, li);
tt=(double)(rjcount1)/200;
   li.Format("%3.4f",tt*100);
   li=li+"%";
m_l.SetItemText (2, 1, li);
tt=(double)(rjcount2)/200;
   li.Format("%3.4f",tt*100);
   li=li+"%";
m_l.SetItemText (2, 2, li);
tt=(double)(rjcount3)/200;
   li.Format("%3.4f",tt*100);
   li=li+"%";
m_l.SetItemText (2, 3, li);
tt=(double)(200-rjcount1-count1)/200;
   li.Format("%3.4f",tt*100);
   li=li+"%";
m_l.SetItemText (0, 1, li);
tt=(double)(200-rjcount2-count2)/200;
   li.Format("%3.4f",tt*100);
   li=li+"%";
m_l.SetItemText (0, 2, li);
tt=(double)(200-rjcount3-count3)/200;
   
   li.Format("%3.4f",tt*100);
   li=li+"%";
m_l.SetItemText (0, 3, li);

	//////////////////////////////////////
	CRect rectldj; GetDlgItem(IDC_STATIC3)->GetWindowRect(rectldj);ScreenToClient(rectldj);InvalidateRect(rectldj,true);
    }
}

void CMyDlg::OnClass41() 
{
	// TODO: Add your command handler code here
	
}

void CMyDlg::OnClass42() 
{
	// TODO: Add your command handler code here
	CDialogs1 dlg;
	
	int i=0;
	for(i=0;i<240;i++)
	{
		*(dlg.onep+i)=*(onep+i);
	}
for(i=0;i<260;i++)
	{
		*(dlg.towp+i)=*(towp+i);
	}
for(i=0;i<300;i++)
	{
		*(dlg.threep+i)=*(threep+i);
	}
for(i=0;i<600;i++)
	{
		*(dlg.test+i)=*(test+i);
	}
dlg.DoModal();
}

void CMyDlg::OnClass43() 
{
	// TODO: Add your command handler code here
	CDialogs3 dlg;
	
	int i=0;
	for(i=0;i<240;i++)
	{
		*(dlg.onep+i)=*(onep+i);
	}
for(i=0;i<260;i++)
	{
		*(dlg.towp+i)=*(towp+i);
	}
for(i=0;i<300;i++)
	{
		*(dlg.threep+i)=*(threep+i);
	}
for(i=0;i<600;i++)
	{
		*(dlg.test+i)=*(test+i);
	}
dlg.m_b1.down =true;
dlg.DoModal();
}

void CMyDlg::OnClass44() 
{
	// TODO: Add your command handler code here
	CDialog34 dlg;dlg.m_b1.down=true;
	dlg.DoModal();
}
void CMyDlg::Seticon()
{
    HINSTANCE hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_ICON12),
													RT_GROUP_ICON);
	Sicon1= (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(IDI_ICON12), IMAGE_ICON, 32, 32, 0);
     hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_ICON13),
													RT_GROUP_ICON);
	Sicon2= (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(IDI_ICON13), IMAGE_ICON, 32, 32, 0);
 hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_ICON14),
													RT_GROUP_ICON);
	Sicon3= (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(IDI_ICON14), IMAGE_ICON, 32, 32, 0);
 hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_ICON15),
													RT_GROUP_ICON);
	Sicon4= (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(IDI_ICON15), IMAGE_ICON, 32, 32, 0);
hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_ICON5),
													RT_GROUP_ICON);
	sion1= (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(IDI_ICON5), IMAGE_ICON, 32, 32, 0);
hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_ICON6),
													RT_GROUP_ICON);
	sion2= (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(IDI_ICON6), IMAGE_ICON, 32, 32, 0);
hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_ICON7),
													RT_GROUP_ICON);
	sion3= (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(IDI_ICON7), IMAGE_ICON, 32, 32, 0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -