Example usage for edu.stanford.nlp.stats Counters addInPlace

List of usage examples for edu.stanford.nlp.stats Counters addInPlace

Introduction

In this page you can find the example usage for edu.stanford.nlp.stats Counters addInPlace.

Prototype

public static <E> void addInPlace(Counter<E> target, double value) 

Source Link

Document

Increments all keys in a Counter by a specific value.

Usage

From source file:gr.aueb.cs.nlp.wordtagger.classifier.SVMWindows64Factory.java

License:Open Source License

/**
 * Takes all the support vectors, and their corresponding alphas, and computes a weight
 * vector that can be used in a vanilla LinearClassifier.  This only works because
 * we are using a linear kernel.  The Counter is over the feature indices (+1 cos for
 * some reason svm_light is 1-indexed), not features.
 *//*from   w w w . j a  va  2  s  .  c o  m*/
private static ClassicCounter<Integer> getWeights(List<Pair<Double, ClassicCounter<Integer>>> supportVectors) {
    ClassicCounter<Integer> weights = new ClassicCounter<Integer>();
    for (Pair<Double, ClassicCounter<Integer>> sv : supportVectors) {
        ClassicCounter<Integer> c = new ClassicCounter<Integer>(sv.second());
        Counters.multiplyInPlace(c, sv.first());
        Counters.addInPlace(weights, c);
    }
    return weights;
}