本文整理汇总了Java中cc.mallet.types.Labeling.numLocations方法的典型用法代码示例。如果您正苦于以下问题:Java Labeling.numLocations方法的具体用法?Java Labeling.numLocations怎么用?Java Labeling.numLocations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.types.Labeling
的用法示例。
在下文中一共展示了Labeling.numLocations方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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();
}
示例3: printLabelings
import cc.mallet.types.Labeling; //导入方法依赖的package包/类
public void printLabelings(Classifier classifier, File file) throws IOException {
// Create a new iterator that will read raw instance data from
// the lines of a file.
// Lines should be formatted as:
//
// [name] [label] [data ... ]
//
// in this case, "label" is ignored.
CsvIterator reader =
new CsvIterator(new FileReader(file),
"(\\w+)\\s+(\\w+)\\s+(.*)",
3, 2, 1); // (data, label, name) field indices
// Create an iterator that will pass each instance through
// the same pipe that was used to create the training data
// for the classifier.
Iterator instances =
classifier.getInstancePipe().newIteratorFrom(reader);
// Classifier.classify() returns a Classification object
// that includes the instance, the classifier, and the
// classification results (the labeling). Here we only
// care about the Labeling.
int i = 0;
while (instances.hasNext()) {
Instance next = (Instance) instances.next();
Labeling labeling = classifier.classify(next).getLabeling();
// print the labels with their weights in descending order (ie best first)
if (labeling.getLabelAtRank(0).toString().equals("Yes")&labeling.getValueAtRank(0)>0.995)
{
i++;
}
for (int rank = 0; rank < labeling.numLocations(); rank++){
System.out.print(next.getName().toString()+" "+labeling.getLabelAtRank(rank) + ":" +
labeling.getValueAtRank(rank) + " ");
}
System.out.println("i = "+i);
}
}