Program: 117227
Project: 117227
Buggy source:
public Function2D build(Instances instances){
  List<Attribute> attributes=instances.getAttributes();
  int size1=0;
  Attribute f1=attributes.get(attIndex1);
  if (f1.getType() == Attribute.Type.BINNED) {
    size1=((BinnedAttribute)f1).getNumBins();
  }
 else   if (f1.getType() == Attribute.Type.NOMINAL) {
    size1=((NominalAttribute)f1).getCardinality();
  }
  int size2=0;
  Attribute f2=attributes.get(attIndex2);
  if (f1.getType() == Attribute.Type.BINNED) {
    size2=((BinnedAttribute)f2).getNumBins();
  }
 else   if (f1.getType() == Attribute.Type.NOMINAL) {
    size2=((NominalAttribute)f2).getCardinality();
  }
  if (size1 == 1 || size2 == 1) {
    return new Function2D(f1.getIndex(),f2.getIndex(),new double[]{Double.POSITIVE_INFINITY},new double[]{Double.POSITIVE_INFINITY},new double[1][1]);
  }
  Histogram2D hist2d=new Histogram2D(size1,size2);
  for (  Instance instance : instances) {
    int idx1=(int)instance.getValue(f1);
    int idx2=(int)instance.getValue(f2);
    hist2d.resp[idx1][idx2]+=instance.getTarget() * instance.getWeight();
    hist2d.count[idx1][idx2]+=instance.getWeight();
  }
  Pair<CHistogram,CHistogram> cHist=hist2d.computeCHistogram();
  Table table=new Table(size1,size2);
  computeTable(hist2d,cHist.v1,cHist.v2,table);
  double bestRSS=Double.POSITIVE_INFINITY;
  double[] predInt1=new double[4];
  int bestV1=-1;
  int[] bestV2s=new int[2];
  int[] v2s=new int[2];
  for (int v1=0; v1 < size1 - 1; v1++) {
    findCuts(table,v1,v2s);
    getPredictor(table,v1,v2s,predInt1);
    double rss=getRSS(table,v1,v2s,predInt1);
    if (rss < bestRSS) {
      bestRSS=rss;
      bestV1=v1;
      bestV2s[0]=v2s[0];
      bestV2s[1]=v2s[1];
    }
  }
  boolean cutOnAttr2=false;
  double[] predInt2=new double[4];
  int[] bestV1s=new int[2];
  int bestV2=-1;
  int[] v1s=new int[2];
  for (int v2=0; v2 < size2 - 1; v2++) {
    findCuts(table,v1s,v2);
    getPredictor(table,v1s,v2,predInt2);
    double rss=getRSS(table,v1s,v2,predInt2);
    if (rss < bestRSS) {
      bestRSS=rss;
      bestV2=v2;
      bestV1s[0]=v1s[0];
      bestV1s[1]=v1s[1];
      cutOnAttr2=true;
    }
  }
  if (cutOnAttr2) {
    getPredictor(table,bestV1s,bestV2,predInt2);
    if (lineSearch) {
      lineSearch(instances,f2.getIndex(),f1.getIndex(),bestV2,bestV1s[0],bestV1s[1],predInt2);
    }
    return getFunction2D(f1.getIndex(),f2.getIndex(),bestV1s,bestV2,predInt2);
  }
 else {
    getPredictor(table,bestV1,bestV2s,predInt1);
    if (lineSearch) {
      lineSearch(instances,f1.getIndex(),f2.getIndex(),bestV1,bestV2s[0],bestV2s[1],predInt1);
    }
    return getFunction2D(f1.getIndex(),f2.getIndex(),bestV1,bestV2s,predInt1);
  }
}

Fixed version (ground truth):
public Function2D build(Instances instances){
  List<Attribute> attributes=instances.getAttributes();
  int size1=0;
  Attribute f1=attributes.get(attIndex1);
  if (f1.getType() == Attribute.Type.BINNED) {
    size1=((BinnedAttribute)f1).getNumBins();
  }
 else   if (f1.getType() == Attribute.Type.NOMINAL) {
    size1=((NominalAttribute)f1).getCardinality();
  }
  int size2=0;
  Attribute f2=attributes.get(attIndex2);
  if (f2.getType() == Attribute.Type.BINNED) {
    size2=((BinnedAttribute)f2).getNumBins();
  }
 else   if (f2.getType() == Attribute.Type.NOMINAL) {
    size2=((NominalAttribute)f2).getCardinality();
  }
  if (size1 == 1 || size2 == 1) {
    return new Function2D(f1.getIndex(),f2.getIndex(),new double[]{Double.POSITIVE_INFINITY},new double[]{Double.POSITIVE_INFINITY},new double[1][1]);
  }
  Histogram2D hist2d=new Histogram2D(size1,size2);
  for (  Instance instance : instances) {
    int idx1=(int)instance.getValue(f1);
    int idx2=(int)instance.getValue(f2);
    hist2d.resp[idx1][idx2]+=instance.getTarget() * instance.getWeight();
    hist2d.count[idx1][idx2]+=instance.getWeight();
  }
  Pair<CHistogram,CHistogram> cHist=hist2d.computeCHistogram();
  Table table=new Table(size1,size2);
  computeTable(hist2d,cHist.v1,cHist.v2,table);
  double bestRSS=Double.POSITIVE_INFINITY;
  double[] predInt1=new double[4];
  int bestV1=-1;
  int[] bestV2s=new int[2];
  int[] v2s=new int[2];
  for (int v1=0; v1 < size1 - 1; v1++) {
    findCuts(table,v1,v2s);
    getPredictor(table,v1,v2s,predInt1);
    double rss=getRSS(table,v1,v2s,predInt1);
    if (rss < bestRSS) {
      bestRSS=rss;
      bestV1=v1;
      bestV2s[0]=v2s[0];
      bestV2s[1]=v2s[1];
    }
  }
  boolean cutOnAttr2=false;
  double[] predInt2=new double[4];
  int[] bestV1s=new int[2];
  int bestV2=-1;
  int[] v1s=new int[2];
  for (int v2=0; v2 < size2 - 1; v2++) {
    findCuts(table,v1s,v2);
    getPredictor(table,v1s,v2,predInt2);
    double rss=getRSS(table,v1s,v2,predInt2);
    if (rss < bestRSS) {
      bestRSS=rss;
      bestV2=v2;
      bestV1s[0]=v1s[0];
      bestV1s[1]=v1s[1];
      cutOnAttr2=true;
    }
  }
  if (cutOnAttr2) {
    getPredictor(table,bestV1s,bestV2,predInt2);
    if (lineSearch) {
      lineSearch(instances,f2.getIndex(),f1.getIndex(),bestV2,bestV1s[0],bestV1s[1],predInt2);
    }
    return getFunction2D(f1.getIndex(),f2.getIndex(),bestV1s,bestV2,predInt2);
  }
 else {
    getPredictor(table,bestV1,bestV2s,predInt1);
    if (lineSearch) {
      lineSearch(instances,f1.getIndex(),f2.getIndex(),bestV1,bestV2s[0],bestV2s[1],predInt1);
    }
    return getFunction2D(f1.getIndex(),f2.getIndex(),bestV1,bestV2s,predInt1);
  }
}