Program: 31941
Project: 31941
Buggy source:
/** 
 * If earlyStopEnabled is true, the early stop feature will be enabled
 */
@Override public DTMasterParams doCompute(MasterContext<DTMasterParams,DTWorkerParams> context){
  if (context.isFirstIteration()) {
    return buildInitialMasterParams();
  }
  if (this.cpMasterParams != null) {
    DTMasterParams tmpMasterParams=rebuildRecoverMasterResultDepthList();
    this.cpMasterParams=null;
    if (this.isGBDT) {
      tmpMasterParams.setTrees(trees.subList(trees.size() - 1,trees.size()));
      tmpMasterParams.setTmpTrees(this.trees);
    }
    return tmpMasterParams;
  }
  boolean isFirst=false;
  Map<Integer,NodeStats> nodeStatsMap=null;
  double trainError=0d, validationError=0d;
  double weightedTrainCount=0d, weightedValidationCount=0d;
  for (  DTWorkerParams params : context.getWorkerResults()) {
    if (!isFirst) {
      isFirst=true;
      nodeStatsMap=params.getNodeStatsMap();
    }
 else {
      Map<Integer,NodeStats> currNodeStatsmap=params.getNodeStatsMap();
      for (      Entry<Integer,NodeStats> entry : nodeStatsMap.entrySet()) {
        NodeStats resultNodeStats=entry.getValue();
        mergeNodeStats(resultNodeStats,currNodeStatsmap.get(entry.getKey()));
      }
    }
    trainError+=params.getTrainError();
    validationError+=params.getValidationError();
    weightedTrainCount+=params.getTrainCount();
    weightedValidationCount+=params.getValidationCount();
  }
  for (  Entry<Integer,NodeStats> entry : nodeStatsMap.entrySet()) {
    NodeStats nodeStats=entry.getValue();
    int treeId=nodeStats.getTreeId();
    Node doneNode=Node.getNode(trees.get(treeId).getNode(),nodeStats.getNodeId());
    Map<Integer,double[]> statistics=nodeStats.getFeatureStatistics();
    List<GainInfo> gainList=new ArrayList<GainInfo>();
    for (    Entry<Integer,double[]> gainEntry : statistics.entrySet()) {
      int columnNum=gainEntry.getKey();
      ColumnConfig config=this.columnConfigList.get(columnNum);
      double[] statsArray=gainEntry.getValue();
      GainInfo gainInfo=this.impurity.computeImpurity(statsArray,config);
      if (gainInfo != null) {
        gainList.add(gainInfo);
      }
    }
    GainInfo maxGainInfo=GainInfo.getGainInfoByMaxGain(gainList);
    if (maxGainInfo == null) {
      doneNode.setLeaf(true);
      continue;
    }
    populateGainInfoToNode(treeId,doneNode,maxGainInfo);
    if (this.isLeafWise) {
      boolean isNotSplit=maxGainInfo.getGain() <= 0d;
      if (!isNotSplit) {
        this.toSplitQueue.offer(new TreeNode(treeId,doneNode));
      }
 else {
        LOG.info("String_Node_Str",doneNode.getId(),treeId);
      }
    }
 else {
      boolean isLeaf=maxGainInfo.getGain() <= 0d || Node.indexToLevel(doneNode.getId()) == this.maxDepth;
      doneNode.setLeaf(isLeaf);
      splitNodeForLevelWisedTree(isLeaf,treeId,doneNode);
    }
  }
  if (this.isLeafWise) {
    int currSplitIndex=0;
    while (!toSplitQueue.isEmpty() && currSplitIndex < this.maxBatchSplitSize) {
      TreeNode treeNode=this.toSplitQueue.poll();
      splitNodeForLeafWisedTree(treeNode.getTreeId(),treeNode.getNode());
    }
  }
  Map<Integer,TreeNode> todoNodes=new HashMap<Integer,TreeNode>();
  DTMasterParams masterParams=new DTMasterParams(weightedTrainCount,trainError,weightedValidationCount,validationError);
  if (toDoQueue.isEmpty()) {
    if (this.isGBDT) {
      TreeNode treeNode=this.trees.get(this.trees.size() - 1);
      Node node=treeNode.getNode();
      if (this.trees.size() == this.treeNum + this.existingTreeSize) {
        masterParams.setHalt(true);
        LOG.info("String_Node_Str",context.getCurrentIteration());
      }
 else       if (node.getLeft() == null && node.getRight() == null) {
        masterParams.setHalt(true);
        LOG.warn("String_Node_Str",context.getCurrentIteration());
      }
 else {
        masterParams.setFirstTree(this.trees.size() == 1);
        treeNode.setFeatures(null);
        TreeNode newRootNode=new TreeNode(this.trees.size(),new Node(Node.ROOT_INDEX),this.learningRate);
        LOG.info("String_Node_Str",this.trees.size());
        this.trees.add(newRootNode);
        newRootNode.setFeatures(getSubsamplingFeatures(this.featureSubsetStrategy));
        todoNodes.put(0,newRootNode);
        masterParams.setTodoNodes(todoNodes);
        masterParams.setSwitchToNextTree(true);
      }
    }
 else {
      masterParams.setHalt(true);
      LOG.info("String_Node_Str",context.getCurrentIteration());
    }
  }
 else {
    int nodeIndexInGroup=0;
    long currMem=0L;
    List<Integer> depthList=new ArrayList<Integer>();
    if (this.isGBDT) {
      depthList.add(-1);
    }
    if (isRF) {
      for (int i=0; i < this.trees.size(); i++) {
        depthList.add(-1);
      }
    }
    while (!toDoQueue.isEmpty() && currMem <= this.maxStatsMemory) {
      TreeNode node=this.toDoQueue.poll();
      int treeId=node.getTreeId();
      int oldDepth=this.isGBDT ? depthList.get(0) : depthList.get(treeId);
      int currDepth=Node.indexToLevel(node.getNode().getId());
      if (currDepth > oldDepth) {
        if (this.isGBDT) {
          depthList.set(0,currDepth);
        }
 else {
          depthList.set(treeId,currDepth);
        }
      }
      List<Integer> subsetFeatures=getSubsamplingFeatures(featureSubsetStrategy);
      node.setFeatures(subsetFeatures);
      currMem+=getStatsMem(subsetFeatures);
      todoNodes.put(nodeIndexInGroup,node);
      nodeIndexInGroup+=1;
    }
    masterParams.setTreeDepth(depthList);
    masterParams.setTodoNodes(todoNodes);
    masterParams.setSwitchToNextTree(false);
    masterParams.setContinuousRunningStart(false);
    masterParams.setFirstTree(this.trees.size() == 1);
    LOG.info("String_Node_Str",todoNodes.size());
  }
  if (this.isGBDT) {
    if (masterParams.isSwitchToNextTree()) {
      masterParams.setTrees(trees.subList(trees.size() - 2,trees.size()));
    }
 else {
      masterParams.setTrees(trees.subList(trees.size() - 1,trees.size()));
    }
  }
  if (this.isRF) {
    if (masterParams.getTreeDepth().size() == this.trees.size()) {
      List<TreeNode> todoTrees=new ArrayList<TreeNode>();
      for (int i=0; i < trees.size(); i++) {
        if (masterParams.getTreeDepth().get(i) >= 0) {
          todoTrees.add(trees.get(i));
        }
 else {
          todoTrees.add(new TreeNode(i,new Node(Node.INVALID_INDEX),1d));
        }
      }
      masterParams.setTrees(todoTrees);
    }
 else {
      masterParams.setTrees(trees);
    }
  }
  if (this.isGBDT) {
    masterParams.setTmpTrees(this.trees);
  }
  doCheckPoint(context,masterParams);
  LOG.info("String_Node_Str",weightedTrainCount,weightedValidationCount,trainError,validationError);
  return masterParams;
}

Fixed version (ground truth):
/** 
 * If earlyStopEnabled is true, the early stop feature will be enabled
 */
@Override public DTMasterParams doCompute(MasterContext<DTMasterParams,DTWorkerParams> context){
  if (context.isFirstIteration()) {
    return buildInitialMasterParams();
  }
  if (this.cpMasterParams != null) {
    DTMasterParams tmpMasterParams=rebuildRecoverMasterResultDepthList();
    this.cpMasterParams=null;
    if (this.isGBDT) {
      tmpMasterParams.setTrees(trees.subList(trees.size() - 1,trees.size()));
      tmpMasterParams.setTmpTrees(this.trees);
    }
    return tmpMasterParams;
  }
  boolean isFirst=false;
  Map<Integer,NodeStats> nodeStatsMap=null;
  double trainError=0d, validationError=0d;
  double weightedTrainCount=0d, weightedValidationCount=0d;
  for (  DTWorkerParams params : context.getWorkerResults()) {
    if (!isFirst) {
      isFirst=true;
      nodeStatsMap=params.getNodeStatsMap();
    }
 else {
      Map<Integer,NodeStats> currNodeStatsmap=params.getNodeStatsMap();
      for (      Entry<Integer,NodeStats> entry : nodeStatsMap.entrySet()) {
        NodeStats resultNodeStats=entry.getValue();
        mergeNodeStats(resultNodeStats,currNodeStatsmap.get(entry.getKey()));
      }
    }
    trainError+=params.getTrainError();
    validationError+=params.getValidationError();
    weightedTrainCount+=params.getTrainCount();
    weightedValidationCount+=params.getValidationCount();
  }
  for (  Entry<Integer,NodeStats> entry : nodeStatsMap.entrySet()) {
    NodeStats nodeStats=entry.getValue();
    int treeId=nodeStats.getTreeId();
    Node doneNode=Node.getNode(trees.get(treeId).getNode(),nodeStats.getNodeId());
    Map<Integer,double[]> statistics=nodeStats.getFeatureStatistics();
    List<GainInfo> gainList=new ArrayList<GainInfo>();
    for (    Entry<Integer,double[]> gainEntry : statistics.entrySet()) {
      int columnNum=gainEntry.getKey();
      ColumnConfig config=this.columnConfigList.get(columnNum);
      double[] statsArray=gainEntry.getValue();
      GainInfo gainInfo=this.impurity.computeImpurity(statsArray,config);
      if (gainInfo != null) {
        gainList.add(gainInfo);
      }
    }
    GainInfo maxGainInfo=GainInfo.getGainInfoByMaxGain(gainList);
    if (maxGainInfo == null) {
      doneNode.setLeaf(true);
      continue;
    }
    populateGainInfoToNode(treeId,doneNode,maxGainInfo);
    if (this.isLeafWise) {
      boolean isNotSplit=maxGainInfo.getGain() <= 0d;
      if (!isNotSplit) {
        this.toSplitQueue.offer(new TreeNode(treeId,doneNode));
      }
 else {
        LOG.info("String_Node_Str",doneNode.getId(),treeId);
      }
    }
 else {
      boolean isLeaf=maxGainInfo.getGain() <= 0d || Node.indexToLevel(doneNode.getId()) == this.maxDepth;
      doneNode.setLeaf(isLeaf);
      splitNodeForLevelWisedTree(isLeaf,treeId,doneNode);
    }
  }
  if (this.isLeafWise) {
    int currSplitIndex=0;
    while (!toSplitQueue.isEmpty() && currSplitIndex < this.maxBatchSplitSize) {
      TreeNode treeNode=this.toSplitQueue.poll();
      splitNodeForLeafWisedTree(treeNode.getTreeId(),treeNode.getNode());
    }
  }
  Map<Integer,TreeNode> todoNodes=new HashMap<Integer,TreeNode>();
  DTMasterParams masterParams=new DTMasterParams(weightedTrainCount,trainError,weightedValidationCount,validationError);
  if (toDoQueue.isEmpty()) {
    if (this.isGBDT) {
      TreeNode treeNode=this.trees.get(this.trees.size() - 1);
      Node node=treeNode.getNode();
      if (this.trees.size() == this.treeNum + this.existingTreeSize) {
        masterParams.setHalt(true);
        LOG.info("String_Node_Str",context.getCurrentIteration());
      }
 else       if (node.getLeft() == null && node.getRight() == null) {
        masterParams.setHalt(true);
        LOG.warn("String_Node_Str",context.getCurrentIteration());
      }
 else {
        masterParams.setFirstTree(this.trees.size() == 1);
        treeNode.setFeatures(null);
        TreeNode newRootNode=new TreeNode(this.trees.size(),new Node(Node.ROOT_INDEX),this.learningRate);
        LOG.info("String_Node_Str",this.trees.size());
        this.trees.add(newRootNode);
        newRootNode.setFeatures(getSubsamplingFeatures(this.featureSubsetStrategy,this.featureSubsetRate));
        todoNodes.put(0,newRootNode);
        masterParams.setTodoNodes(todoNodes);
        masterParams.setSwitchToNextTree(true);
      }
    }
 else {
      masterParams.setHalt(true);
      LOG.info("String_Node_Str",context.getCurrentIteration());
    }
  }
 else {
    int nodeIndexInGroup=0;
    long currMem=0L;
    List<Integer> depthList=new ArrayList<Integer>();
    if (this.isGBDT) {
      depthList.add(-1);
    }
    if (isRF) {
      for (int i=0; i < this.trees.size(); i++) {
        depthList.add(-1);
      }
    }
    while (!toDoQueue.isEmpty() && currMem <= this.maxStatsMemory) {
      TreeNode node=this.toDoQueue.poll();
      int treeId=node.getTreeId();
      int oldDepth=this.isGBDT ? depthList.get(0) : depthList.get(treeId);
      int currDepth=Node.indexToLevel(node.getNode().getId());
      if (currDepth > oldDepth) {
        if (this.isGBDT) {
          depthList.set(0,currDepth);
        }
 else {
          depthList.set(treeId,currDepth);
        }
      }
      List<Integer> subsetFeatures=getSubsamplingFeatures(this.featureSubsetStrategy,this.featureSubsetRate);
      node.setFeatures(subsetFeatures);
      currMem+=getStatsMem(subsetFeatures);
      todoNodes.put(nodeIndexInGroup,node);
      nodeIndexInGroup+=1;
    }
    masterParams.setTreeDepth(depthList);
    masterParams.setTodoNodes(todoNodes);
    masterParams.setSwitchToNextTree(false);
    masterParams.setContinuousRunningStart(false);
    masterParams.setFirstTree(this.trees.size() == 1);
    LOG.info("String_Node_Str",todoNodes.size());
  }
  if (this.isGBDT) {
    if (masterParams.isSwitchToNextTree()) {
      masterParams.setTrees(trees.subList(trees.size() - 2,trees.size()));
    }
 else {
      masterParams.setTrees(trees.subList(trees.size() - 1,trees.size()));
    }
  }
  if (this.isRF) {
    if (masterParams.getTreeDepth().size() == this.trees.size()) {
      List<TreeNode> todoTrees=new ArrayList<TreeNode>();
      for (int i=0; i < trees.size(); i++) {
        if (masterParams.getTreeDepth().get(i) >= 0) {
          todoTrees.add(trees.get(i));
        }
 else {
          todoTrees.add(new TreeNode(i,new Node(Node.INVALID_INDEX),1d));
        }
      }
      masterParams.setTrees(todoTrees);
    }
 else {
      masterParams.setTrees(trees);
    }
  }
  if (this.isGBDT) {
    masterParams.setTmpTrees(this.trees);
  }
  doCheckPoint(context,masterParams);
  LOG.info("String_Node_Str",weightedTrainCount,weightedValidationCount,trainError,validationError);
  return masterParams;
}