当前位置: 首页>>代码示例>>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;未经允许,请勿转载。