コード例 #1
0
ファイル: Weights.java プロジェクト: wmaier/uparse
 public float[] weight(Collection<String> features) {
   float[] scores = new float[index.size()];
   for (String feature : features) {
     if (!data.containsKey(feature)) {
       continue;
     }
     if (isAveraged || data.get(feature).used > opts.minupdate) {
       data.get(feature).sumScoresForAllTransitions(scores);
     }
   }
   return scores;
 }
コード例 #2
0
ファイル: Weights.java プロジェクト: wmaier/uparse
 public Weights<T> average() {
   System.err.print("averaging (this may take a while)... ");
   Weights<T> result = new Weights<T>(opts, true);
   result.data = new Object2ObjectOpenHashMap<>();
   result.index = index;
   result.gram = gram;
   int cnt = 0;
   for (String feat : data.keySet()) {
     FeatureWeights dw = data.get(feat);
     if (dw.used > opts.minupdate) {
       cnt++;
       FeatureWeights fw = new FeatureWeights();
       for (int trans : index.indices()) {
         float averaged = dw.getAveraged(trans, i);
         if (!Float.isNaN(averaged)) {
           fw.increment(trans, averaged, 0);
         }
       }
       result.data.put(feat, fw);
     }
   }
   System.err.println("done, averaged " + cnt + " features.");
   return result;
 }