예제 #1
0
 // calculate p(y|x)=sum_i(alpha_i*f_i(x,y))/sum_y(sum_i(alpha_i*f_i(x,y))).
 public Map<String, Double> predict(List<String> x) {
   Map<String, Double> probMap = new HashMap<String, Double>();
   double sum = 0;
   for (String label : labelSet) {
     double prob = 0;
     for (String feature : x) {
       prob += features.getModelWeight(label, feature);
     }
     prob = Math.exp(prob);
     probMap.put(label, prob);
     sum += prob;
   }
   for (String label : probMap.keySet()) {
     probMap.put(label, probMap.get(label) / sum);
   }
   return probMap;
 }