【文件属性】:
文件名称:k-mean聚类算法实现
文件大小:837B
文件格式:RAR
更新时间:2013-10-12 05:52:19
k-mean
c++实现k-mean算法#include
#include
#include
#include
#include
// FUNCTION PROTOTYPES
// DEFINES
#define SUCCESS 1
#define FAILURE 0
#define TRUE 1
#define FALSE 0
#define MAXVECTDIM 20
#define MAXPATTERN 20
#define MAXCLUSTER 10
char *f2a(double x, int width){
char cbuf[255];
char *cp;
int i,k;
int d,s;
cp=fcvt(x,width,&d,&s);
if (s) {
strcpy(cbuf,"-");
}
else {
strcpy(cbuf," ");
} /* endif */
if (d>0) {
for (i=0; i[%f,%f]\n", cl,Cluster[cl].Center[0],Cluster[cl].Center[1]);
} /* endfor */
}
void System::SaveClusters(char *fname){
}
void main(int argc, char *argv[]) {
System kmeans;
if (argc<2) {
printf("USAGE: KMEANS PATTERN_FILE\n");
exit(0);
}
if (kmeans.LoadPatterns(argv[1])==FAILURE ){
printf("UNABLE TO READ PATTERN_FILE:%s\n",argv[1]);
exit(0);
}
kmeans.InitClusters();
kmeans.RunKMeans();
kmeans.ShowClusters();
}
【文件预览】:
k_means.m