本文整理汇总了Java中cc.mallet.types.Labeling类的典型用法代码示例。如果您正苦于以下问题:Java Labeling类的具体用法?Java Labeling怎么用?Java Labeling使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Labeling类属于cc.mallet.types包,在下文中一共展示了Labeling类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: ConfusionMatrix
import cc.mallet.types.Labeling; //导入依赖的package包/类
/**
* Constructs matrix and calculates values
* @param t the trial to build matrix from
*/
public ConfusionMatrix(Trial t)
{
this.trial = t;
this.classifications = t;
Labeling tempLabeling =
((Classification)classifications.get(0)).getLabeling();
this.numClasses = tempLabeling.getLabelAlphabet().size();
values = new int[numClasses][numClasses];
for(int i=0; i < classifications.size(); i++)
{
LabelVector lv =
((Classification)classifications.get(i)).getLabelVector();
Instance inst = ((Classification)classifications.get(i)).getInstance();
int bestIndex = lv.getBestIndex();
int correctIndex = inst.getLabeling().getBestIndex();
assert(correctIndex != -1);
//System.out.println("Best index="+bestIndex+". Correct="+correctIndex);
values[correctIndex][bestIndex]++;
}
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:25,代码来源:ConfusionMatrix.java
示例2: incorporateOneInstance
import cc.mallet.types.Labeling; //导入依赖的package包/类
private void incorporateOneInstance (Instance instance, double instanceWeight)
{
Labeling labeling = instance.getLabeling ();
if (labeling == null) return; // Handle unlabeled instances by skipping them
FeatureVector fv = (FeatureVector) instance.getData ();
double oneNorm = fv.oneNorm();
if (oneNorm <= 0) return; // Skip instances that have no features present
if (docLengthNormalization > 0)
// Make the document have counts that sum to docLengthNormalization
// I.e., if 20, it would be as if the document had 20 words.
instanceWeight *= docLengthNormalization / oneNorm;
assert (instanceWeight > 0 && !Double.isInfinite(instanceWeight));
for (int lpos = 0; lpos < labeling.numLocations(); lpos++) {
int li = labeling.indexAtLocation (lpos);
double labelWeight = labeling.valueAtLocation (lpos);
if (labelWeight == 0) continue;
//System.out.println ("NaiveBayesTrainer me.increment "+ labelWeight * instanceWeight);
me[li].increment (fv, labelWeight * instanceWeight);
// This relies on labelWeight summing to 1 over all labels
pe.increment (li, labelWeight * instanceWeight);
}
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:23,代码来源:NaiveBayesTrainer.java
示例3: ConfusionMatrix
import cc.mallet.types.Labeling; //导入依赖的package包/类
/**
* Constructs matrix and calculates values
* @param t the trial to build matrix from
*/
public ConfusionMatrix(Trial t) {
this.trial = t;
this.classifications = t;
Labeling tempLabeling =
((Classification) classifications.get(0)).getLabeling();
this.numClasses = tempLabeling.getLabelAlphabet().size();
values = new int[numClasses][numClasses];
for (int i=0; i < classifications.size(); i++) {
LabelVector lv =
((Classification)classifications.get(i)).getLabelVector();
Instance inst = ((Classification)classifications.get(i)).getInstance();
int bestIndex = lv.getBestIndex();
int correctIndex = inst.getLabeling().getBestIndex();
assert(correctIndex != -1);
//System.out.println("Best index="+bestIndex+". Correct="+correctIndex);
values[correctIndex][bestIndex]++;
}
}
开发者ID:iamxiatian,项目名称:wikit,代码行数:25,代码来源:ConfusionMatrix.java
示例4: getAverageRank
import cc.mallet.types.Labeling; //导入依赖的package包/类
/** Return the average rank of the correct class label as returned by Labeling.getRank(correctLabel) on the predicted Labeling. */
public double getAverageRank ()
{
double rsum = 0;
Labeling tmpL;
Classification tmpC;
Instance tmpI;
Label tmpLbl, tmpLbl2;
int tmpInt;
for(int i = 0; i < this.size(); i++) {
tmpC = this.get(i);
tmpI = tmpC.getInstance();
tmpL = tmpC.getLabeling();
tmpLbl = (Label)tmpI.getTarget();
tmpInt = tmpL.getRank(tmpLbl);
tmpLbl2 = tmpL.getLabelAtRank(0);
rsum = rsum + tmpInt;
}
return rsum/this.size();
}
开发者ID:Mondego,项目名称:LDA-studies,代码行数:21,代码来源:Trial.java
示例5: applyModel
import cc.mallet.types.Labeling; //导入依赖的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;
}
开发者ID:GateNLP,项目名称:gateplugin-LearningFramework,代码行数:36,代码来源:EngineMBMalletClass.java
示例6: labelsToString
import cc.mallet.types.Labeling; //导入依赖的package包/类
public String labelsToString(Labeling lab) {
StringBuilder sb = new StringBuilder();
int num_labs = lab.numLocations();
for (int i = 0; i < num_labs; i++) {
sb.append(lab.labelAtLocation(i)).append(":").append(lab.valueAtLocation(i));
if (i + 1 < num_labs) {
sb.append(",");
}
}
return sb.toString();
}
开发者ID:isoboroff,项目名称:basekb-search,代码行数:12,代码来源:FreebaseIndexer.java
示例7: convert
import cc.mallet.types.Labeling; //导入依赖的package包/类
/**
*
* @param inst input instance, with FeatureVectorSequence as data.
* @param alphabetsPipe a Noop pipe containing the data and target alphabets for
* the resulting InstanceList and AugmentableFeatureVectors
* @return list of instances, each with one AugmentableFeatureVector as data
*/
public static InstanceList convert(Instance inst, Noop alphabetsPipe)
{
InstanceList ret = new InstanceList(alphabetsPipe);
Object obj = inst.getData();
assert(obj instanceof FeatureVectorSequence);
FeatureVectorSequence fvs = (FeatureVectorSequence) obj;
LabelSequence ls = (LabelSequence) inst.getTarget();
assert(fvs.size() == ls.size());
Object instName = (inst.getName() == null ? "NONAME" : inst.getName());
for (int j = 0; j < fvs.size(); j++) {
FeatureVector fv = fvs.getFeatureVector(j);
int[] indices = fv.getIndices();
FeatureVector data = new AugmentableFeatureVector (alphabetsPipe.getDataAlphabet(),
indices, fv.getValues(), indices.length);
Labeling target = ls.getLabelAtPosition(j);
String name = instName.toString() + "[email protected]_POS_" + (j + 1);
Object source = inst.getSource();
Instance toAdd = alphabetsPipe.pipe(new Instance(data, target, name, source));
ret.add(toAdd);
}
return ret;
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:35,代码来源:AddClassifierTokenPredictions.java
示例8: Classification
import cc.mallet.types.Labeling; //导入依赖的package包/类
public Classification (Instance instance, Classifier classifier,
Labeling labeling)
{
this.instance = instance;
this.classifier = classifier;
this.labeling = labeling;
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:8,代码来源:Classification.java
示例9: bestLabelIsCorrect
import cc.mallet.types.Labeling; //导入依赖的package包/类
public boolean bestLabelIsCorrect ()
{
Labeling correctLabeling = instance.getLabeling();
if (correctLabeling == null)
throw new IllegalStateException ("Instance has no label.");
return (labeling.getBestLabel().equals (correctLabeling.getBestLabel()));
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:8,代码来源:Classification.java
示例10: getPrecision
import cc.mallet.types.Labeling; //导入依赖的package包/类
/** Calculate the precision of the classifier on an instance list for a
particular target entry */
public double getPrecision (Object labelEntry)
{
int index;
if (labelEntry instanceof Labeling)
index = ((Labeling)labelEntry).getBestIndex();
else
index = classifier.getLabelAlphabet().lookupIndex(labelEntry, false);
if (index == -1) throw new IllegalArgumentException ("Label "+labelEntry.toString()+" is not a valid label.");
return getPrecision (index);
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:13,代码来源:Trial.java
示例11: getRecall
import cc.mallet.types.Labeling; //导入依赖的package包/类
/** Calculate the recall of the classifier on an instance list for a
particular target entry */
public double getRecall (Object labelEntry)
{
int index;
if (labelEntry instanceof Labeling)
index = ((Labeling)labelEntry).getBestIndex();
else
index = classifier.getLabelAlphabet().lookupIndex(labelEntry, false);
if (index == -1) throw new IllegalArgumentException ("Label "+labelEntry.toString()+" is not a valid label.");
return getRecall (index);
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:13,代码来源:Trial.java
示例12: getF1
import cc.mallet.types.Labeling; //导入依赖的package包/类
/** Calculate the F1-measure of the classifier on an instance list for a
particular target entry */
public double getF1 (Object labelEntry)
{
int index;
if (labelEntry instanceof Labeling)
index = ((Labeling)labelEntry).getBestIndex();
else
index = classifier.getLabelAlphabet().lookupIndex(labelEntry, false);
if (index == -1) throw new IllegalArgumentException ("Label "+labelEntry.toString()+" is not a valid label.");
return getF1 (index);
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:13,代码来源:Trial.java
注:本文中的cc.mallet.types.Labeling类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论