Program: 32034
Project: 32034
Buggy source:
public void bufferedComputeConfusionMatrixAndPerformance(long pigPosTags,long pigNegTags,double pigPosWeightTags,double pigNegWeightTags,long records) throws IOException {
  PathFinder pathFinder=new PathFinder(modelConfig);
  SourceType sourceType=evalConfig.getDataSet().getSource();
  List<Scanner> scanners=ShifuFileUtils.getDataScanners(pathFinder.getEvalScorePath(evalConfig,sourceType),sourceType);
  int numBucket=evalConfig.getPerformanceBucketNum();
  boolean isWeight=evalConfig.getDataSet().getWeightColumnName() != null;
  boolean isDir=ShifuFileUtils.isDir(pathFinder.getEvalScorePath(evalConfig,sourceType),sourceType);
  List<PerformanceObject> FPRList=new ArrayList<PerformanceObject>(numBucket + 1);
  List<PerformanceObject> catchRateList=new ArrayList<PerformanceObject>(numBucket + 1);
  List<PerformanceObject> gainList=new ArrayList<PerformanceObject>(numBucket + 1);
  List<PerformanceObject> FPRWeightList=new ArrayList<PerformanceObject>(numBucket + 1);
  List<PerformanceObject> catchRateWeightList=new ArrayList<PerformanceObject>(numBucket + 1);
  List<PerformanceObject> gainWeightList=new ArrayList<PerformanceObject>(numBucket + 1);
  int fpBin=1, tpBin=1, gainBin=1, fpWeightBin=1, tpWeightBin=1, gainWeightBin=1;
  double binCapacity=1.0 / numBucket;
  PerformanceObject po=null;
  int i=0;
  log.info("String_Node_Str",scanners.size());
  int cnt=0;
  Set<String> posTags=new HashSet<String>(modelConfig.getPosTags(evalConfig));
  Set<String> negTags=new HashSet<String>(modelConfig.getNegTags(evalConfig));
  ConfusionMatrixObject prevCmo=new ConfusionMatrixObject();
  prevCmo.setTp(0.0);
  prevCmo.setFp(0.0);
  prevCmo.setFn(pigPosTags);
  prevCmo.setTn(pigNegTags);
  prevCmo.setWeightedTp(0.0);
  prevCmo.setWeightedFp(0.0);
  prevCmo.setWeightedFn(pigPosWeightTags);
  prevCmo.setWeightedTn(pigNegWeightTags);
  prevCmo.setScore(1000);
  po=PerformanceEvaluator.setPerformanceObject(prevCmo);
  po.precision=1.0;
  po.weightedPrecision=1.0;
  po.liftUnit=0.0;
  po.weightLiftUnit=0.0;
  FPRList.add(po);
  catchRateList.add(po);
  gainList.add(po);
  FPRWeightList.add(po);
  catchRateWeightList.add(po);
  gainWeightList.add(po);
  for (  Scanner scanner : scanners) {
    while (scanner.hasNext()) {
      if ((++cnt) % 100000 == 0) {
        log.info("String_Node_Str" + cnt + "String_Node_Str");
      }
      String[] raw=scanner.nextLine().split("String_Node_Str");
      if ((!isDir) && cnt == 1) {
        continue;
      }
      String tag=raw[targetColumnIndex];
      if (StringUtils.isBlank(tag) || (!posTags.contains(tag) && !negTags.contains(tag))) {
        if (rd.nextDouble() < 0.01) {
          log.warn("String_Node_Str",tag);
        }
        continue;
      }
      double weight=1.0d;
      if (this.weightColumnIndex > 0) {
        try {
          weight=Double.parseDouble(raw[1]);
        }
 catch (        NumberFormatException e) {
        }
      }
      double score=0.0;
      try {
        score=Double.parseDouble(raw[scoreColumnIndex]);
      }
 catch (      NumberFormatException e) {
        if (rd.nextDouble() < 0.05) {
          log.warn("String_Node_Str",raw[scoreColumnIndex]);
        }
        continue;
      }
      ConfusionMatrixObject cmo=new ConfusionMatrixObject(prevCmo);
      if (posTags.contains(tag)) {
        cmo.setTp(cmo.getTp() + 1);
        cmo.setFn(cmo.getFn() - 1);
        cmo.setWeightedTp(cmo.getWeightedTp() + weight * 1.0);
        cmo.setWeightedFn(cmo.getWeightedFn() - weight * 1.0);
      }
 else {
        cmo.setFp(cmo.getFp() + 1);
        cmo.setTn(cmo.getTn() - 1);
        cmo.setWeightedFp(cmo.getWeightedFp() + weight * 1.0);
        cmo.setWeightedTn(cmo.getWeightedTn() - weight * 1.0);
      }
      cmo.setScore(score);
      ConfusionMatrixObject object=cmo;
      po=PerformanceEvaluator.setPerformanceObject(object);
      if (po.fpr >= fpBin * binCapacity) {
        po.binNum=fpBin++;
        FPRList.add(po);
      }
      if (po.recall >= tpBin * binCapacity) {
        po.binNum=tpBin++;
        catchRateList.add(po);
      }
      if ((double)(i + 1) / records >= gainBin * binCapacity) {
        po.binNum=gainBin++;
        gainList.add(po);
      }
      if (po.weightedFpr >= fpWeightBin * binCapacity) {
        po.binNum=fpWeightBin++;
        FPRWeightList.add(po);
      }
      if (po.weightedRecall >= tpWeightBin * binCapacity) {
        po.binNum=tpWeightBin++;
        catchRateWeightList.add(po);
      }
      if ((object.getWeightedTp() + object.getWeightedFp() + 1) / object.getWeightedTotal() >= gainWeightBin * binCapacity) {
        po.binNum=gainWeightBin++;
        gainWeightList.add(po);
      }
      i++;
      prevCmo=cmo;
    }
    scanner.close();
  }
  log.info("String_Node_Str" + cnt + "String_Node_Str");
  PerformanceEvaluator.logResult(FPRList,"String_Node_Str");
  if (isWeight) {
    PerformanceEvaluator.logResult(FPRWeightList,"String_Node_Str");
  }
  PerformanceEvaluator.logResult(catchRateList,"String_Node_Str");
  if (isWeight) {
    PerformanceEvaluator.logResult(catchRateWeightList,"String_Node_Str");
  }
  PerformanceEvaluator.logResult(gainList,"String_Node_Str");
  if (isWeight) {
    PerformanceEvaluator.logResult(gainWeightList,"String_Node_Str");
  }
  PerformanceResult result=new PerformanceResult();
  result.version=Constants.version;
  result.pr=catchRateList;
  result.weightedPr=catchRateWeightList;
  result.roc=FPRList;
  result.weightedRoc=FPRWeightList;
  result.gains=gainList;
  result.weightedGains=gainWeightList;
  result.areaUnderRoc=AreaUnderCurve.ofRoc(result.roc);
  result.weightedAreaUnderRoc=AreaUnderCurve.ofWeightedRoc(result.weightedRoc);
  result.areaUnderPr=AreaUnderCurve.ofPr(result.pr);
  result.weightedAreaUnderPr=AreaUnderCurve.ofWeightedPr(result.weightedPr);
  PerformanceEvaluator.logAucResult(result,isWeight);
  Writer writer=null;
  try {
    writer=ShifuFileUtils.getWriter(pathFinder.getEvalPerformancePath(evalConfig,evalConfig.getDataSet().getSource()),evalConfig.getDataSet().getSource());
    JSONUtils.writeValue(writer,result);
  }
 catch (  IOException e) {
    IOUtils.closeQuietly(writer);
  }
  if (cnt == 0) {
    log.error("String_Node_Str");
    throw new ShifuException(ShifuErrorCode.ERROR_EVALSCORE);
  }
}

Fixed version (ground truth):
public void bufferedComputeConfusionMatrixAndPerformance(long pigPosTags,long pigNegTags,double pigPosWeightTags,double pigNegWeightTags,long records) throws IOException {
  PathFinder pathFinder=new PathFinder(modelConfig);
  SourceType sourceType=evalConfig.getDataSet().getSource();
  List<Scanner> scanners=ShifuFileUtils.getDataScanners(pathFinder.getEvalScorePath(evalConfig,sourceType),sourceType);
  int numBucket=evalConfig.getPerformanceBucketNum();
  boolean isWeight=evalConfig.getDataSet().getWeightColumnName() != null;
  boolean isDir=ShifuFileUtils.isDir(pathFinder.getEvalScorePath(evalConfig,sourceType),sourceType);
  List<PerformanceObject> FPRList=new ArrayList<PerformanceObject>(numBucket + 1);
  List<PerformanceObject> catchRateList=new ArrayList<PerformanceObject>(numBucket + 1);
  List<PerformanceObject> gainList=new ArrayList<PerformanceObject>(numBucket + 1);
  List<PerformanceObject> FPRWeightList=new ArrayList<PerformanceObject>(numBucket + 1);
  List<PerformanceObject> catchRateWeightList=new ArrayList<PerformanceObject>(numBucket + 1);
  List<PerformanceObject> gainWeightList=new ArrayList<PerformanceObject>(numBucket + 1);
  int fpBin=1, tpBin=1, gainBin=1, fpWeightBin=1, tpWeightBin=1, gainWeightBin=1;
  double binCapacity=1.0 / numBucket;
  PerformanceObject po=null;
  int i=0;
  log.info("String_Node_Str",scanners.size());
  int cnt=0;
  Set<String> posTags=new HashSet<String>(modelConfig.getPosTags(evalConfig));
  Set<String> negTags=new HashSet<String>(modelConfig.getNegTags(evalConfig));
  ConfusionMatrixObject prevCmo=new ConfusionMatrixObject();
  prevCmo.setTp(0.0);
  prevCmo.setFp(0.0);
  prevCmo.setFn(pigPosTags);
  prevCmo.setTn(pigNegTags);
  prevCmo.setWeightedTp(0.0);
  prevCmo.setWeightedFp(0.0);
  prevCmo.setWeightedFn(pigPosWeightTags);
  prevCmo.setWeightedTn(pigNegWeightTags);
  prevCmo.setScore(1000);
  po=PerformanceEvaluator.setPerformanceObject(prevCmo);
  po.precision=1.0;
  po.weightedPrecision=1.0;
  po.liftUnit=0.0;
  po.weightLiftUnit=0.0;
  FPRList.add(po);
  catchRateList.add(po);
  gainList.add(po);
  FPRWeightList.add(po);
  catchRateWeightList.add(po);
  gainWeightList.add(po);
  for (  Scanner scanner : scanners) {
    while (scanner.hasNext()) {
      if ((++cnt) % 100000 == 0) {
        log.info("String_Node_Str" + cnt + "String_Node_Str");
      }
      String[] raw=scanner.nextLine().split("String_Node_Str");
      if ((!isDir) && cnt == 1) {
        continue;
      }
      String tag=raw[targetColumnIndex];
      if (StringUtils.isBlank(tag) || (!posTags.contains(tag) && !negTags.contains(tag))) {
        if (rd.nextDouble() < 0.01) {
          log.warn("String_Node_Str",tag);
        }
        continue;
      }
      double weight=1.0d;
      if (this.weightColumnIndex > 0) {
        try {
          weight=Double.parseDouble(raw[1]);
        }
 catch (        NumberFormatException e) {
        }
      }
      double score=0.0;
      try {
        score=Double.parseDouble(raw[scoreColumnIndex]);
      }
 catch (      NumberFormatException e) {
        if (rd.nextDouble() < 0.05) {
          log.warn("String_Node_Str",raw[scoreColumnIndex]);
        }
        continue;
      }
      if (cnt == 1 && CommonConstants.GBDT_ALG_NAME.equalsIgnoreCase(modelConfig.getAlgorithm())) {
        po.binLowestScore=score;
      }
      ConfusionMatrixObject cmo=new ConfusionMatrixObject(prevCmo);
      if (posTags.contains(tag)) {
        cmo.setTp(cmo.getTp() + 1);
        cmo.setFn(cmo.getFn() - 1);
        cmo.setWeightedTp(cmo.getWeightedTp() + weight * 1.0);
        cmo.setWeightedFn(cmo.getWeightedFn() - weight * 1.0);
      }
 else {
        cmo.setFp(cmo.getFp() + 1);
        cmo.setTn(cmo.getTn() - 1);
        cmo.setWeightedFp(cmo.getWeightedFp() + weight * 1.0);
        cmo.setWeightedTn(cmo.getWeightedTn() - weight * 1.0);
      }
      cmo.setScore(score);
      ConfusionMatrixObject object=cmo;
      po=PerformanceEvaluator.setPerformanceObject(object);
      if (po.fpr >= fpBin * binCapacity) {
        po.binNum=fpBin++;
        FPRList.add(po);
      }
      if (po.recall >= tpBin * binCapacity) {
        po.binNum=tpBin++;
        catchRateList.add(po);
      }
      if ((double)(i + 1) / records >= gainBin * binCapacity) {
        po.binNum=gainBin++;
        gainList.add(po);
      }
      if (po.weightedFpr >= fpWeightBin * binCapacity) {
        po.binNum=fpWeightBin++;
        FPRWeightList.add(po);
      }
      if (po.weightedRecall >= tpWeightBin * binCapacity) {
        po.binNum=tpWeightBin++;
        catchRateWeightList.add(po);
      }
      if ((object.getWeightedTp() + object.getWeightedFp() + 1) / object.getWeightedTotal() >= gainWeightBin * binCapacity) {
        po.binNum=gainWeightBin++;
        gainWeightList.add(po);
      }
      i++;
      prevCmo=cmo;
    }
    scanner.close();
  }
  log.info("String_Node_Str" + cnt + "String_Node_Str");
  PerformanceEvaluator.logResult(FPRList,"String_Node_Str");
  if (isWeight) {
    PerformanceEvaluator.logResult(FPRWeightList,"String_Node_Str");
  }
  PerformanceEvaluator.logResult(catchRateList,"String_Node_Str");
  if (isWeight) {
    PerformanceEvaluator.logResult(catchRateWeightList,"String_Node_Str");
  }
  PerformanceEvaluator.logResult(gainList,"String_Node_Str");
  if (isWeight) {
    PerformanceEvaluator.logResult(gainWeightList,"String_Node_Str");
  }
  PerformanceResult result=new PerformanceResult();
  result.version=Constants.version;
  result.pr=catchRateList;
  result.weightedPr=catchRateWeightList;
  result.roc=FPRList;
  result.weightedRoc=FPRWeightList;
  result.gains=gainList;
  result.weightedGains=gainWeightList;
  result.areaUnderRoc=AreaUnderCurve.ofRoc(result.roc);
  result.weightedAreaUnderRoc=AreaUnderCurve.ofWeightedRoc(result.weightedRoc);
  result.areaUnderPr=AreaUnderCurve.ofPr(result.pr);
  result.weightedAreaUnderPr=AreaUnderCurve.ofWeightedPr(result.weightedPr);
  PerformanceEvaluator.logAucResult(result,isWeight);
  Writer writer=null;
  try {
    writer=ShifuFileUtils.getWriter(pathFinder.getEvalPerformancePath(evalConfig,evalConfig.getDataSet().getSource()),evalConfig.getDataSet().getSource());
    JSONUtils.writeValue(writer,result);
  }
 catch (  IOException e) {
    IOUtils.closeQuietly(writer);
  }
  if (cnt == 0) {
    log.error("String_Node_Str");
    throw new ShifuException(ShifuErrorCode.ERROR_EVALSCORE);
  }
}