本文整理汇总了Java中cc.mallet.types.LabelVector.numLocations方法的典型用法代码示例。如果您正苦于以下问题:Java LabelVector.numLocations方法的具体用法?Java LabelVector.numLocations怎么用?Java LabelVector.numLocations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.types.LabelVector
的用法示例。
在下文中一共展示了LabelVector.numLocations方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyModel
import cc.mallet.types.LabelVector; //导入方法依赖的package包/类
@Override
public List<ModelApplication> applyModel(
AnnotationSet instanceAS, AnnotationSet inputAS, AnnotationSet sequenceAS, String parms) {
// NOTE: the crm should be of type CorpusRepresentationMalletClass for this to work!
if(!(corpusRepresentation instanceof CorpusRepresentationMalletTarget)) {
throw new GateRuntimeException("Cannot perform classification with data from "+corpusRepresentation.getClass());
}
CorpusRepresentationMalletTarget data = (CorpusRepresentationMalletTarget)corpusRepresentation;
data.stopGrowth();
List<ModelApplication> gcs = new ArrayList<ModelApplication>();
LFPipe pipe = (LFPipe)data.getRepresentationMallet().getPipe();
Classifier classifier = (Classifier)model;
// iterate over the instance annotations and create mallet instances
for(Annotation instAnn : instanceAS.inDocumentOrder()) {
Instance inst = data.extractIndependentFeatures(instAnn, inputAS);
inst = pipe.instanceFrom(inst);
Classification classification = classifier.classify(inst);
Labeling labeling = classification.getLabeling();
LabelVector labelvec = labeling.toLabelVector();
List<String> classes = new ArrayList<String>(labelvec.numLocations());
List<Double> confidences = new ArrayList<Double>(labelvec.numLocations());
for(int i=0; i<labelvec.numLocations(); i++) {
classes.add(labelvec.getLabelAtRank(i).toString());
confidences.add(labelvec.getValueAtRank(i));
}
ModelApplication gc = new ModelApplication(instAnn, labeling.getBestLabel().toString(),
labeling.getBestValue(), classes, confidences);
//System.err.println("ADDING GC "+gc);
// now save the class in our special class feature on the instance as well
instAnn.getFeatures().put("gate.LF.target",labeling.getBestLabel().toString());
gcs.add(gc);
}
data.startGrowth();
return gcs;
}
示例2: evaluate
import cc.mallet.types.LabelVector; //导入方法依赖的package包/类
/**
*
* @param neighbors
* @return An array containing a score for each of the elements of <code>neighbors</code>.
*/
public double[] evaluate (Neighbor[] neighbors) {
double[] scores = new double[neighbors.length];
LabelVector ranks = classifier.classify(neighbors).getLabelVector();
for (int i = 0; i < ranks.numLocations(); i++) {
int idx = ((Integer)ranks.getLabelAtRank(i).getEntry()).intValue();
scores[idx] = ranks.getValueAtRank(i);
}
return scores;
}
示例3: getPredictionProbabilities
import cc.mallet.types.LabelVector; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends Comparable<?>> Map<T, Double> getPredictionProbabilities(String instanceId) {
Map<T, Double> res = new TreeMap<T, Double>();
Integer in = data.instanceIds.get(instanceId);
LabelVector vec = prediction.get(in).getLabelVector();
for (int i = 0; i < vec.numLocations(); ++i)
res.put((T) vec.labelAtLocation(i).getEntry(), vec.valueAtLocation(i));
return res;
}
示例4: classify
import cc.mallet.types.LabelVector; //导入方法依赖的package包/类
public Classification classify (Instance instance)
{
Classification c = underlyingClassifier.classify (instance);
Classification cpc = confidencePredictingClassifier.classify (c);
LabelVector lv = c.getLabelVector();
int bestIndex = lv.getBestIndex();
double [] values = new double[lv.numLocations()];
//// Put score of "correct" into score of the winning class...
// xxx Can't set lv - it's immutable.
// Must create copy and new classification object
// lv.set (bestIndex, cpc.getLabelVector().value("correct"));
//for (int i = 0; i < lv.numLocations(); i++)
// if (i != bestIndex)
// lv.set (i, 0.0);
// Put score of "correct" in winning class and
// set rest to 0
for (int i = 0; i < lv.numLocations(); i++) {
if (i != bestIndex)
values[i] = 0.0;
else values[i] = cpc.getLabelVector().value("correct");
}
//return c;
if(c.bestLabelIsCorrect()){
numCorrectInstances++;
totalCorrect+=cpc.getLabelVector().value("correct");
totalIncorrectCorrect+=cpc.getLabelVector().value("incorrect");
String correct = new String("correct");
if(correct.equals(cpc.getLabelVector().getBestLabel().toString()))
numConfidenceCorrect++;
else numFalseNegative++;
}
else{
numIncorrectInstances++;
totalIncorrect+=cpc.getLabelVector().value("correct");
totalIncorrectIncorrect+=cpc.getLabelVector().value("incorrect");
if((new String("incorrect")).equals(cpc.getLabelVector().getBestLabel().toString()))
numConfidenceCorrect++;
else numFalsePositive++;
}
return new Classification(instance, this, new LabelVector(lv.getLabelAlphabet(), values));
// return cpc;
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:47,代码来源:ConfidencePredictingClassifier.java