Program: 32011
Project: 32011
Buggy source:
@Override public DTMasterParams doCompute(MasterContext<DTMasterParams,DTWorkerParams> context){
  if (context.isFirstIteration()) {
    return buildInitialMasterParams();
  }
  boolean isFirst=false;
  Map<Integer,NodeStats> nodeStatsMap=null;
  double trainError=0d, validationError=0d;
  long trainCount=0L, validationCount=0L;
  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();
    if (this.isRF) {
      trainCount+=params.getTrainCount() * this.treeNum;
      validationCount+=params.getValidationCount() * this.treeNum;
    }
    if (this.isGBDT) {
      trainCount+=params.getTrainCount();
      validationCount+=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(doneNode,maxGainInfo);
    boolean isLeaf=maxGainInfo.getGain() <= 0d || Node.indexToLevel(doneNode.getId()) == this.maxDepth;
    doneNode.setLeaf(isLeaf);
    if (!doneNode.isLeaf()) {
      boolean leftChildIsLeaf=Node.indexToLevel(doneNode.getId()) + 1 == this.maxDepth || Double.compare(maxGainInfo.getLeftImpurity(),0d) == 0;
      int leftIndex=Node.leftIndex(doneNode.getId());
      Node left=new Node(leftIndex,maxGainInfo.getLeftPredict(),maxGainInfo.getLeftImpurity(),true);
      doneNode.setLeft(left);
      if (!leftChildIsLeaf) {
        this.queue.offer(new TreeNode(treeId,left));
      }
 else {
        LOG.info("String_Node_Str",leftIndex,treeId);
      }
      boolean rightChildIsLeaf=Node.indexToLevel(doneNode.getId()) + 1 == this.maxDepth || Double.compare(maxGainInfo.getRightImpurity(),0d) == 0;
      int rightIndex=Node.rightIndex(doneNode.getId());
      Node right=new Node(rightIndex,maxGainInfo.getRightPredict(),maxGainInfo.getRightImpurity(),true);
      doneNode.setRight(right);
      if (!rightChildIsLeaf) {
        this.queue.offer(new TreeNode(treeId,right));
      }
 else {
        LOG.info("String_Node_Str",rightIndex,treeId);
      }
    }
 else {
      LOG.info("String_Node_Str",doneNode.getId(),treeId);
    }
  }
  Map<Integer,TreeNode> todoNodes=new HashMap<Integer,TreeNode>();
  DTMasterParams masterParams=new DTMasterParams(trainCount,trainError,validationCount,validationError);
  if (queue.isEmpty()) {
    if (this.isGBDT) {
      Node treeNode=this.trees.get(this.trees.size() - 1).getNode();
      if (this.trees.size() == this.treeNum + this.existingTreeSize) {
        masterParams.setHalt(true);
        LOG.info("String_Node_Str",context.getCurrentIteration());
      }
 else       if (treeNode.getLeft() == null && treeNode.getRight() == null) {
        masterParams.setHalt(true);
        LOG.warn("String_Node_Str",context.getCurrentIteration());
      }
 else {
        TreeNode newRootNode=new TreeNode(this.trees.size(),new Node(Node.ROOT_INDEX));
        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>();
    for (int i=0; i < this.trees.size(); i++) {
      depthList.add(-1);
    }
    while (!queue.isEmpty() && currMem <= this.maxStatsMemory) {
      TreeNode node=this.queue.poll();
      int treeId=node.getTreeId();
      int oldDepth=depthList.get(treeId);
      int currDepth=Node.indexToLevel(node.getNode().getId());
      if (currDepth > oldDepth) {
        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);
    LOG.info("String_Node_Str",todoNodes.size());
  }
  masterParams.setTrees(trees);
  return masterParams;
}

Fixed version (ground truth):
@Override public DTMasterParams doCompute(MasterContext<DTMasterParams,DTWorkerParams> context){
  if (context.isFirstIteration()) {
    return buildInitialMasterParams();
  }
  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(doneNode,maxGainInfo);
    boolean isLeaf=maxGainInfo.getGain() <= 0d || Node.indexToLevel(doneNode.getId()) == this.maxDepth;
    doneNode.setLeaf(isLeaf);
    if (!doneNode.isLeaf()) {
      boolean leftChildIsLeaf=Node.indexToLevel(doneNode.getId()) + 1 == this.maxDepth || Double.compare(maxGainInfo.getLeftImpurity(),0d) == 0;
      int leftIndex=Node.leftIndex(doneNode.getId());
      Node left=new Node(leftIndex,maxGainInfo.getLeftPredict(),maxGainInfo.getLeftImpurity(),true);
      doneNode.setLeft(left);
      if (!leftChildIsLeaf) {
        this.queue.offer(new TreeNode(treeId,left));
      }
 else {
        LOG.info("String_Node_Str",leftIndex,treeId);
      }
      boolean rightChildIsLeaf=Node.indexToLevel(doneNode.getId()) + 1 == this.maxDepth || Double.compare(maxGainInfo.getRightImpurity(),0d) == 0;
      int rightIndex=Node.rightIndex(doneNode.getId());
      Node right=new Node(rightIndex,maxGainInfo.getRightPredict(),maxGainInfo.getRightImpurity(),true);
      doneNode.setRight(right);
      if (!rightChildIsLeaf) {
        this.queue.offer(new TreeNode(treeId,right));
      }
 else {
        LOG.info("String_Node_Str",rightIndex,treeId);
      }
    }
 else {
      LOG.info("String_Node_Str",doneNode.getId(),treeId);
    }
  }
  Map<Integer,TreeNode> todoNodes=new HashMap<Integer,TreeNode>();
  DTMasterParams masterParams=new DTMasterParams(weightedTrainCount,trainError,weightedValidationCount,validationError);
  if (queue.isEmpty()) {
    if (this.isGBDT) {
      Node treeNode=this.trees.get(this.trees.size() - 1).getNode();
      if (this.trees.size() == this.treeNum + this.existingTreeSize) {
        masterParams.setHalt(true);
        LOG.info("String_Node_Str",context.getCurrentIteration());
      }
 else       if (treeNode.getLeft() == null && treeNode.getRight() == null) {
        masterParams.setHalt(true);
        LOG.warn("String_Node_Str",context.getCurrentIteration());
      }
 else {
        TreeNode newRootNode=new TreeNode(this.trees.size(),new Node(Node.ROOT_INDEX));
        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>();
    for (int i=0; i < this.trees.size(); i++) {
      depthList.add(-1);
    }
    while (!queue.isEmpty() && currMem <= this.maxStatsMemory) {
      TreeNode node=this.queue.poll();
      int treeId=node.getTreeId();
      int oldDepth=depthList.get(treeId);
      int currDepth=Node.indexToLevel(node.getNode().getId());
      if (currDepth > oldDepth) {
        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);
    LOG.info("String_Node_Str",todoNodes.size());
  }
  masterParams.setTrees(trees);
  return masterParams;
}