亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? hierarchy.c

?? 經典的層次聚類算法Birch。在linux下運行通過
?? C
字號:
/****************************************************************File Name: hierarchy.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 <assert.h>#include "global.h"#include "util.h"#include "vector.h"#include "rectangle.h"#include "cfentry.h"#include "cutil.h"#include "parameter.h"#include "hierarchy.h"/* for MergeHierarchy use only */static void Update_Distance(int n1, int n2, int CurI, int NextI, 			    int n, int *checked, double *dist){int 	i, j;double  d1, d2;for (i=0; i<CurI; i++) {      if (checked[i]!=0) {	if (i!=NextI) {      		d1 = dist[i*n-i*(i+1)/2+CurI-i-1];      		if (i<NextI) d2 = dist[i*n-i*(i+1)/2+NextI-i-1];      		else d2 = dist[NextI*n-NextI*(NextI+1)/2+i-NextI-1];      		dist[i*n-i*(i+1)/2+CurI-i-1] = (n1*d1+n2*d2)/(n1+n2);      	}}}for (j=CurI+1; j<n; j++) {      if (checked[j]!=0) {	if (j!=NextI) {		d1 = dist[CurI*n-CurI*(CurI+1)/2+j-CurI-1];		if (j<NextI) d2 = dist[j*n-j*(j+1)/2+NextI-j-1];		else d2 = dist[NextI*n-NextI*(NextI+1)/2+j-NextI-1];		dist[CurI*n-CurI*(CurI+1)/2+j-CurI-1] = (n1*d1+n2*d2)/(n1+n2);      	}}}}/* for MergeHierarchy use only */static int Pick_One_Unchecked(int n, int *checked){int i,j = rand() % n;for (i=0;i<n;i++) 	if (checked[(i+j)%n]!=0) return (i+j)%n;return -1;}/* for MergeHierarchy use only */static int Nearest_Neighbor(int CurI, int n, int *checked, double *dist){int    i, imin=0;double d, dmin = HUGE;for (i=0;i<CurI;i++) {    if (checked[i]!=0){	d = dist[i*n-i*(i+1)/2+CurI-i-1];	if (d<dmin) { dmin=d; imin=i; }	}}for (i=CurI+1;i<n;i++) {    if (checked[i]!=0){	d = dist[CurI*n-CurI*(CurI+1)/2+i-CurI-1];	if (d<dmin) { dmin=d; imin=i; }	}}if (dmin<HUGE) return imin;else return -1;}/* for SplitHierarchy use only */static int Farthest_Merge(int chainptr, int *chain, double *dd) {if (chainptr<=0) return chainptr;double d, dmax = 0;int    i, imax = -1;for (i=0; i<=chainptr; i++) {	if (chain[i]<0) {		d = dd[-chain[i]-1];		if (d>dmax) {imax = i; dmax = d;}		}}return imax;}/* for SplitHierarchy use only */static int Largest_Merge(int chainptr, int *chain, Entry *cf, short ftype, double ft){for (int i=0; i<=chainptr; i++) {	if (chain[i]<0) {		if (cf[-chain[i]-1].Fitness(ftype)>ft)			return i;			}}return -1;}/*********************************************************************This is an O(n^2) algorithm, but works only for D2 and D4 due to the "REDUCIBILITY PROPERTY" that is given as below:if d(i,j) < p, d(i,k) > p, d(j,k) > p then d(i+j,k) > p.Algorithm:Part 1: MergeHierarchy:	form the complete hierarchy in O(n^2) time	step1: Pick any cluster i[1].	step2: Determine the chain i[2]=NN(i[1]), i[3]=NN(i[2]) ... 	       until i[k]=NN(i[k-1]) and i[k-1]=NN(i[k]), where NN 	       means nearest neighbor.	step3: Merge clusters i[k-1] and i[k].	step4: If more than 1 clusters left, goto step using i[k-2] 	       as start if (k-2>0), otherwise choose arbitrary i[1].Part 2: SplitHierarchy:	cut from the complete hierarchy in O(n^2) 		by number of clusters K, 		by the threshold Ft, 		by tree height H,		...*********************************************************************/void Hierarchy::MergeHierarchy(short gdtype,    // distance type			       int nentry,      // number of entries                               Entry *entries)  // array storing entries{if (gdtype!=D2 && gdtype!=D4) 	print_error("MergeHierarchy","only support distance D2 and D4");int 	i,j,n1,n2;int	CurI, PrevI, NextI;int 	uncheckcnt = nentry;int 	*checked = new int[nentry];for (i=0;i<nentry;i++) checked[i]=i+1;	// 0: invalid after being merged to other entries	// positive 1..nentry+1 :     original entries	// negative -1..-(nentry-1) : merged entries// get initial distancesdouble *dist=new double[nentry*(nentry-1)/2];for (i=0; i<nentry-1; i++)  for (j=i+1; j<nentry; j++) 	dist[i*nentry-i*(i+1)/2+j-i-1] = 		distance(gdtype,entries[i],entries[j]);	CurI = rand() % nentry;			// step1 chain[++chainptr]=CurI;while (uncheckcnt>1) {   if (chainptr==-1) {			// step4	chainptr++;  	chain[chainptr]=Pick_One_Unchecked(nentry,checked); 	}   if (chainptr>0) 	PrevI=chain[chainptr-1];   else PrevI=-1;   stopchain=FALSE;   while (stopchain==FALSE) {		// step2		CurI=chain[chainptr];	NextI = Nearest_Neighbor(CurI,nentry,checked,dist);	// it is impossible NextI be -1 because uncheckcnt>1	if (NextI==PrevI)	  stopchain = TRUE;	else {	  chain[++chainptr]=NextI;	  PrevI = CurI;	  }	} // end of while for step 2   step++;   ii[step] = checked[CurI];			// step3   jj[step] = checked[NextI];   if (CurI<NextI) 	dd[step] = dist[CurI*nentry-CurI*(CurI+1)/2+NextI-CurI-1];   else 	dd[step] = dist[NextI*nentry-NextI*(NextI+1)/2+CurI-NextI-1];   if (checked[CurI]>0) {	n1 = entries[CurI].n;	if (checked[NextI]>0) {		n2 = entries[NextI].n;   		cf[step].Add(entries[CurI],entries[NextI]);		}	else  {		n2 = cf[-checked[NextI]-1].n;		cf[step].Add(entries[CurI],cf[-checked[NextI]-1]);		}	}   else {	n1 = cf[-checked[CurI]-1].n;	if (checked[NextI]>0) {		n2 = entries[NextI].n;		cf[step].Add(cf[-checked[CurI]-1],entries[NextI]);		}	else {		n2 = cf[-checked[NextI]-1].n;		cf[step].Add(cf[-checked[CurI]-1],cf[-checked[NextI]-1]);		}	}   Update_Distance(n1,n2,CurI,NextI,nentry,checked,dist);   uncheckcnt--;   checked[CurI] = -(step+1);	       checked[NextI] = 0;   chainptr--; chainptr--;   } //end of while (uncheckcnt>1)if (checked) delete [] checked;if (dist) delete [] dist;// prepare for SplitHierarchystopchain = FALSE;chainptr = 0;chain[chainptr] = -(step+1);}short Hierarchy::SplitHierarchy(short option,short ftype,double ft){int i, j;switch (option) {case BY_THRESHOLD:	if (stopchain==TRUE) return FALSE;	i = Largest_Merge(chainptr,chain,cf,ftype,ft);	if (i!=-1) {j = -chain[i]-1;		    chain[i] = ii[j];		    chain[++chainptr]=jj[j];		    return TRUE;		    }	else {stopchain = TRUE; return FALSE;}	break;	case BY_KCLUSTERS:	if (chainptr==size) return FALSE;	i = Farthest_Merge(chainptr,chain,dd);	if (i!=-1) {j = -chain[i]-1;		    chain[i]=ii[j];		    chain[++chainptr]=jj[j];		    return TRUE;		    }        else return FALSE;	break;	}}double Hierarchy::MinFtMerged(short ftype){int MinI;double tmpFt, MinFt=HUGE_DOUBLE;for (int i=0; i<=chainptr; i++) {	if (chain[i]<0) {		tmpFt=cf[-chain[i]-1].Fitness(ftype);		if (tmpFt<MinFt) {MinFt=tmpFt; MinI=i;}		}	}// prepare for physically merging the MinI clusterstopchain=FALSE;chainptr=0;chain[0]=chain[MinI];return MinFt;}double Hierarchy::DistortionEdge(Entry *entries){double TotalDistort=0;for (int i=0; i<=chainptr; i++) {	if (chain[i]<0)		TotalDistort+=cf[-chain[i]-1].N()*cf[-chain[i]-1].Radius();	else TotalDistort+=entries[chain[i]-1].N()*entries[chain[i]-1].Radius();	}return TotalDistort;}double Hierarchy::NmaxFtMerged(short ftype){double NmaxFt;int    maxn;maxn = 0; NmaxFt=0;for (int i=0; i<=chainptr; i++) {	if (chain[i]<0 && cf[-chain[i]-1].N()>maxn) {		maxn = cf[-chain[i]-1].N();		NmaxFt = cf[-chain[i]-1].Fitness(ftype);		}	}return NmaxFt;}double Hierarchy::TotalFtDEdge(short ftype, short d, Entry *entries){double TotalFtD=0;for (int i=0; i<=chainptr; i++) {	if (chain[i]<0) 		TotalFtD+=pow(cf[-chain[i]-1].Fitness(ftype),1.0*d);	else TotalFtD+=pow(entries[chain[i]-1].Fitness(ftype),1.0*d);	}return TotalFtD;}/***********************************************************This is an O(n^3) algorithm, but works fine for all 5(D0,D1,D2,D3,D4) distance definitions.  It is used to make sure Hierarchy1 and Hierarchy0 can produce the same results for debugging purpose.************************************************************/void Hierarchy0(int &n, 	 // final number of clusters		const int K,     // final number of clusters		Entry **entries,		short GDtype,		short Ftype,		double Ft){if (n<=1) return;int 	i, j, imin, jmin, done;short  	*checked = new short[n];memset(checked,0,n*sizeof(short));	// 0: unchecked;	// -1: exceeds the given threshold if merged with nearest neighbor;	// -2: nonexistant after merging.double 	*dist = new double[n*(n-1)/2];double 	d, dmin;Entry 	tmpent;tmpent.Init((*entries)[0].sx.dim);dmin = HUGE;	// compute all initial distances and closest pairfor (i=0; i<n-1; i++)  for (j=i+1; j<n; j++) {	d = distance(GDtype,(*entries)[i],(*entries)[j]);	dist[i*n-i*(i+1)/2+j-i-1] = d;	if (d<dmin) {		dmin = d;		imin = i;		jmin = j;		}	}if (K==0) {// ****** case 1 ****** cluster by threshold ftdone = FALSE;while (done==FALSE) {	tmpent.Add((*entries)[imin],(*entries)[jmin]);	if (tmpent.Fitness(Ftype) < Ft) { 	// within the threshold		(*entries)[imin] += (*entries)[jmin];		checked[jmin] = -2;		for (i=0; i<imin; i++) {		   if (checked[i]==0) {		   dist[i*n-i*(i+1)/2+imin-i-1] = 			distance(GDtype,(*entries)[i],(*entries)[imin]);		   }}		for (j=imin+1; j<n; j++) {		   if (checked[j]==0) {		   dist[imin*n-imin*(imin+1)/2+j-imin-1] =			distance(GDtype,(*entries)[imin],(*entries)[j]);		   }}		}	else { 	// exceeds the threshold		checked[imin] = -1;		checked[jmin] = -1;		}	done = TRUE;	dmin = HUGE;	for (i=0; i<n-1; i++) {	  if (checked[i]==0) {	  for (j=i+1; j<n; j++) {		if (checked[j]==0) {			d = dist[i*n-i*(i+1)/2+j-i-1];			if (d<dmin) {				done = FALSE;				dmin = d;				imin = i;				jmin = j;	}}}}} 	} // end of while} // end of ifelse { // ***** case 2 ***** cluster by number k	done = n;while (done > K) {	(*entries)[imin] += (*entries)[jmin];	checked[jmin] = -2;	done--;	for (i=0; i<imin; i++) {	   if (checked[i]==0) {	   dist[i*n-i*(i+1)/2+imin-i-1] = 		distance(GDtype,(*entries)[i],(*entries)[imin]);	   }}	for (j=imin+1; j<n; j++) {	   if (checked[j]==0) {	   dist[imin*n-imin*(imin+1)/2+j-imin-1] =		distance(GDtype,(*entries)[imin],(*entries)[j]);	   }}	dmin = HUGE;	for (i=0; i<n-1; i++) {	  if (checked[i]==0) {	  for (j=i+1; j<n; j++) {		if (checked[j]==0) {		d = dist[i*n-i*(i+1)/2+j-i-1];			if (d<dmin) {			dmin = d;			imin = i;			jmin = j;	}}}}}	} // end of while} // end of elsej = 0;for (i=0; i<n; i++)   if (checked[i]!=-2) {	(*entries)[j]=(*entries)[i];	j++;	}n=j;delete [] checked;delete [] dist;}/*********************************************************************This is an O(n^2) algorithm, but works only for D2 and D4 due to the "REDUCIBILITY PROPERTY" that is given as below:if d(i,j) < p, d(i,k) > p, d(j,k) > p then d(i+j,k) > p.Algorithm:Part 1: Form the complete hierarchy in O(n^2) time	step1: Pick any cluster i[1].	step2: Determine the chain i[2]=NN(i[1]), i[3]=NN(i[2]) ... 	       until i[k]=NN(i[k-1]) and i[k-1]=NN(i[k]), where NN 	       means nearest neighbor.	step3: Merge clusters i[k-1] and i[k].	step4: If more than 1 clusters left, goto step using i[k-2] 	       as start if (k-2>0), otherwise choose arbitrary i[1].Part 2: Split from the complete hierarchy in O(n^2) 		by number of clusters K, 		by the threshold Ft, 		by tree height H,		...*********************************************************************/void Hierarchy1(int &n, 	// final number of clusters		const int K,    // final number of clusters		Entry **entries,// array storing clusters		short GDtype,		short Ftype,		double Ft){if (GDtype!=D2 && GDtype!=D4) 	print_error("Hierarchy1","only support distance D2 and D4");if (n<=1) return;if (n==K) return;// ****************** Part 1 **********************Hierarchy *h = new Hierarchy(n-1,(*entries)[0].sx.dim);h->MergeHierarchy(GDtype,n,*entries);// ******************* Part 2 *********************if (K==0) { 	// by the threshold	while (h->SplitHierarchy(BY_THRESHOLD,Ftype,Ft)==TRUE);	}else 	{		// by the number of clusters	while (h->chainptr+1<K && 	       h->SplitHierarchy(BY_KCLUSTERS,Ftype,Ft)==TRUE);	}// ******************* Part 3 *********************int j;Entry *tmpentries = new Entry[h->chainptr+1];for (j=0;j<=h->chainptr;j++) 	tmpentries[j].Init((*entries)[0].sx.dim);for (j=0;j<=h->chainptr;j++) {	if (h->chain[j]<0) 		tmpentries[j] = h->cf[-h->chain[j]-1];	else 	tmpentries[j] = (*entries)[h->chain[j]-1];	}delete [] *entries;*entries = tmpentries;n=h->chainptr+1;delete h;}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99精品偷自拍| 日韩欧美成人激情| 在线91免费看| 国产欧美精品国产国产专区| 亚洲综合色噜噜狠狠| 韩日欧美一区二区三区| 91国产视频在线观看| 国产亚洲成aⅴ人片在线观看| 一区二区三区久久久| 国产高清在线精品| 欧美一区在线视频| 亚洲自拍偷拍麻豆| 本田岬高潮一区二区三区| 精品少妇一区二区三区免费观看 | 精品久久国产97色综合| 一区二区三区四区不卡在线| 国产99久久久精品| 久久精品人人做人人爽人人| 日韩国产欧美在线视频| 91久久精品国产91性色tv| 国产精品女人毛片| 国产精品影音先锋| 精品精品欲导航| 免费的成人av| 制服.丝袜.亚洲.中文.综合| 亚洲一区免费视频| 色综合天天狠狠| 亚洲精品久久嫩草网站秘色| 懂色一区二区三区免费观看| 国产偷国产偷精品高清尤物| 久久99久久精品| 精品999在线播放| 精品一区二区三区免费毛片爱| 欧美日韩精品一区二区三区四区| 一区二区三区日本| 在线免费亚洲电影| 亚洲电影视频在线| 欧美日韩久久一区| 免费看欧美美女黄的网站| 日韩一级二级三级精品视频| 免费在线观看不卡| 精品国产乱码久久| 国产suv精品一区二区883| 国产欧美日韩在线| av男人天堂一区| 一区二区三区四区av| 在线不卡a资源高清| 日韩精品成人一区二区三区| 欧美不卡视频一区| 国产盗摄一区二区三区| 最新欧美精品一区二区三区| 色婷婷激情综合| 亚洲v中文字幕| 日韩精品一区二区三区swag | 日韩一区二区三免费高清| 日韩高清不卡一区二区三区| 日韩欧美精品在线| 成人永久aaa| 亚洲午夜激情av| 精品久久久久久最新网址| proumb性欧美在线观看| 亚洲与欧洲av电影| 欧美xxxxx牲另类人与| 成人在线一区二区三区| 午夜欧美视频在线观看| 久久尤物电影视频在线观看| 色综合天天综合网天天狠天天| 亚洲成av人在线观看| 26uuu亚洲| 在线观看免费一区| 国内外成人在线视频| 一区二区三区在线视频播放| 欧美va亚洲va香蕉在线| 91一区一区三区| 日韩成人午夜精品| 日韩久久一区二区| 精品欧美乱码久久久久久| 99精品视频在线观看免费| 日韩黄色小视频| 中文字幕在线不卡视频| 欧美一区二区视频网站| av资源站一区| 精品一区在线看| 一区二区三区中文字幕精品精品 | 在线观看亚洲一区| 韩国女主播一区| 亚洲国产成人va在线观看天堂| 久久精品人人做人人综合| 7777精品伊人久久久大香线蕉| 波多野结衣91| 国产99久久久久久免费看农村| 人人精品人人爱| 亚洲成av人片一区二区三区| 中文字幕一区av| 久久久精品人体av艺术| 欧美一区二区三区系列电影| 91香蕉视频mp4| 国产91丝袜在线观看| 麻豆国产精品一区二区三区| 亚洲第一主播视频| 一个色在线综合| 中文字幕综合网| 亚洲国产精品精华液2区45| 日韩免费视频一区二区| 3751色影院一区二区三区| 欧美性感一区二区三区| 91在线精品秘密一区二区| 成人激情校园春色| 国产精品一区二区黑丝| 国产一区二区三区在线观看免费| 日日摸夜夜添夜夜添国产精品 | 欧洲色大大久久| 91欧美激情一区二区三区成人| 国产成人在线观看| 国产精品一区二区久久不卡| 国产精品正在播放| 国产激情一区二区三区四区| 国产精品综合久久| 国产福利一区在线观看| 国产精品99久久久久| 国产精品456露脸| 成人晚上爱看视频| www.亚洲国产| 97国产一区二区| 色婷婷精品久久二区二区蜜臀av| 在线视频国内自拍亚洲视频| 欧美日韩在线一区二区| 精品视频在线免费观看| 7777精品伊人久久久大香线蕉超级流畅| 亚洲午夜精品久久久久久久久| 亚洲国产精品嫩草影院| 天天av天天翘天天综合网色鬼国产| 亚洲摸摸操操av| 亚洲v日本v欧美v久久精品| 奇米精品一区二区三区在线观看一| 日本在线不卡视频| 韩国成人福利片在线播放| 99麻豆久久久国产精品免费| 在线精品视频一区二区| 日韩欧美精品在线视频| 久久久国产午夜精品| 国产精品欧美久久久久一区二区| 亚洲三级理论片| 日韩黄色小视频| 国产成人精品免费一区二区| 色一情一乱一乱一91av| 欧美一卡二卡三卡四卡| 国产日产欧美一区| 亚洲成av人片在www色猫咪| 国产一区二区三区美女| 91捆绑美女网站| 日韩午夜激情视频| 国产精品久线在线观看| 五月婷婷综合网| 国产91丝袜在线观看| 欧美三级中文字幕在线观看| 久久一区二区三区四区| 一区二区三区四区不卡视频| 国产做a爰片久久毛片| 一本色道久久综合亚洲精品按摩| 91.xcao| 欧美激情在线一区二区| 日韩国产精品大片| 91在线无精精品入口| 久久伊人中文字幕| 日韩经典一区二区| 99精品桃花视频在线观看| 精品粉嫩超白一线天av| 亚洲午夜三级在线| 不卡一区二区三区四区| 日韩三级视频在线观看| 亚洲一区二区黄色| 成人午夜av在线| 精品av久久707| 日韩电影在线看| 欧美无砖专区一中文字| 国产精品久久久一本精品| 免费成人在线网站| 欧美日韩成人综合天天影院| 亚洲婷婷综合久久一本伊一区| 精品亚洲国产成人av制服丝袜| 在线观看91av| 亚洲高清三级视频| 在线观看国产一区二区| 亚洲欧美激情在线| 成+人+亚洲+综合天堂| 日本一区二区三区高清不卡| 九九视频精品免费| 日韩一级精品视频在线观看| 婷婷丁香激情综合| 欧美亚洲国产怡红院影院| 亚洲裸体xxx| 99久久免费国产| 国产精品久久久久毛片软件| 国产精品99精品久久免费| 精品国产亚洲一区二区三区在线观看| 日韩精品欧美成人高清一区二区| 欧美在线观看一区| 一区二区日韩电影| 在线精品视频一区二区三四|