www.pudn.com > K-Means动态聚类算法源程序 .zip > KMEANS.CPP
/**************************************************************************** * * * KMEANS * * * *****************************************************************************/ #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){ } 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(); }