List of usage examples for edu.stanford.nlp.stats ClassicCounter keySet
@Override
public Set<E> keySet()
From source file:gr.aueb.cs.nlp.wordtagger.classifier.SVMWindows64Factory.java
License:Open Source License
/** * Converts the svm_light weight Counter (which uses feature indices) into a weight Counter * using the actual features and labels. Because this is svm_light, and not svm_struct, the * weights for the +1 class (which correspond to labelIndex.get(0)) and the -1 class * (which correspond to labelIndex.get(1)) are just the negation of one another. *//*www. ja v a 2 s .c om*/ private ClassicCounter<Pair<F, L>> convertSVMLightWeights(ClassicCounter<Integer> weights, Index<F> featureIndex, Index<L> labelIndex) { ClassicCounter<Pair<F, L>> newWeights = new ClassicCounter<Pair<F, L>>(); for (int i : weights.keySet()) { F f = featureIndex.get(i - 1); double w = weights.getCount(i); // the first guy in the labelIndex was the +1 class and the second guy // was the -1 class newWeights.incrementCount(new Pair<F, L>(f, labelIndex.get(0)), w); newWeights.incrementCount(new Pair<F, L>(f, labelIndex.get(1)), -w); } return newWeights; }
From source file:gr.aueb.cs.nlp.wordtagger.classifier.SVMWindows64Factory.java
License:Open Source License
/** * Converts the svm_struct weight Counter (in which the weight for a feature/label pair * correspondes to ((labelIndex * numFeatures)+(featureIndex+1))) into a weight Counter * using the actual features and labels. */// w w w. ja va 2s. c o m private ClassicCounter<Pair<F, L>> convertSVMStructWeights(ClassicCounter<Integer> weights, Index<F> featureIndex, Index<L> labelIndex) { // int numLabels = labelIndex.size(); int numFeatures = featureIndex.size(); ClassicCounter<Pair<F, L>> newWeights = new ClassicCounter<Pair<F, L>>(); for (int i : weights.keySet()) { L l = labelIndex.get((i - 1) / numFeatures); // integer division on purpose F f = featureIndex.get((i - 1) % numFeatures); double w = weights.getCount(i); newWeights.incrementCount(new Pair<F, L>(f, l), w); } return newWeights; }