test_contree.c
来自「Solaris环境下的数据挖掘算法:birch聚类算法。该算法适用于对大量数据的」· C语言 代码 · 共 120 行
C
120 行
/****************************************************************File Name: phase3.C Author: Tian Zhang, CS Dept., Univ. of Wisconsin-Madison, 1995 Copyright(c) 1995 by Tian Zhang All Rights ReservedPermission to use, copy and modify this software must be grantedby the author and provided that the above copyright notice appear in all relevant copies and that both that copyright notice and this permission notice appear in all relevant supporting documentations. Comments and additions may be sent the author at zhang@cs.wisc.edu.******************************************************************/#include "global.h"#include "util.h"#include "vector.h"#include "rectangle.h"#include "cfentry.h"#include "cutil.h"#include "parameter.h"#include "status.h"#include "cftree.h"#include "contree.h"#include "hierarchy.h"#include "clarans.h"#include "lloyd.h"#include "kmeans.h"#include "phase3.h"void BirchPhase3(Stat **Stats){char tmpname[MAX_NAME];ofstream tmpfile;int i,j,k;// start test contree.*ConNode *contree=Stats[0]->NewRoot->Copy(Stats[0]);contree->Print_Summary(cout);contree->Print_Tree(0,cout);cout<<"HERE\n";contree->Connect(Stats[0]);contree->Print_Summary(cout);contree->Print_Tree(0,cout);// end test contree.*Entry *tmpents = new Entry[Paras->ntrees]; for (i=0; i<Paras->ntrees; i++) tmpents[i].Init(Stats[i]->Dimension);for (i=0; i<Paras->ntrees; i++) { sprintf(tmpname,"%s-cluster",Stats[i]->name); tmpfile.open(tmpname); Stats[i]->Phase=3; Stats[i]->NewRoot->free_nonleaf(Stats[i]); Stats[i]->NewRoot=NULL; Stats[i]->Entries=new Entry[Stats[i]->CurrEntryCnt]; for (j=0; j<Stats[i]->CurrEntryCnt; j++) Stats[i]->Entries[j].Init(Stats[i]->Dimension); j=k=0; Stats[i]->OldLeafHead=Stats[i]->NewLeafHead; while (Stats[i]->NextEntryFreeOldLeafHead(j,tmpents[i])!=FALSE) Stats[i]->Entries[k++]=tmpents[i]; Stats[i]->OldLeafHead=Stats[i]->NewLeafHead=NULL; if (k!=Stats[i]->CurrEntryCnt) print_error(Stats[i]->name,"Entry number not matching"); if (Stats[i]->K==0 && Stats[i]->CurFt>Stats[i]->Ft) Paras->logfile<<Stats[i]->name<<":"<<"CurFt>EndFt"<<endl; else if (Stats[i]->K!=0 && Stats[i]->K>Stats[i]->CurrEntryCnt) Paras->logfile<<Stats[i]->name<<":"<<"K>CurEntryCnt"<<endl; else { Paras->logfile<<Stats[i]->name<<":" <<"CurFt<EndFt or K<CurrEntryCnt"<<endl; switch (Stats[i]->Gtype) { case HIERARCHY0:Hierarchy0(Stats[i]->CurrEntryCnt,Stats[i]->K,&(Stats[i]->Entries),Stats[i]->GDtype,Stats[i]->Ftype,Stats[i]->Ft); break; case HIERARCHY1:Hierarchy1(Stats[i]->CurrEntryCnt,Stats[i]->K,&(Stats[i]->Entries),Stats[i]->GDtype,Stats[i]->Ftype,Stats[i]->Ft); break; case CLARANS0: Clarans0(Stats[i]->CurrEntryCnt,Stats[i]->K,Stats[i]->Entries); break; case CLARANS1: Clarans1(Stats[i]->CurrEntryCnt,Stats[i]->K,Stats[i]->Entries,Stats[i]->GDtype, Stats[i]->Qtype); break; case LLOYD: Lloyd(Stats[i]->CurrEntryCnt,&(Stats[i]->Entries)); break; case KMEANS: Kmeans(Stats[i]->CurrEntryCnt,&(Stats[i]->Entries)); break; default: print_error("BirchPhase3","Invalid global algorithm"); break; } } Paras->logfile<<Stats[i]->name<<":"<<"Quality of Phase3 " <<Quality(Stats[i]->Qtype,Stats[i]->CurrEntryCnt,Stats[i]->Entries)<<endl; for (j=0; j<Stats[i]->CurrEntryCnt; j++) tmpfile<<Stats[i]->Entries[j]<<endl; tmpfile.close(); }delete [] tmpents;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?