当前位置: 首页>>代码示例>>Java>>正文


Java Clustering.getInstances方法代码示例

本文整理汇总了Java中cc.mallet.cluster.Clustering.getInstances方法的典型用法代码示例。如果您正苦于以下问题:Java Clustering.getInstances方法的具体用法?Java Clustering.getInstances怎么用?Java Clustering.getInstances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cc.mallet.cluster.Clustering的用法示例。


在下文中一共展示了Clustering.getInstances方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pipe

import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
public Instance pipe(Instance carrier) {
	AgglomerativeNeighbor neighbor = (AgglomerativeNeighbor) carrier
			.getData();
	Clustering original = neighbor.getOriginal();
	int[] cluster1 = neighbor.getOldClusters()[0];
	int[] cluster2 = neighbor.getOldClusters()[1];
	InstanceList list = original.getInstances();
	int[] mergedIndices = neighbor.getNewCluster();
	Record[] records = array2Records(mergedIndices, list);
	Alphabet fieldAlph = records[0].fieldAlphabet();
	Alphabet valueAlph = records[0].valueAlphabet();

	PropertyList features = null;
	features = addExactMatch(records, fieldAlph, valueAlph, features);
	features = addApproxMatch(records, fieldAlph, valueAlph, features);
	features = addSubstringMatch(records, fieldAlph, valueAlph, features);
	carrier
			.setData(new FeatureVector(getDataAlphabet(), features,
					true));

	LabelAlphabet ldict = (LabelAlphabet) getTargetAlphabet();
	String label = (original.getLabel(cluster1[0]) == original
			.getLabel(cluster2[0])) ? "YES" : "NO";
	carrier.setTarget(ldict.lookupLabel(label));			
	return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:27,代码来源:Clusterings2Clusterer.java

示例2: getEvaluationScores

import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
@Override
public double[] getEvaluationScores(Clustering truth, Clustering predicted) {
	double precision = 0.0;
	double recall = 0.0;

	InstanceList instances = truth.getInstances();

	for (int i = 0; i < instances.size(); i++) {
		int trueLabel = truth.getLabel(i);
		int predLabel = predicted.getLabel(i);
		int[] trueIndices = truth.getIndicesWithLabel(trueLabel);
		int[] predIndices = predicted.getIndicesWithLabel(predLabel);

		int correct = 0;
		for (int j = 0; j < predIndices.length; j++) {
			for (int k = 0; k < trueIndices.length; k++)
				if (trueIndices[k] == predIndices[j])
					correct++;
		}			
		precision += (double)correct / predIndices.length;
		recall += (double)correct / trueIndices.length;		
	}

	macroPrecision += precision;
	macroRecall += recall;
	macroNumInstances += instances.size();

	precision /= instances.size();
	recall /= instances.size();
	return new double[]{precision, recall, (2 * precision * recall / (precision + recall))};
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:32,代码来源:BCubedEvaluator.java

示例3: copyWithNewLabels

import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
/**
 * @param clustering 
 * @return A shallow copy of the argument where new objects are only
 * allocated for the cluster assignment.
 */
public static Clustering copyWithNewLabels (Clustering clustering) {
	int[] oldLabels = clustering.getLabels();
	int[] newLabels = new int[oldLabels.length];
	System.arraycopy(oldLabels, 0, newLabels, 0, oldLabels.length);
	return new Clustering(clustering.getInstances(),
												clustering.getNumClusters(),
												newLabels);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:14,代码来源:ClusterUtils.java

示例4: mergeInstancesWithSameLabel

import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
public static Clustering mergeInstancesWithSameLabel (Clustering clustering) {
	InstanceList list = clustering.getInstances();
	for (int i = 0; i < list.size(); i++) {
		Instance ii = list.get(i);
		int li = clustering.getLabel(i);
		for (int j = i + 1; j < list.size(); j++) {
			Instance ij = list.get(j);
			int lj = clustering.getLabel(j);
			if (li != lj && ii.getLabeling().equals(ij.getLabeling()))
				clustering = ClusterUtils.mergeClusters(clustering, li, lj);
		}
	}	
	return clustering;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:15,代码来源:ClusterUtils.java

示例5: AllPairsIterator

import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
/**
 *
 * @param clustering True Clustering.
 * @return
 */
public AllPairsIterator (Clustering clustering) {
	super(clustering);
	i = 0;
	j = 1;
	this.instances = clustering.getInstances();
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:AllPairsIterator.java

示例6: PairSampleIterator

import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
/**
 *
 * @param clustering True clustering.
 * @param random Source of randomness.
 * @param positiveProportion Proportion of Instances that should be positive examples.
 * @param numberSamples Total number of samples to generate.
 * @return
 */
public PairSampleIterator (Clustering clustering,
													 Randoms random,
													 double positiveProportion,
													 int numberSamples) {
	super(clustering);
	this.random = random;
	this.positiveProportion = positiveProportion;
	this.numberSamples = numberSamples;
	this.positiveTarget = (int)(numberSamples * positiveProportion);
	this.totalCount = this.positiveCount = 0;
	this.instances = clustering.getInstances();
	setNonSingletons();
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:22,代码来源:PairSampleIterator.java

示例7: run

import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
public void run () {
		Alphabet alphabet = dictOfSize(20);
		
		// TRAIN
		Clustering training = sampleClustering(alphabet);		
		Pipe clusterPipe = new OverlappingFeaturePipe();
		System.err.println("Training with " + training);
		InstanceList trainList = new InstanceList(clusterPipe);
		trainList.addThruPipe(new ClusterSampleIterator(training, random, 0.5, 100));
		System.err.println("Created " + trainList.size() + " instances.");
		Classifier me = new MaxEntTrainer().train(trainList);
		ClassifyingNeighborEvaluator eval =
			new ClassifyingNeighborEvaluator(me, "YES");
																					 
		Trial trial = new Trial(me, trainList);
		System.err.println(new ConfusionMatrix(trial));
		InfoGain ig = new InfoGain(trainList);
		ig.print();

// 		Clusterer clusterer = new GreedyAgglomerative(training.getInstances().getPipe(),
// 																									eval, 0.5);
		Clusterer clusterer = new GreedyAgglomerativeByDensity(training.getInstances().getPipe(),
																													 eval, 0.5, false,
																													 new java.util.Random(1));

		// TEST
		Clustering testing = sampleClustering(alphabet);		
		InstanceList testList = testing.getInstances();
		Clustering predictedClusters = clusterer.cluster(testList);			

		// EVALUATE
		System.err.println("\n\nEvaluating System: " + clusterer);
		ClusteringEvaluators evaluators = new ClusteringEvaluators(new ClusteringEvaluator[]{
				new BCubedEvaluator(),
				new PairF1Evaluator(),
				new MUCEvaluator(),
				new AccuracyEvaluator()});

		System.err.println("truth:" + testing);
		System.err.println("pred: " + predictedClusters);				
		System.err.println(evaluators.evaluate(testing, predictedClusters)); 					
	}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:43,代码来源:FirstOrderClusterExample.java

示例8: pipe

import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
public Instance pipe (Instance carrier) {
	boolean mergeFirst = false;
	
	AgglomerativeNeighbor neighbor = (AgglomerativeNeighbor)carrier.getData();
	Clustering original = neighbor.getOriginal();
	InstanceList list = original.getInstances();			
	int[] mergedIndices = neighbor.getNewCluster();
	boolean match = true;
	for (int i = 0; i < mergedIndices.length; i++) {
		for (int j = i + 1; j < mergedIndices.length; j++) {
			if ((original.getLabel(mergedIndices[i]) !=
					 original.getLabel(mergedIndices[j])) || mergeFirst) {
				FeatureVector fvi = (FeatureVector)list.get(mergedIndices[i]).getData();
				FeatureVector fvj = (FeatureVector)list.get(mergedIndices[j]).getData();
				if (!(fvi.contains("feature0") && fvj.contains("feature0"))) {
					match = false;
					break;							
				}
			}
		}
	}

	PropertyList pl = null;
	if (match) 
		pl = PropertyList.add("Match", 1.0, pl);
	else
		pl = PropertyList.add("NoMatch", 1.0, pl);
	
	FeatureVector fv = new FeatureVector ((Alphabet)getDataAlphabet(),
																				pl, true);
	carrier.setData(fv);

	boolean positive = true;
	for (int i = 0; i < mergedIndices.length; i++) {
		for (int j = i + 1; j < mergedIndices.length; j++) {
			if (original.getLabel(mergedIndices[i]) != original.getLabel(mergedIndices[j])) {
				positive = false;
				break;
			}
		}
	}
	LabelAlphabet ldict = (LabelAlphabet)getTargetAlphabet();
	String label = positive ? "YES" : "NO";			
	carrier.setTarget(ldict.lookupLabel(label));
	return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:47,代码来源:FirstOrderClusterExample.java


注:本文中的cc.mallet.cluster.Clustering.getInstances方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。