Program: 31776
Project: 31776
Buggy source:
@SuppressWarnings("String_Node_Str") public void computeConfusionMatixForMultipleClassification(long records) throws IOException {
  PathFinder pathFinder=new PathFinder(modelConfig);
  SourceType sourceType=evalConfig.getDataSet().getSource();
  List<Scanner> scanners=ShifuFileUtils.getDataScanners(pathFinder.getEvalScorePath(evalConfig,sourceType),sourceType);
  boolean isDir=ShifuFileUtils.isDir(pathFinder.getEvalScorePath(evalConfig,sourceType),sourceType);
  int cnt=0;
  Set<String> posTags=new HashSet<String>(modelConfig.getPosTags(evalConfig));
  Set<String> negTags=new HashSet<String>(modelConfig.getNegTags(evalConfig));
  Set<String> tagSet=new HashSet<String>(modelConfig.getFlattenTags(modelConfig.getPosTags(evalConfig),modelConfig.getNegTags(evalConfig)));
  List<Set<String>> tags=modelConfig.getSetTags(modelConfig.getPosTags(evalConfig),modelConfig.getNegTags(evalConfig));
  int classes=tags.size();
  long[][] confusionMatrix=new long[classes][classes];
  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 (modelConfig.isRegression()) {
        if (StringUtils.isBlank(tag) || (!posTags.contains(tag) && !negTags.contains(tag))) {
          if (rd.nextDouble() < 0.01) {
            log.warn("String_Node_Str");
          }
          continue;
        }
      }
 else {
        if (StringUtils.isBlank(tag) || !tagSet.contains(tag)) {
          if (rd.nextDouble() < 0.01) {
            log.warn("String_Node_Str");
          }
          continue;
        }
      }
      double[] scores=new double[classes];
      int maxIndex=-1;
      double maxScore=Double.NEGATIVE_INFINITY;
      if (CommonUtils.isDesicionTreeAlgorithm(modelConfig.getAlgorithm()) && !modelConfig.getTrain().isOneVsAll()) {
        double[] tagCounts=new double[tags.size()];
        for (int i=this.multiClassScore1Index; i < raw.length; i++) {
          double dd=NumberFormatUtils.getDouble(raw[i],0d);
          tagCounts[(int)dd]+=1d;
        }
        double maxVotes=-1d;
        for (int i=0; i < tagCounts.length; i++) {
          if (tagCounts[i] > maxVotes) {
            maxIndex=i;
            maxScore=maxVotes=tagCounts[i];
          }
        }
      }
 else       if ((CommonUtils.isDesicionTreeAlgorithm(modelConfig.getAlgorithm()) || NNConstants.NN_ALG_NAME.equalsIgnoreCase(modelConfig.getAlgorithm())) && modelConfig.getTrain().isOneVsAll()) {
        for (int i=this.multiClassScore1Index; i < raw.length; i++) {
          double dd=NumberFormatUtils.getDouble(raw[i],0d);
          if (dd > maxScore) {
            maxScore=dd;
            maxIndex=i - this.multiClassScore1Index;
          }
        }
      }
 else {
        for (int i=0; i < classes; i++) {
          for (int j=0; j < multiClassModelCnt; j++) {
            double dd=NumberFormatUtils.getDouble(raw[this.multiClassScore1Index + j * classes + i],0d);
            scores[i]+=dd;
          }
          scores[i]/=multiClassModelCnt;
          if (scores[i] > maxScore) {
            maxIndex=i;
            maxScore=scores[i];
          }
        }
      }
      int tagIndex=-1;
      for (int i=0; i < tags.size(); i++) {
        if (tags.get(i).contains(tag)) {
          tagIndex=i;
          break;
        }
      }
      confusionMatrix[tagIndex][maxIndex]+=1L;
    }
    scanner.close();
  }
  Path localEvalMatrixFile=new Path(pathFinder.getEvalLocalMultiMatrixFile(evalConfig.getName()));
  log.info("String_Node_Str",localEvalMatrixFile);
  if (HDFSUtils.getLocalFS().exists(localEvalMatrixFile)) {
    HDFSUtils.getLocalFS().delete(localEvalMatrixFile);
  }
  BufferedWriter writer=null;
  try {
    writer=ShifuFileUtils.getWriter(localEvalMatrixFile.toString(),SourceType.LOCAL);
    writer.write("String_Node_Str" + StringUtils.join(tags,"String_Node_Str") + "String_Node_Str");
    for (int i=0; i < confusionMatrix.length; i++) {
      StringBuilder sb=new StringBuilder(300);
      sb.append(tags.get(i));
      for (int j=0; j < confusionMatrix[i].length; j++) {
        sb.append("String_Node_Str").append(confusionMatrix[i][j]);
      }
      sb.append("String_Node_Str");
      writer.write(tags.get(i) + "String_Node_Str" + sb.toString());
    }
  }
  finally {
    writer.close();
  }
  log.info("String_Node_Str");
  log.info(String.format("String_Node_Str","String_Node_Str",tags.toString()));
  for (int i=0; i < confusionMatrix.length; i++) {
    log.info(String.format("String_Node_Str",tags.get(i),Arrays.toString(confusionMatrix[i])));
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public void computeConfusionMatixForMultipleClassification(long records) throws IOException {
  PathFinder pathFinder=new PathFinder(modelConfig);
  SourceType sourceType=evalConfig.getDataSet().getSource();
  List<Scanner> scanners=ShifuFileUtils.getDataScanners(pathFinder.getEvalScorePath(evalConfig,sourceType),sourceType);
  boolean isDir=ShifuFileUtils.isDir(pathFinder.getEvalScorePath(evalConfig,sourceType),sourceType);
  int cnt=0;
  Set<String> tagSet=new HashSet<String>(modelConfig.getFlattenTags(modelConfig.getPosTags(evalConfig),modelConfig.getNegTags(evalConfig)));
  List<Set<String>> tags=modelConfig.getSetTags(modelConfig.getPosTags(evalConfig),modelConfig.getNegTags(evalConfig));
  int classes=tags.size();
  long[][] confusionMatrix=new long[classes][classes];
  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) || !tagSet.contains(tag)) {
        if (rd.nextDouble() < 0.01) {
          log.warn("String_Node_Str");
        }
        continue;
      }
      double[] scores=new double[classes];
      int maxIndex=-1;
      double maxScore=Double.NEGATIVE_INFINITY;
      if (CommonUtils.isDesicionTreeAlgorithm(modelConfig.getAlgorithm()) && !modelConfig.getTrain().isOneVsAll()) {
        double[] tagCounts=new double[tags.size()];
        for (int i=this.multiClassScore1Index; i < (raw.length - this.metaColumns); i++) {
          double dd=NumberFormatUtils.getDouble(raw[i],0d);
          tagCounts[(int)dd]+=1d;
        }
        double maxVotes=-1d;
        for (int i=0; i < tagCounts.length; i++) {
          if (tagCounts[i] > maxVotes) {
            maxIndex=i;
            maxScore=maxVotes=tagCounts[i];
          }
        }
      }
 else       if ((CommonUtils.isDesicionTreeAlgorithm(modelConfig.getAlgorithm()) || NNConstants.NN_ALG_NAME.equalsIgnoreCase(modelConfig.getAlgorithm())) && modelConfig.getTrain().isOneVsAll()) {
        for (int i=this.multiClassScore1Index; i < (classes + this.multiClassScore1Index); i++) {
          double dd=NumberFormatUtils.getDouble(raw[i],0d);
          if (dd > maxScore) {
            maxScore=dd;
            maxIndex=i - this.multiClassScore1Index;
          }
        }
      }
 else {
        for (int i=0; i < classes; i++) {
          for (int j=0; j < multiClassModelCnt; j++) {
            double dd=NumberFormatUtils.getDouble(raw[this.multiClassScore1Index + j * classes + i],0d);
            scores[i]+=dd;
          }
          scores[i]/=multiClassModelCnt;
          if (scores[i] > maxScore) {
            maxIndex=i;
            maxScore=scores[i];
          }
        }
      }
      int tagIndex=-1;
      for (int i=0; i < tags.size(); i++) {
        if (tags.get(i).contains(tag)) {
          tagIndex=i;
          break;
        }
      }
      confusionMatrix[tagIndex][maxIndex]+=1L;
    }
    scanner.close();
  }
  Path localEvalMatrixFile=new Path(pathFinder.getEvalLocalMultiMatrixFile(evalConfig.getName()));
  log.info("String_Node_Str",localEvalMatrixFile);
  if (HDFSUtils.getLocalFS().exists(localEvalMatrixFile)) {
    HDFSUtils.getLocalFS().delete(localEvalMatrixFile);
  }
  BufferedWriter writer=null;
  try {
    writer=ShifuFileUtils.getWriter(localEvalMatrixFile.toString(),SourceType.LOCAL);
    writer.write("String_Node_Str" + StringUtils.join(tags,"String_Node_Str") + "String_Node_Str");
    for (int i=0; i < confusionMatrix.length; i++) {
      StringBuilder sb=new StringBuilder(300);
      sb.append(tags.get(i));
      for (int j=0; j < confusionMatrix[i].length; j++) {
        sb.append("String_Node_Str").append(confusionMatrix[i][j]);
      }
      sb.append("String_Node_Str");
      writer.write(sb.toString());
    }
  }
  finally {
    writer.close();
  }
  log.info("String_Node_Str");
  log.info(String.format("String_Node_Str","String_Node_Str",tags.toString()));
  for (int i=0; i < confusionMatrix.length; i++) {
    log.info(String.format("String_Node_Str",tags.get(i),Arrays.toString(confusionMatrix[i])));
  }
}