Program: 32159
Project: 32159
Buggy source:
/** 
 * categorical binning
 */
private void doCategoricalBinning(){
  Map<String,Integer> categoryHistNeg=new HashMap<String,Integer>();
  Map<String,Integer> categoryHistPos=new HashMap<String,Integer>();
  Map<String,Double> categoryWeightedNeg=new HashMap<String,Double>();
  Map<String,Double> categoryWeightedPos=new HashMap<String,Double>();
  Set<String> categorySet=new HashSet<String>();
  for (int i=0; i < voSize; i++) {
    String category=voList.get(i).getRaw();
    categorySet.add(category);
    if (negTags.contains(voList.get(i).getTag())) {
      incMapCnt(categoryHistNeg,category);
      incMapWithValue(categoryWeightedNeg,category,voList.get(i).getWeight());
    }
 else {
      incMapCnt(categoryHistPos,category);
      incMapWithValue(categoryWeightedPos,category,voList.get(i).getWeight());
    }
  }
  Map<String,Double> categoryFraudRateMap=new HashMap<String,Double>();
  for (  String key : categorySet) {
    double cnt0=categoryHistNeg.containsKey(key) ? categoryHistNeg.get(key) : 0;
    double cnt1=categoryHistPos.containsKey(key) ? categoryHistPos.get(key) : 0;
    double rate;
    if (cnt0 + cnt1 == 0) {
      rate=0;
    }
 else {
      rate=cnt1 / (cnt0 + cnt1);
    }
    categoryFraudRateMap.put(key,rate);
  }
  MapComparator cmp=new MapComparator(categoryFraudRateMap);
  Map<String,Double> sortedCategoryFraudRateMap=new TreeMap<String,Double>(cmp);
  sortedCategoryFraudRateMap.putAll(categoryFraudRateMap);
  for (  String key : sortedCategoryFraudRateMap.keySet()) {
    Integer countNeg=categoryHistNeg.containsKey(key) ? categoryHistNeg.get(key) : 0;
    binCountNeg.add(countNeg);
    Integer countPos=categoryHistPos.containsKey(key) ? categoryHistPos.get(key) : 0;
    binCountPos.add(countPos);
    Double weightedNeg=categoryWeightedNeg.containsKey(key) ? categoryWeightedNeg.get(key) : 0.0;
    this.binWeightedNeg.add(weightedNeg);
    Double weightedPos=categoryWeightedPos.containsKey(key) ? categoryWeightedPos.get(key) : 0.0;
    this.binWeightedPos.add(weightedPos);
    binAvgScore.add(0);
    binCategory.add(key);
    binPosCaseRate.add(sortedCategoryFraudRateMap.get(key));
  }
  this.actualNumBins=binCategory.size();
  for (  ValueObject vo : voList) {
    String key=vo.getRaw();
    if (binCategory.indexOf(key) == -1) {
      vo.setValue(0.0);
    }
 else {
      vo.setValue(binPosCaseRate.get(binCategory.indexOf(key)));
    }
  }
}

Fixed version (ground truth):
/** 
 * categorical binning
 */
private void doCategoricalBinning(){
  Map<String,Integer> categoryHistNeg=new HashMap<String,Integer>();
  Map<String,Integer> categoryHistPos=new HashMap<String,Integer>();
  Map<String,Double> categoryWeightedNeg=new HashMap<String,Double>();
  Map<String,Double> categoryWeightedPos=new HashMap<String,Double>();
  Set<String> categorySet=new HashSet<String>();
  for (int i=0; i < voSize; i++) {
    String category=voList.get(i).getRaw();
    categorySet.add(category);
    if (negTags.contains(voList.get(i).getTag())) {
      incMapCnt(categoryHistNeg,category);
      incMapWithValue(categoryWeightedNeg,category,voList.get(i).getWeight());
    }
 else {
      incMapCnt(categoryHistPos,category);
      incMapWithValue(categoryWeightedPos,category,voList.get(i).getWeight());
    }
  }
  Map<String,Double> categoryFraudRateMap=new HashMap<String,Double>();
  for (  String key : categorySet) {
    double cnt0=categoryHistNeg.containsKey(key) ? categoryHistNeg.get(key) : 0;
    double cnt1=categoryHistPos.containsKey(key) ? categoryHistPos.get(key) : 0;
    double rate;
    if (cnt0 + cnt1 == 0) {
      rate=0;
    }
 else {
      rate=cnt1 / (cnt0 + cnt1);
    }
    categoryFraudRateMap.put(key,rate);
  }
  MapComparator cmp=new MapComparator(categoryFraudRateMap);
  Map<String,Double> sortedCategoryFraudRateMap=new TreeMap<String,Double>(cmp);
  sortedCategoryFraudRateMap.putAll(categoryFraudRateMap);
  for (  Map.Entry<String,Double> entry : sortedCategoryFraudRateMap.entrySet()) {
    String key=entry.getKey();
    Integer countNeg=categoryHistNeg.containsKey(key) ? categoryHistNeg.get(key) : 0;
    binCountNeg.add(countNeg);
    Integer countPos=categoryHistPos.containsKey(key) ? categoryHistPos.get(key) : 0;
    binCountPos.add(countPos);
    Double weightedNeg=categoryWeightedNeg.containsKey(key) ? categoryWeightedNeg.get(key) : 0.0;
    this.binWeightedNeg.add(weightedNeg);
    Double weightedPos=categoryWeightedPos.containsKey(key) ? categoryWeightedPos.get(key) : 0.0;
    this.binWeightedPos.add(weightedPos);
    binAvgScore.add(0);
    binCategory.add(key);
    binPosCaseRate.add(entry.getValue());
  }
  this.actualNumBins=binCategory.size();
  for (  ValueObject vo : voList) {
    String key=vo.getRaw();
    if (binCategory.indexOf(key) == -1) {
      vo.setValue(0.0);
    }
 else {
      vo.setValue(binPosCaseRate.get(binCategory.indexOf(key)));
    }
  }
}