本文整理汇总了Java中cc.mallet.cluster.Clustering.getLabel方法的典型用法代码示例。如果您正苦于以下问题:Java Clustering.getLabel方法的具体用法?Java Clustering.getLabel怎么用?Java Clustering.getLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.cluster.Clustering
的用法示例。
在下文中一共展示了Clustering.getLabel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: getEvaluationScores
import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
@Override
public double[] getEvaluationScores(Clustering truth, Clustering predicted) {
int correct = 0;
int comparisons = 0;
for (int i = 0; i < truth.getNumInstances(); i++)
for (int j = i + 1; j < truth.getNumInstances(); j++) {
if ((truth.getLabel(i) == truth.getLabel(j)) ==
(predicted.getLabel(i) == predicted.getLabel(j)))
correct++;
comparisons++;
}
this.correctTotal += correct;
this.comparisonsTotal += comparisons;
return new double[]{(double)correct / comparisons};
}
示例3: 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))};
}
示例4: getEvaluationScores
import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
@Override
public double[] getEvaluationScores(Clustering truth, Clustering predicted) {
int tp, fn, fp;
tp = fn = fp = 0;
for (int i = 0; i < predicted.getNumClusters(); i++) {
int[] predIndices = predicted.getIndicesWithLabel(i);
for (int j = 0; j < predIndices.length; j++)
for (int k = j + 1; k < predIndices.length; k++)
if (truth.getLabel(predIndices[j]) == truth.getLabel(predIndices[k]))
tp++;
else
fp++;
}
for (int i = 0; i < truth.getNumClusters(); i++) {
int[] trueIndices = truth.getIndicesWithLabel(i);
for (int j = 0; j < trueIndices.length; j++)
for (int k = j + 1; k < trueIndices.length; k++)
if (predicted.getLabel(trueIndices[j]) != predicted.getLabel(trueIndices[k]))
fn++;
}
double pr = (double)tp / (tp+fp);
double rec = (double)tp / (tp+fn);
double f1 = 2*pr*rec/(pr+rec);
this.tpTotal += tp;
this.fpTotal += fp;
this.fnTotal += fn;
return new double[]{pr, rec, f1};
}
示例5: mergeInstances
import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
/**
* Merge clusters containing the specified instances.
* @param clustering
* @param instances
* @return Modified Clustering.
*/
public static Clustering mergeInstances (Clustering clustering,
int[] instances) {
for (int i = 0; i < instances.length; i++) {
for (int j = i + 1; j < instances.length; j++) {
int labeli = clustering.getLabel(instances[i]);
int labelj = clustering.getLabel(instances[j]);
clustering = mergeClusters(clustering, labeli, labelj);
}
}
return clustering;
}
示例6: 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;
}
示例7: 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;
}