资源简介
根据欧式距离 将随即生成的点进行自动分类 有界面

代码片段和文件信息
#include
#include
#include
#include
#include “math.h“
typedef struct CPoint{
unsigned int num;
double x;
double y;
}Cpoint ;
double Distance( Cpoint &Cpoint &);
bool Rw(CPoint &Cpoint &);
Cpoint ComputeCndt(Cpoint a[]int n);
bool Rw_k(Cpoint newd[]Cpoint oldd[]short Numk);
void initSumdot(short Numk);
void ChangeCntd(Cpoint newd[]Cpoint oldd[]short Numk);
CPoint Sumdot[30][500];
short count[30];
CPoint Clscntdt[30];
int main()
{
CPoint Srandot[500];
Cpoint oldd[30];
int Rdot1Rdot2;
srand( (unsigned)time( NULL ) );
short K;
cout<<“要分几类:(0~30)“< cin>>K;
initSumdot(K);
//初始化随机数据
for (int i=0;i<500;i++)
{
Srandot[i].num=i;
Srandot[i].x=rand()%1000;//
Srandot[i].y=1000*rand()/RAND_MAX;
}
for (i=0;i<500;i++)
{
cout< }
//初始化中心点
for(i=0;i {
Rdot1=rand()%500;
Rdot2=rand()%500;
while(Rdot1==Rdot2)
{
Rdot2=rand()%500;
}
Clscntdt[i]=Srandot[Rdot1];
oldd[i]=Srandot[Rdot2];
count[i]=0;
}
double Dsts[30]tem=0;
int m=0;
short num=0;
while(Rw_k(Clscntdt olddK))
{
int j;
initSumdot(K);
ChangeCntd(ClscntdtolddK);
for (i=0;i {
count[i]=0;
}
for( j=0;j<500;j++)
{
for(int i=0;i {
Dsts[i]=Distance(Srandot[j]oldd[i]);
}
tem=Dsts[0];
for(i=0;i {
if (tem>=Dsts[i])
{
tem=Dsts[i];
num=i;
}
}
Sumdot[num][count[num]]=Srandot[j];
count[num]++;
}
//计算中心点
for ( m=0;m {
Clscntdt[m].num=Sumdot[m][0].num;
for (int i=0;i {
Clscntdt[m].x+=Sumdot[m][i].x;
Clscntdt[m].y+=Sumdot[m][i].y;
}
if(count[m]!=0){
Clscntdt[m].x/=count[m];
Clscntdt[m].y/=count[m];}
}
}
for(i=0;i {
cout< cout< }
return 0;
}
double Distance( Cpoint &aCpoint &b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool Rw(CPoint &aCpoint &b)
{
if(a.x!=b.x || a.y!=b.y )
return 1;
else return 0;
}
bool Rw_k(Cpoint newd[]Cpoint oldd[]short Numk)
{
for (int i=0;i {
if (Rw(newd[i]oldd[i]))
return 1;
else return 0;
}
}
void ChangeCntd(Cpoint newd[]Cpoint oldd[]short Numk)
{
for(int i=0;i oldd[i]=newd[i];
}
void initSumdot(short Numk)
{
for (int i=0;i {
for (int j=0;j<500;j++)
{
Sumdot[i][j].x=0;
Sumdot[i][j].y=0;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 245853 2010-12-18 09:55 二维聚类分析\Debug\二维类分析.exe
文件 2725 2010-12-19 21:32 二维聚类分析\二维类分析.cpp
文件 3451 2010-12-16 20:28 二维聚类分析\二维类分析.dsp
文件 545 2010-12-16 20:28 二维聚类分析\二维类分析.dsw
文件 41984 2010-12-18 09:56 二维聚类分析\二维类分析.ncb
文件 48640 2010-12-18 09:56 二维聚类分析\二维类分析.opt
文件 768 2010-12-18 09:55 二维聚类分析\二维类分析.plg
目录 0 2010-12-18 18:35 二维聚类分析\Debug
目录 0 2010-12-18 18:38 二维聚类分析
----------- --------- ---------- ----- ----
343966 9
- 上一篇:计算机算法分析试卷两套有答案
- 下一篇:统一用户及权限管理系统需求分析
相关资源
- 模糊聚类分析问题试验论文及源代码
- 聚类分析在股市中的应用
- 聚类分析与模糊聚类的两本书籍
- LBP+直方图与PCA+的欧式距离的人脸识别
- 聚类分析、机器学习及数据挖掘中常
- 超详细学习报告资料模糊理论基础
- powermarker V3.25
- SPSS教程-聚类分析-附操作
- 多元统计分析 聚类分析 ppt
- 多元统计分析聚类分析
- spass聚类分析与判别分析
- 基于欧式距离模板匹配的识别手写体
- 数学建模——判别分析 灰色理论 聚
- 基于时间序列聚类分析的股票数据 分
- 模糊聚类分析的应用论文整理
- 帧差欧式距离提取关键帧.rar
- R语言实现聚类分析、PCA实现与应用
- 数理统计大作业.pdf
- 基于K均值的文本聚类分析
- 2017B“拍照赚钱”的任务定价
- 模糊聚类分析在数据挖掘中的应用研
- SPSS视频教程6——聚类分析
- Data clustering theory algorithms and applicat
- Data clustering algorithms and application
- GeoDa使用手册中文版
- 基于遗传算法的聚类分析论文
- 聚类分析聚类算法综述ppt
- 基于 K-means 聚类算法的图像区域分割
- 论文研究-基于模糊聚类分析的客户分
- 划分聚类分析: K均值和基于中心点的
评论
共有 条评论