Program: 125186
Project: 125186
Buggy source:
double computeTreeSTBipartitions(MGDInference_DP inference){
  double unweigthedConstant=0;
  double weightedConstant=0;
  int k=inference.trees.size();
  String[] leaves=stTaxa;
  int n=leaves.length;
  boolean duploss=(inference.optimizeDuploss == 3);
  geneTreeSTBCount=new HashMap<STBipartition,Integer>(k * n);
  geneTreeInvalidSTBCont=new HashMap<AbstractMap.SimpleEntry<STITreeCluster,STITreeCluster>,Integer>();
  STITreeCluster all=new STITreeCluster();
  for (int i=0; i < stTaxa.length; i++) {
    all.addLeaf(i);
  }
  addToClusters(all,leaves.length,false);
  for (int t=0; t < inference.trees.size(); t++) {
    Tree tr=inference.trees.get(t);
    STITreeCluster allInducedByGT=new STITreeCluster();
    String[] gtLeaves=tr.getLeaves();
    for (int i=0; i < gtLeaves.length; i++) {
      String l=gtLeaves[i];
      allInducedByGT.addLeaf(getSpeciesName(l));
    }
    treeAlls.add(allInducedByGT);
    int allInducedByGTSize=allInducedByGT.getClusterSize();
    weightedConstant+=duploss ? 2 * (allInducedByGTSize - 1) : 0;
    unweigthedConstant+=(tr.getLeafCount() - 1);
    Map<TNode,STITreeCluster> nodeToSTCluster=new HashMap<TNode,STITreeCluster>(n);
    for (    TNode node : tr.postTraverse()) {
      if (node.isLeaf()) {
        String nodeName=getSpeciesName(node.getName());
        STITreeCluster cluster=new STITreeCluster();
        cluster.addLeaf(nodeName);
        addToClusters(cluster,1,true);
        nodeToSTCluster.put(node,cluster);
        if (!rooted) {
          throw new RuntimeException("String_Node_Str");
        }
      }
 else {
        int childCount=node.getChildCount();
        STITreeCluster childbslist[]=new STITreeCluster[childCount];
        BitSet bs=new BitSet(leaves.length);
        int index=0;
        for (        TNode child : node.getChildren()) {
          childbslist[index++]=nodeToSTCluster.get(child);
          bs.or(nodeToSTCluster.get(child).getBitSet());
        }
        STITreeCluster cluster=new STITreeCluster();
        cluster.setCluster((BitSet)bs.clone());
        int size=cluster.getClusterSize();
        addToClusters(cluster,size,true);
        nodeToSTCluster.put(node,cluster);
        if (rooted) {
          if (index > 2) {
            throw new RuntimeException("String_Node_Str" + tr + "String_Node_Str"+ node);
          }
          STITreeCluster l_cluster=childbslist[0];
          STITreeCluster r_cluster=childbslist[1];
          tryAddingSTB(l_cluster,r_cluster,cluster,node,true);
        }
 else {
          throw new RuntimeException("String_Node_Str");
        }
      }
    }
  }
  int s=0;
  for (  Integer c : geneTreeSTBCount.values()) {
    s+=c;
  }
  System.err.println("String_Node_Str" + geneTreeSTBCount.size());
  System.err.println("String_Node_Str" + s);
  s=clusters.getClusterCount();
  System.err.println("String_Node_Str" + s);
  weights=new HashMap<STBipartition,Integer>(geneTreeSTBCount.size() * 2);
  if (inference.DLbdWeigth == -1) {
    inference.DLbdWeigth=(weightedConstant + 2 * k + 0.0D) / 2 * (k * n);
    System.out.println("String_Node_Str" + inference.DLbdWeigth);
  }
  return (unweigthedConstant + (1 - inference.DLbdWeigth) * weightedConstant);
}

Fixed version (ground truth):
double computeTreeSTBipartitions(MGDInference_DP inference){
  double unweigthedConstant=0;
  double weightedConstant=0;
  int k=inference.trees.size();
  String[] leaves=stTaxa;
  int n=leaves.length;
  boolean duploss=(inference.optimizeDuploss == 3);
  geneTreeSTBCount=new HashMap<STBipartition,Integer>(k * n);
  geneTreeInvalidSTBCont=new HashMap<AbstractMap.SimpleEntry<STITreeCluster,STITreeCluster>,Integer>();
  STITreeCluster all=new STITreeCluster();
  for (int i=0; i < stTaxa.length; i++) {
    all.addLeaf(i);
  }
  addToClusters(all,leaves.length,false);
  for (int t=0; t < inference.trees.size(); t++) {
    Tree tr=inference.trees.get(t);
    STITreeCluster allInducedByGT=new STITreeCluster();
    String[] gtLeaves=tr.getLeaves();
    for (int i=0; i < gtLeaves.length; i++) {
      String l=gtLeaves[i];
      allInducedByGT.addLeaf(GlobalMaps.taxonIdentifier.taxonId(getSpeciesName(l)));
    }
    treeAlls.add(allInducedByGT);
    int allInducedByGTSize=allInducedByGT.getClusterSize();
    weightedConstant+=duploss ? 2 * (allInducedByGTSize - 1) : 0;
    unweigthedConstant+=(tr.getLeafCount() - 1);
    Map<TNode,STITreeCluster> nodeToSTCluster=new HashMap<TNode,STITreeCluster>(n);
    for (    TNode node : tr.postTraverse()) {
      if (node.isLeaf()) {
        String nodeName=getSpeciesName(node.getName());
        STITreeCluster cluster=new STITreeCluster();
        cluster.addLeaf(GlobalMaps.taxonIdentifier.taxonId(nodeName));
        addToClusters(cluster,1,true);
        nodeToSTCluster.put(node,cluster);
        if (!rooted) {
          throw new RuntimeException("String_Node_Str");
        }
      }
 else {
        int childCount=node.getChildCount();
        STITreeCluster childbslist[]=new STITreeCluster[childCount];
        BitSet bs=new BitSet(leaves.length);
        int index=0;
        for (        TNode child : node.getChildren()) {
          childbslist[index++]=nodeToSTCluster.get(child);
          bs.or(nodeToSTCluster.get(child).getBitSet());
        }
        STITreeCluster cluster=new STITreeCluster();
        cluster.setCluster((BitSet)bs.clone());
        int size=cluster.getClusterSize();
        addToClusters(cluster,size,true);
        nodeToSTCluster.put(node,cluster);
        if (rooted) {
          if (index > 2) {
            throw new RuntimeException("String_Node_Str" + tr + "String_Node_Str"+ node);
          }
          STITreeCluster l_cluster=childbslist[0];
          STITreeCluster r_cluster=childbslist[1];
          tryAddingSTB(l_cluster,r_cluster,cluster,node,true);
        }
 else {
          throw new RuntimeException("String_Node_Str");
        }
      }
    }
  }
  int s=0;
  for (  Integer c : geneTreeSTBCount.values()) {
    s+=c;
  }
  System.err.println("String_Node_Str" + geneTreeSTBCount.size());
  System.err.println("String_Node_Str" + s);
  s=clusters.getClusterCount();
  System.err.println("String_Node_Str" + s);
  weights=new HashMap<STBipartition,Integer>(geneTreeSTBCount.size() * 2);
  if (inference.DLbdWeigth == -1) {
    inference.DLbdWeigth=(weightedConstant + 2 * k + 0.0D) / 2 * (k * n);
    System.out.println("String_Node_Str" + inference.DLbdWeigth);
  }
  return (unweigthedConstant + (1 - inference.DLbdWeigth) * weightedConstant);
}