Program: 32018
Project: 32018
Buggy source:
@Override public DTWorkerParams doCompute(WorkerContext<DTMasterParams,DTWorkerParams> context){
  if (context.isFirstIteration()) {
    return new DTWorkerParams();
  }
  DTMasterParams lastMasterResult=context.getLastMasterResult();
  final List<TreeNode> trees=lastMasterResult.getTrees();
  final Map<Integer,TreeNode> todoNodes=lastMasterResult.getTodoNodes();
  if (todoNodes == null) {
    return new DTWorkerParams();
  }
  Map<Integer,NodeStats> statistics=initTodoNodeStats(todoNodes);
  double trainError=0d, validationError=0d;
  if (this.isGBDT && !this.gbdtSampleWithReplacement && lastMasterResult.isSwitchToNextTree()) {
    this.random=new Random();
  }
  for (  Data data : this.trainingData) {
    if (this.isRF) {
      for (      TreeNode treeNode : trees) {
        Node predictNode=predictNodeIndex(treeNode.getNode(),data);
        if (predictNode.getPredict() != null) {
          trainError+=loss.computeError((float)(predictNode.getPredict().getPredict()),data.label);
        }
      }
    }
    if (this.isGBDT) {
      if (this.isContinuousEnabled && lastMasterResult.isContinuousRunningStart()) {
        recoverGBTData(context,data.output,data.predict,data);
        trainError+=loss.computeError(data.predict,data.label);
      }
 else {
        int currTreeIndex=trees.size() - 1;
        if (lastMasterResult.isSwitchToNextTree()) {
          if (currTreeIndex >= 1) {
            Node node=trees.get(currTreeIndex - 1).getNode();
            Node predictNode=predictNodeIndex(node,data);
            if (predictNode.getPredict() != null) {
              double predict=predictNode.getPredict().getPredict();
              if (currTreeIndex == 1) {
                data.predict=(float)predict;
              }
 else {
                data.predict+=(float)(this.learningRate * predict);
              }
              data.output=-1f * loss.computeGradient(data.predict,data.label);
            }
            if (!this.gbdtSampleWithReplacement) {
              if (random.nextDouble() <= modelConfig.getTrain().getBaggingSampleRate()) {
                data.subsampleWeights[currTreeIndex % data.subsampleWeights.length]=1f;
              }
 else {
                data.subsampleWeights[currTreeIndex % data.subsampleWeights.length]=0f;
              }
            }
          }
        }
        Node predictNode=predictNodeIndex(trees.get(currTreeIndex).getNode(),data);
        if (currTreeIndex >= 1) {
          trainError+=loss.computeError(data.predict,data.label);
        }
 else {
          if (predictNode.getPredict() != null) {
            trainError+=loss.computeError(((float)predictNode.getPredict().getPredict()),data.label);
          }
        }
      }
    }
  }
  if (validationData != null) {
    for (    Data data : this.validationData) {
      if (this.isRF) {
        for (        TreeNode treeNode : trees) {
          Node predictNode=predictNodeIndex(treeNode.getNode(),data);
          if (predictNode.getPredict() != null) {
            validationError+=loss.computeError((float)(predictNode.getPredict().getPredict()),data.label);
          }
        }
      }
      if (this.isGBDT) {
        if (this.isContinuousEnabled && lastMasterResult.isContinuousRunningStart()) {
          recoverGBTData(context,data.output,data.predict,data);
          validationError+=loss.computeError(data.predict,data.label);
        }
 else {
          int currTreeIndex=trees.size() - 1;
          if (lastMasterResult.isSwitchToNextTree()) {
            if (currTreeIndex >= 1) {
              Node node=trees.get(currTreeIndex - 1).getNode();
              Node predictNode=predictNodeIndex(node,data);
              if (predictNode.getPredict() != null) {
                double predict=predictNode.getPredict().getPredict();
                if (currTreeIndex == 1) {
                  data.predict=(float)predict;
                }
 else {
                  data.predict+=(float)(this.learningRate * predict);
                }
                data.output=-1f * loss.computeGradient(data.predict,data.label);
              }
              if (!this.gbdtSampleWithReplacement) {
                if (random.nextDouble() <= modelConfig.getTrain().getBaggingSampleRate()) {
                  data.subsampleWeights[currTreeIndex % data.subsampleWeights.length]=1f;
                }
 else {
                  data.subsampleWeights[currTreeIndex % data.subsampleWeights.length]=0f;
                }
              }
            }
          }
          Node predictNode=predictNodeIndex(trees.get(currTreeIndex).getNode(),data);
          if (currTreeIndex >= 1) {
            validationError+=loss.computeError(data.predict,data.label);
          }
 else {
            if (predictNode.getPredict() != null) {
              validationError+=loss.computeError(((float)predictNode.getPredict().getPredict()),data.label);
            }
          }
        }
      }
    }
  }
  CompletionService<Map<Integer,NodeStats>> completionService=new ExecutorCompletionService<Map<Integer,NodeStats>>(this.threadPool);
  Set<Entry<Integer,TreeNode>> treeNodeEntrySet=todoNodes.entrySet();
  Iterator<Entry<Integer,TreeNode>> treeNodeIterator=treeNodeEntrySet.iterator();
  int roundNodeNumer=treeNodeEntrySet.size() / this.workerThreadCount;
  int modeNodeNumber=treeNodeEntrySet.size() % this.workerThreadCount;
  int realThreadCount=0;
  LOG.info("String_Node_Str",todoNodes.size());
  for (int i=0; i < this.workerThreadCount; i++) {
    final Map<Integer,TreeNode> localTodoNodes=new HashMap<Integer,TreeNode>();
    final Map<Integer,NodeStats> localStatistics=new HashMap<Integer,DTWorkerParams.NodeStats>();
    for (int j=0; j < roundNodeNumer; j++) {
      Entry<Integer,TreeNode> tmpTreeNode=treeNodeIterator.next();
      localTodoNodes.put(tmpTreeNode.getKey(),tmpTreeNode.getValue());
      localStatistics.put(tmpTreeNode.getKey(),statistics.get(tmpTreeNode.getKey()));
    }
    if (modeNodeNumber > 0) {
      Entry<Integer,TreeNode> tmpTreeNode=treeNodeIterator.next();
      localTodoNodes.put(tmpTreeNode.getKey(),tmpTreeNode.getValue());
      localStatistics.put(tmpTreeNode.getKey(),statistics.get(tmpTreeNode.getKey()));
      modeNodeNumber-=1;
    }
    LOG.info("String_Node_Str",i,localTodoNodes.size(),localStatistics.size());
    if (localTodoNodes.size() == 0) {
      continue;
    }
    realThreadCount+=1;
    completionService.submit(new Callable<Map<Integer,NodeStats>>(){
      @Override public Map<Integer,NodeStats> call() throws Exception {
        List<Integer> nodeIndexes=new ArrayList<Integer>(trees.size());
        for (        Data data : DTWorker.this.trainingData) {
          nodeIndexes.clear();
          if (DTWorker.this.isRF) {
            for (            TreeNode treeNode : trees) {
              Node predictNode=predictNodeIndex(treeNode.getNode(),data);
              nodeIndexes.add(predictNode.getId());
            }
          }
          if (DTWorker.this.isGBDT) {
            int currTreeIndex=trees.size() - 1;
            Node predictNode=predictNodeIndex(trees.get(currTreeIndex).getNode(),data);
            nodeIndexes.add(predictNode.getId());
          }
          for (          Map.Entry<Integer,TreeNode> entry : localTodoNodes.entrySet()) {
            Node todoNode=entry.getValue().getNode();
            int treeId=entry.getValue().getTreeId();
            int currPredictIndex=0;
            if (DTWorker.this.isRF) {
              currPredictIndex=nodeIndexes.get(entry.getValue().getTreeId());
            }
            if (DTWorker.this.isGBDT) {
              currPredictIndex=nodeIndexes.get(0);
            }
            if (todoNode.getId() == currPredictIndex) {
              List<Integer> features=entry.getValue().getFeatures();
              if (features.isEmpty()) {
                features=getAllValidFeatures();
              }
              for (              Integer columnNum : features) {
                ColumnConfig config=DTWorker.this.columnConfigList.get(columnNum);
                double[] featuerStatistic=localStatistics.get(entry.getKey()).getFeatureStatistics().get(columnNum);
                float weight=data.subsampleWeights[treeId % data.subsampleWeights.length];
                if (config.isNumerical()) {
                  float value=data.numericInputs[DTWorker.this.numericInputIndexMap.get(columnNum)];
                  int binIndex=getBinIndex(value,config.getBinBoundary());
                  DTWorker.this.impurity.featureUpdate(featuerStatistic,binIndex,data.output,data.significance,weight);
                }
 else                 if (config.isCategorical()) {
                  String category=data.categoricalInputs[DTWorker.this.categoricalInputIndexMap.get(columnNum)];
                  Integer binIndex=DTWorker.this.categoryIndexMap.get(columnNum).get(category);
                  if (binIndex == null) {
                    binIndex=config.getBinCategory().size();
                  }
                  DTWorker.this.impurity.featureUpdate(featuerStatistic,binIndex,data.output,data.significance,weight);
                }
 else {
                  throw new IllegalStateException("String_Node_Str");
                }
              }
            }
          }
        }
        return localStatistics;
      }
    }
);
  }
  int rCnt=0;
  while (rCnt < realThreadCount) {
    try {
      statistics.putAll(completionService.take().get());
    }
 catch (    ExecutionException e) {
      throw new RuntimeException(e);
    }
catch (    InterruptedException e) {
      Thread.currentThread().interrupt();
    }
    rCnt+=1;
  }
  LOG.info("String_Node_Str",count,trainError,statistics.size());
  return new DTWorkerParams(trainingData.size(),(this.validationData == null ? 0L : this.validationData.size()),trainError,validationError,statistics);
}

Fixed version (ground truth):
@Override public DTWorkerParams doCompute(WorkerContext<DTMasterParams,DTWorkerParams> context){
  if (context.isFirstIteration()) {
    return new DTWorkerParams();
  }
  DTMasterParams lastMasterResult=context.getLastMasterResult();
  final List<TreeNode> trees=lastMasterResult.getTrees();
  final Map<Integer,TreeNode> todoNodes=lastMasterResult.getTodoNodes();
  if (todoNodes == null) {
    return new DTWorkerParams();
  }
  Map<Integer,NodeStats> statistics=initTodoNodeStats(todoNodes);
  double trainError=0d, validationError=0d;
  double weightedTrainCount=0d, weightedValidationCount=0d;
  if (this.isGBDT && !this.gbdtSampleWithReplacement && lastMasterResult.isSwitchToNextTree()) {
    this.random=new Random();
  }
  for (  Data data : this.trainingData) {
    if (this.isRF) {
      for (      TreeNode treeNode : trees) {
        Node predictNode=predictNodeIndex(treeNode.getNode(),data);
        if (predictNode.getPredict() != null) {
          trainError+=data.significance * loss.computeError((float)(predictNode.getPredict().getPredict()),data.label);
          weightedTrainCount+=data.significance;
        }
      }
    }
    if (this.isGBDT) {
      if (this.isContinuousEnabled && lastMasterResult.isContinuousRunningStart()) {
        recoverGBTData(context,data.output,data.predict,data);
        trainError+=data.significance * loss.computeError(data.predict,data.label);
        weightedTrainCount+=data.significance;
      }
 else {
        int currTreeIndex=trees.size() - 1;
        if (lastMasterResult.isSwitchToNextTree()) {
          if (currTreeIndex >= 1) {
            Node node=trees.get(currTreeIndex - 1).getNode();
            Node predictNode=predictNodeIndex(node,data);
            if (predictNode.getPredict() != null) {
              double predict=predictNode.getPredict().getPredict();
              if (currTreeIndex == 1) {
                data.predict=(float)predict;
              }
 else {
                data.predict+=(float)(this.learningRate * predict);
              }
              data.output=-1f * loss.computeGradient(data.predict,data.label);
            }
            if (!this.gbdtSampleWithReplacement) {
              if (random.nextDouble() <= modelConfig.getTrain().getBaggingSampleRate()) {
                data.subsampleWeights[currTreeIndex % data.subsampleWeights.length]=1f;
              }
 else {
                data.subsampleWeights[currTreeIndex % data.subsampleWeights.length]=0f;
              }
            }
          }
        }
        Node predictNode=predictNodeIndex(trees.get(currTreeIndex).getNode(),data);
        if (currTreeIndex >= 1) {
          trainError+=data.significance * loss.computeError(data.predict,data.label);
          weightedTrainCount+=data.significance;
        }
 else {
          if (predictNode.getPredict() != null) {
            trainError+=data.significance * loss.computeError(((float)predictNode.getPredict().getPredict()),data.label);
            weightedTrainCount+=data.significance;
          }
        }
      }
    }
  }
  if (validationData != null) {
    for (    Data data : this.validationData) {
      if (this.isRF) {
        for (        TreeNode treeNode : trees) {
          Node predictNode=predictNodeIndex(treeNode.getNode(),data);
          if (predictNode.getPredict() != null) {
            validationError+=data.significance * loss.computeError((float)(predictNode.getPredict().getPredict()),data.label);
            weightedValidationCount+=data.significance;
          }
        }
      }
      if (this.isGBDT) {
        if (this.isContinuousEnabled && lastMasterResult.isContinuousRunningStart()) {
          recoverGBTData(context,data.output,data.predict,data);
          validationError+=data.significance * loss.computeError(data.predict,data.label);
          weightedValidationCount+=data.significance;
        }
 else {
          int currTreeIndex=trees.size() - 1;
          if (lastMasterResult.isSwitchToNextTree()) {
            if (currTreeIndex >= 1) {
              Node node=trees.get(currTreeIndex - 1).getNode();
              Node predictNode=predictNodeIndex(node,data);
              if (predictNode.getPredict() != null) {
                double predict=predictNode.getPredict().getPredict();
                if (currTreeIndex == 1) {
                  data.predict=(float)predict;
                }
 else {
                  data.predict+=(float)(this.learningRate * predict);
                }
                data.output=-1f * loss.computeGradient(data.predict,data.label);
              }
              if (!this.gbdtSampleWithReplacement) {
                if (random.nextDouble() <= modelConfig.getTrain().getBaggingSampleRate()) {
                  data.subsampleWeights[currTreeIndex % data.subsampleWeights.length]=1f;
                }
 else {
                  data.subsampleWeights[currTreeIndex % data.subsampleWeights.length]=0f;
                }
              }
            }
          }
          Node predictNode=predictNodeIndex(trees.get(currTreeIndex).getNode(),data);
          if (currTreeIndex >= 1) {
            validationError+=data.significance * loss.computeError(data.predict,data.label);
            weightedValidationCount+=data.significance;
          }
 else {
            if (predictNode.getPredict() != null) {
              validationError+=data.significance * loss.computeError(((float)predictNode.getPredict().getPredict()),data.label);
              weightedValidationCount+=data.significance;
            }
          }
        }
      }
    }
  }
  CompletionService<Map<Integer,NodeStats>> completionService=new ExecutorCompletionService<Map<Integer,NodeStats>>(this.threadPool);
  Set<Entry<Integer,TreeNode>> treeNodeEntrySet=todoNodes.entrySet();
  Iterator<Entry<Integer,TreeNode>> treeNodeIterator=treeNodeEntrySet.iterator();
  int roundNodeNumer=treeNodeEntrySet.size() / this.workerThreadCount;
  int modeNodeNumber=treeNodeEntrySet.size() % this.workerThreadCount;
  int realThreadCount=0;
  LOG.info("String_Node_Str",todoNodes.size());
  for (int i=0; i < this.workerThreadCount; i++) {
    final Map<Integer,TreeNode> localTodoNodes=new HashMap<Integer,TreeNode>();
    final Map<Integer,NodeStats> localStatistics=new HashMap<Integer,DTWorkerParams.NodeStats>();
    for (int j=0; j < roundNodeNumer; j++) {
      Entry<Integer,TreeNode> tmpTreeNode=treeNodeIterator.next();
      localTodoNodes.put(tmpTreeNode.getKey(),tmpTreeNode.getValue());
      localStatistics.put(tmpTreeNode.getKey(),statistics.get(tmpTreeNode.getKey()));
    }
    if (modeNodeNumber > 0) {
      Entry<Integer,TreeNode> tmpTreeNode=treeNodeIterator.next();
      localTodoNodes.put(tmpTreeNode.getKey(),tmpTreeNode.getValue());
      localStatistics.put(tmpTreeNode.getKey(),statistics.get(tmpTreeNode.getKey()));
      modeNodeNumber-=1;
    }
    LOG.info("String_Node_Str",i,localTodoNodes.size(),localStatistics.size());
    if (localTodoNodes.size() == 0) {
      continue;
    }
    realThreadCount+=1;
    completionService.submit(new Callable<Map<Integer,NodeStats>>(){
      @Override public Map<Integer,NodeStats> call() throws Exception {
        List<Integer> nodeIndexes=new ArrayList<Integer>(trees.size());
        for (        Data data : DTWorker.this.trainingData) {
          nodeIndexes.clear();
          if (DTWorker.this.isRF) {
            for (            TreeNode treeNode : trees) {
              Node predictNode=predictNodeIndex(treeNode.getNode(),data);
              nodeIndexes.add(predictNode.getId());
            }
          }
          if (DTWorker.this.isGBDT) {
            int currTreeIndex=trees.size() - 1;
            Node predictNode=predictNodeIndex(trees.get(currTreeIndex).getNode(),data);
            nodeIndexes.add(predictNode.getId());
          }
          for (          Map.Entry<Integer,TreeNode> entry : localTodoNodes.entrySet()) {
            Node todoNode=entry.getValue().getNode();
            int treeId=entry.getValue().getTreeId();
            int currPredictIndex=0;
            if (DTWorker.this.isRF) {
              currPredictIndex=nodeIndexes.get(entry.getValue().getTreeId());
            }
            if (DTWorker.this.isGBDT) {
              currPredictIndex=nodeIndexes.get(0);
            }
            if (todoNode.getId() == currPredictIndex) {
              List<Integer> features=entry.getValue().getFeatures();
              if (features.isEmpty()) {
                features=getAllValidFeatures();
              }
              for (              Integer columnNum : features) {
                ColumnConfig config=DTWorker.this.columnConfigList.get(columnNum);
                double[] featuerStatistic=localStatistics.get(entry.getKey()).getFeatureStatistics().get(columnNum);
                float weight=data.subsampleWeights[treeId % data.subsampleWeights.length];
                if (config.isNumerical()) {
                  float value=data.numericInputs[DTWorker.this.numericInputIndexMap.get(columnNum)];
                  int binIndex=getBinIndex(value,config.getBinBoundary());
                  DTWorker.this.impurity.featureUpdate(featuerStatistic,binIndex,data.output,data.significance,weight);
                }
 else                 if (config.isCategorical()) {
                  String category=data.categoricalInputs[DTWorker.this.categoricalInputIndexMap.get(columnNum)];
                  Integer binIndex=DTWorker.this.categoryIndexMap.get(columnNum).get(category);
                  if (binIndex == null) {
                    binIndex=config.getBinCategory().size();
                  }
                  DTWorker.this.impurity.featureUpdate(featuerStatistic,binIndex,data.output,data.significance,weight);
                }
 else {
                  throw new IllegalStateException("String_Node_Str");
                }
              }
            }
          }
        }
        return localStatistics;
      }
    }
);
  }
  int rCnt=0;
  while (rCnt < realThreadCount) {
    try {
      statistics.putAll(completionService.take().get());
    }
 catch (    ExecutionException e) {
      throw new RuntimeException(e);
    }
catch (    InterruptedException e) {
      Thread.currentThread().interrupt();
    }
    rCnt+=1;
  }
  LOG.info("String_Node_Str",count,trainError,statistics.size());
  return new DTWorkerParams(weightedTrainCount,weightedValidationCount,trainError,validationError,statistics);
}