Example #1
0
 public List<Double> generateEntropy(Map<FV, Collection<FV>> fv_list, int numInstances) {
   List<Double> entropies = new ArrayList();
   Iterator<Entry<FV, Collection<FV>>> iterator = fv_list.entrySet().iterator();
   while (iterator.hasNext()) {
     Entry<FV, Collection<FV>> next = iterator.next();
     FV key = next.getKey();
     key.setFrequency((double) next.getValue().size() / numInstances);
     double[] counter = new double[key.getNumLabels()];
     for (FV fv : next.getValue()) {
       int idx = (int) fv.getLabel();
       counter[idx]++;
     }
     key.setEntropy(calculateEntropy(counter, next.getValue().size()));
     entropies.add(key.getEntropy());
   }
   return entropies;
 }