當前位置: 首頁>>代碼示例>>Java>>正文


Java VectorClusterElement類代碼示例

本文整理匯總了Java中org.seqcode.ml.clustering.vectorcluster.VectorClusterElement的典型用法代碼示例。如果您正苦於以下問題:Java VectorClusterElement類的具體用法?Java VectorClusterElement怎麽用?Java VectorClusterElement使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


VectorClusterElement類屬於org.seqcode.ml.clustering.vectorcluster包,在下文中一共展示了VectorClusterElement類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateBootStrapSample

import org.seqcode.ml.clustering.vectorcluster.VectorClusterElement; //導入依賴的package包/類
private ArrayList<VectorClusterElement> generateBootStrapSample(){
	ArrayList<VectorClusterElement> ret = new ArrayList<VectorClusterElement>();
	Random rand = new Random();
	int maxInd = sparse_profiles.size();
	
	int[] added = new int[dataSplitUnits];
	int currRand =  rand.nextInt(maxInd);
	while(addBsDataPoint(currRand,added).car()){
		added[addBsDataPoint(currRand,added).cdr()]++;
		ret.add(sparse_profiles.get(currRand));
		currRand = rand.nextInt(maxInd);
	}
	//for(int i=0; i<added.length;i++){
	//	System.out.println(added[i]);
	//}
	return ret;
}
 
開發者ID:seqcode,項目名稱:sequnwinder,代碼行數:18,代碼來源:ClusterProfiles.java

示例2: getClusterAssignment

import org.seqcode.ml.clustering.vectorcluster.VectorClusterElement; //導入依賴的package包/類
private int getClusterAssignment(VectorClusterElement pfl, Vector<VectorClusterElement> clusMeans){
	int minCluster = -1;
       double minDist = 0.0;
       for(int i = 0; i < clusMeans.size(); i++) { 
           double clustDist = metric.evaluate(pfl, clusMeans.get(i));
           if(minCluster == -1 || clustDist < minDist) { 
               minDist = clustDist;
               minCluster = i;
           }
       }
       return minCluster;
}
 
開發者ID:seqcode,項目名稱:chexmix,代碼行數:13,代碼來源:ClusterMotifFinder.java

示例3: clusterList

import org.seqcode.ml.clustering.vectorcluster.VectorClusterElement; //導入依賴的package包/類
private List<Integer> clusterList(Vector<VectorClusterElement> clusMeans) throws IOException{
	List<Integer> clusterAssignment = new ArrayList<Integer>();

	for(int p=0; p<profiles.size(); p++){
		int memebership = getClusterAssignment(profiles.get(p),clusMeans);
		clusterAssignment.add(memebership);
	}
	return clusterAssignment;
}
 
開發者ID:seqcode,項目名稱:chexmix,代碼行數:10,代碼來源:ClusterMotifFinder.java

示例4: doClustering

import org.seqcode.ml.clustering.vectorcluster.VectorClusterElement; //導入依賴的package包/類
/**
 * 
 * @param nC
 * @param data
 * @return Pair<Pair<silhouette,ssd>,clustermeans>>
 */
private Pair<Pair<Double,Double>,Vector<VectorClusterElement>> doClustering(int nC, ArrayList<VectorClusterElement> data){
	// Initialize
	ClusterRepresentative<VectorClusterElement> crep = new Mean();
	//Random starts
	Random generator = new Random();
	Vector<VectorClusterElement> starts = new Vector<VectorClusterElement>();
	for(int s=0; s<nC; s++){
		boolean found = false;
		while(!found){
			int r = generator.nextInt(data.size());
			if(!added(starts,data.get(r))){
				starts.add(data.get(r));
				found = true;
			}
		}

	}

	//Initialize clustering
	KMeansClustering<VectorClusterElement> kmc = new KMeansClustering<VectorClusterElement>(metric, crep, starts);
	kmc.setIterations(numClusItrs);
	kmc.clusterElements(data,0.01);
	Pair<Double,Double> clusterquality = new Pair<Double,Double>(kmc.silhouette(),kmc.sumOfSquaredDistance());
	
	return new Pair<Pair<Double,Double>,Vector<VectorClusterElement>>(clusterquality,kmc.getClusterMeans());
	
}
 
開發者ID:seqcode,項目名稱:sequnwinder,代碼行數:34,代碼來源:ClusterProfiles.java

示例5: cluster

import org.seqcode.ml.clustering.vectorcluster.VectorClusterElement; //導入依賴的package包/類
/**
 * The method should be executed after initiating the class object
 * @throws IOException 
 */
public List<Integer> cluster() throws IOException {
	
	// Initialize
	Vector<VectorClusterElement> bestClusterMeans=null;
	Double SSD = Double.MAX_VALUE;
	ClusterRepresentative<VectorClusterElement> crep = new Mean();
	double thresholdDistances[][] = shapeAlign.thresholdDistance();
	
	for (int i= 0 ; i<10; i++){
		for (int j=0; j<10 ; j++){
			System.out.print(thresholdDistances[i][j]);
		}
		System.out.println();
	}
	
	// converting double[] to vector
	for (int i = 0; i <thresholdDistances.length; i++){
		DefaultVectorClusterElement v = new DefaultVectorClusterElement(thresholdDistances[i]);
		profiles.add(v);
	}
	
	for(int i=0; i<=TRAIN_REPEATS; i++){			
		//Random starts
		Random generator = new Random();
		ArrayList<Integer> pNum = new ArrayList<Integer>();
		Vector<VectorClusterElement> starts = new Vector<VectorClusterElement>();
		int s=0;
		do{
			int r = generator.nextInt(profiles.size());
			if (!pNum.contains(r)){	// make sure that random number picked is not previously included
				starts.add(profiles.get(r));
				pNum.add(r);
				s++;
			}
		}while (s<K);		
		System.out.println("iteration round "+i);
	
		//Initialize clustering
		KMeansClustering<VectorClusterElement> kmc = new KMeansClustering<VectorClusterElement>(metric, crep, starts);
		kmc.setIterations(MAX_ITER);			
		// Cluster !
		kmc.clusterElements(profiles,0.01);
		
		Double currSSD = kmc.sumOfSquaredDistance();
		if(currSSD<SSD){
			SSD = currSSD;
			bestClusterMeans = kmc.getClusterMeans();
		}System.out.println("SSD: "+currSSD);	
	}
	
	return clusterList(bestClusterMeans);
}
 
開發者ID:seqcode,項目名稱:chexmix,代碼行數:57,代碼來源:ClusterMotifFinder.java

示例6: execute

import org.seqcode.ml.clustering.vectorcluster.VectorClusterElement; //導入依賴的package包/類
/**
 * The method that should be executed after initiating the class object
 * @throws IOException 
 */
public List<Integer> execute() throws IOException{
	StringBuilder sb = new StringBuilder();
	double[][] sh = new double[maxC-minC+1][numBootstraps];
	double[][] ssd = new double[maxC-minC+1][numBootstraps];
	HashMap<Integer,Vector<VectorClusterElement>> bestClusterMeans = new HashMap<Integer,Vector<VectorClusterElement>>();
	for(int c = minC; c<=maxC; c++){
		double bestSh = Double.MIN_VALUE;
		Vector<VectorClusterElement> bestMeans = null;
		for(int b=0; b<numBootstraps; b++){
			ArrayList<VectorClusterElement> currBS = generateBootStrapSample();
			Pair<Pair<Double,Double>,Vector<VectorClusterElement>> currOut = doClustering(c, currBS);
			double currSH = currOut.car().car();
			double currSSD = currOut.car().cdr();
			sh[c-minC][b] = currSH;
			ssd[c-minC][b] = currSSD;
			sb.append(c);sb.append("\t");sb.append(currSH);sb.append("\t");sb.append("Silhouette");sb.append("\n");
			sb.append(c);sb.append("\t");sb.append(currSSD);sb.append("\t");sb.append("SSD");sb.append("\n");
			if(bestSh < currSH){
				bestSh = currSH;
				bestMeans = currOut.cdr();
			}
		}
		bestClusterMeans.put(c, bestMeans);                            
	}
	
	BufferedWriter bwQual = new BufferedWriter(new FileWriter(outdir.getAbsolutePath()+File.separator+"ClusterQuality.tab"));
	bwQual.write(sb.toString());
	bwQual.close();

	double[] mediansSh = new double[maxC-minC+1];
	for(int c=0; c<sh.length; c++){
		Arrays.sort(sh[c]);
		int middle = ((numBootstraps) / 2);
		if(numBootstraps % 2 == 0){
			double medianA = sh[c][middle];
			double medianB = sh[c][middle-1];
			mediansSh[c] = (medianA + medianB) / 2;
		} else{
			mediansSh[c] = sh[c][middle];
		}
	}
	
	double maxMedian = Double.MIN_VALUE;
	int bestC = 0;
	
	for(int c=0; c<mediansSh.length; c++){
		if(mediansSh[c]>maxMedian){
			maxMedian = mediansSh[c];
			bestC = c+minC;
		}
	}
	
	K= bestC;
	
	// Caution: the value of K might change in the "writClusters" method also
	List<Integer> clusAssignment = writeClusters(bestClusterMeans.get(bestC));
	
	return clusAssignment;
}
 
開發者ID:seqcode,項目名稱:sequnwinder,代碼行數:64,代碼來源:ClusterProfiles.java


注:本文中的org.seqcode.ml.clustering.vectorcluster.VectorClusterElement類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。