Program: 32029
Project: 32029
Buggy source:
@Override public DTWorkerParams doCompute(WorkerContext<DTMasterParams,DTWorkerParams> context){
  if (context.isFirstIteration()) {
    return new DTWorkerParams();
  }
  DTMasterParams lastMasterResult=context.getLastMasterResult();
  List<TreeNode> trees=lastMasterResult.getTrees();
  Map<Integer,TreeNode> todoNodes=lastMasterResult.getTodoNodes();
  if (todoNodes == null) {
    return new DTWorkerParams();
  }
  Map<Integer,NodeStats> statistics=initTodoNodeStats(todoNodes);
  double squareError=0d;
  List<Integer> nodeIndexes=new ArrayList<Integer>(trees.size());
  if (this.isGBDT && !this.gbdtSampleWithReplacement && lastMasterResult.isSwitchToNextTree()) {
    this.random=new Random();
  }
  for (  Data data : this.trainingData) {
    nodeIndexes.clear();
    squareError+=computeErrorAndUpdateNodeIndex(lastMasterResult,trees,nodeIndexes,data);
    updateTodoNodeStats(todoNodes,statistics,nodeIndexes,data);
  }
  LOG.info("String_Node_Str",count,squareError,statistics.size());
  return new DTWorkerParams(count,squareError,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 squareError=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) {
          squareError+=loss.computeError((float)(predictNode.getPredict().getPredict()),data.label);
        }
      }
    }
    if (this.isGBDT) {
      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]=1f;
            }
 else {
              data.subsampleWeights[currTreeIndex]=0f;
            }
          }
        }
      }
      Node predictNode=predictNodeIndex(trees.get(currTreeIndex).getNode(),data);
      if (currTreeIndex >= 1) {
        squareError+=loss.computeError(data.predict,data.label);
      }
 else {
        if (predictNode.getPredict() != null) {
          squareError+=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];
                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,squareError,statistics.size());
  return new DTWorkerParams(count,squareError,statistics);
}