Program: 149554
Project: 149554
Buggy source:
/** 
 * @param results The results generated from running the filter (or null)
 * @param filter
 */
private MemoryPeakResults depthAnalysis(MemoryPeakResults results,Filter filter){
  if (!depthRecallAnalysis || simulationParameters.fixedDepth)   return results;
  final double[] depths=depthStats.getValues();
  final double range=simulationParameters.depth / simulationParameters.a / 2;
  double[] limits={-range,range};
  final int bins=Math.max(10,simulationParameters.molecules / 100);
  double[][] h1=Utils.calcHistogram(depths,limits[0],limits[1],bins);
  double[][] h2=Utils.calcHistogram(depthFitStats.getValues(),limits[0],limits[1],bins);
  results=filter(filter,resultsList.get(0),failCount);
  double[] depths2=new double[results.size()];
  int count=0;
  for (  PeakResult r : results.getResults()) {
    if (r.origValue != 0) {
      depths2[count]=((DepthPeakResult)r).depth;
      count++;
    }
  }
  depths2=Arrays.copyOf(depths2,count);
  double[][] h3=Utils.calcHistogram(depths2,limits[0],limits[1],bins);
  for (int i=0; i < h1[0].length; i++)   h1[0][i]*=simulationParameters.a;
  limits[0]*=simulationParameters.a;
  limits[1]*=simulationParameters.a;
  String title1=TITLE + "String_Node_Str";
  Plot2 plot1=new Plot2(title1,"String_Node_Str","String_Node_Str");
  plot1.setLimits(limits[0],limits[1],0,Maths.max(h1[1]));
  plot1.setColor(Color.black);
  plot1.addPoints(h1[0],h1[1],Plot2.BAR);
  plot1.addLabel(0,0,"String_Node_Str");
  plot1.setColor(Color.blue);
  plot1.addPoints(h1[0],h2[1],Plot2.BAR);
  plot1.setColor(Color.red);
  plot1.addPoints(h1[0],h3[1],Plot2.BAR);
  plot1.setColor(Color.magenta);
  PlotWindow pw1=Utils.display(title1,plot1);
  if (Utils.isNewWindow())   idList[idCount++]=pw1.getImagePlus().getID();
  final double halfBinWidth=(h1[0][1] - h1[0][0]) * 0.5;
  h1[0]=Arrays.copyOf(h1[0],h1[0].length - 1);
  h1[1]=Arrays.copyOf(h1[1],h1[0].length);
  h2[1]=Arrays.copyOf(h2[1],h1[0].length);
  h3[1]=Arrays.copyOf(h3[1],h1[0].length);
  double bandwidth=Math.max(3.0 / h1[0].length,0.15);
  LoessInterpolator loess=new LoessInterpolator(bandwidth,1);
  PolynomialSplineFunction spline1=loess.interpolate(h1[0],h1[1]);
  PolynomialSplineFunction spline2=loess.interpolate(h1[0],h2[1]);
  PolynomialSplineFunction spline3=loess.interpolate(h1[0],h3[1]);
  LinearInterpolator lin=new LinearInterpolator();
  PolynomialSplineFunction spline1b=lin.interpolate(h1[0],h1[1]);
  PolynomialSplineFunction spline2b=lin.interpolate(h1[0],h2[1]);
  PolynomialSplineFunction spline3b=lin.interpolate(h1[0],h3[1]);
  double[] points=new double[bins * 5];
  limits=Maths.limits(h1[0]);
  final double interval=(limits[1] - limits[0]) / (points.length - 1);
  double[] v=new double[points.length];
  double[] v2=new double[points.length];
  double[] v3=new double[points.length];
  for (int i=0; i < points.length - 1; i++) {
    points[i]=limits[0] + i * interval;
    v[i]=getSplineValue(spline1,spline1b,points[i]);
    v2[i]=getSplineValue(spline2,spline2b,points[i]);
    v3[i]=getSplineValue(spline3,spline3b,points[i]);
    points[i]+=halfBinWidth;
  }
  int ii=points.length - 1;
  v[ii]=getSplineValue(spline1,spline1b,limits[1]);
  v2[ii]=getSplineValue(spline2,spline2b,limits[1]);
  v3[ii]=getSplineValue(spline3,spline3b,limits[1]);
  points[ii]=limits[1] + halfBinWidth;
  for (int i=0; i < v.length; i++) {
    v2[i]=v2[i] / v[i];
    v3[i]=v3[i] / v[i];
  }
  final double halfSummaryDepth=summaryDepth * 0.5;
  String title2=TITLE + "String_Node_Str";
  Plot2 plot2=new Plot2(title2,"String_Node_Str","String_Node_Str");
  plot2.setLimits(limits[0] + halfBinWidth,limits[1] + halfBinWidth,0,Maths.min(1,Maths.max(v2)));
  plot2.setColor(Color.black);
  plot2.addLabel(0,0,"String_Node_Str");
  plot2.setColor(Color.blue);
  plot2.addPoints(points,v2,Plot2.LINE);
  plot2.setColor(Color.red);
  plot2.addPoints(points,v3,Plot2.LINE);
  plot2.setColor(Color.magenta);
  plot2.drawLine(-halfSummaryDepth,0,-halfSummaryDepth,getSplineValue(spline3,spline3b,-halfSummaryDepth - halfBinWidth) / getSplineValue(spline1,spline1b,-halfSummaryDepth - halfBinWidth));
  plot2.drawLine(halfSummaryDepth,0,halfSummaryDepth,getSplineValue(spline3,spline3b,halfSummaryDepth - halfBinWidth) / getSplineValue(spline1,spline1b,halfSummaryDepth - halfBinWidth));
  PlotWindow pw2=Utils.display(title2,plot2);
  if (Utils.isNewWindow())   idList[idCount++]=pw2.getImagePlus().getID();
  return results;
}

Fixed version (ground truth):
/** 
 * @param results The results generated from running the filter (or null)
 * @param filter
 */
private MemoryPeakResults depthAnalysis(MemoryPeakResults results,Filter filter){
  if (!depthRecallAnalysis || simulationParameters.fixedDepth)   return results;
  final double[] depths=depthStats.getValues();
  final double range=simulationParameters.depth / simulationParameters.a / 2;
  double[] limits={-range,range};
  final int bins=Math.max(10,simulationParameters.molecules / 100);
  double[][] h1=Utils.calcHistogram(depths,limits[0],limits[1],bins);
  double[][] h2=Utils.calcHistogram(depthFitStats.getValues(),limits[0],limits[1],bins);
  results=filter(filter,resultsList.get(0),failCount);
  double[] depths2=new double[results.size()];
  int count=0;
  for (  PeakResult r : results.getResults()) {
    if (r.origValue != 0) {
      depths2[count]=((DepthPeakResult)r).depth;
      count++;
    }
  }
  depths2=Arrays.copyOf(depths2,count);
  double[][] h3=Utils.calcHistogram(depths2,limits[0],limits[1],bins);
  for (int i=0; i < h1[0].length; i++)   h1[0][i]*=simulationParameters.a;
  limits[0]*=simulationParameters.a;
  limits[1]*=simulationParameters.a;
  String title1=TITLE + "String_Node_Str";
  Plot2 plot1=new Plot2(title1,"String_Node_Str","String_Node_Str");
  plot1.setLimits(limits[0],limits[1],0,Maths.max(h1[1]));
  plot1.setColor(Color.black);
  plot1.addPoints(h1[0],h1[1],Plot2.BAR);
  plot1.addLabel(0,0,"String_Node_Str");
  plot1.setColor(Color.blue);
  plot1.addPoints(h1[0],h2[1],Plot2.BAR);
  plot1.setColor(Color.red);
  plot1.addPoints(h1[0],h3[1],Plot2.BAR);
  plot1.setColor(Color.magenta);
  PlotWindow pw1=Utils.display(title1,plot1);
  if (Utils.isNewWindow())   idList[idCount++]=pw1.getImagePlus().getID();
  final double halfBinWidth=(h1[0][1] - h1[0][0]) * 0.5;
  h1[0]=Arrays.copyOf(h1[0],h1[0].length - 1);
  h1[1]=Arrays.copyOf(h1[1],h1[0].length);
  h2[1]=Arrays.copyOf(h2[1],h1[0].length);
  h3[1]=Arrays.copyOf(h3[1],h1[0].length);
  double bandwidth=Math.max(3.0 / h1[0].length,0.15);
  LoessInterpolator loess=new LoessInterpolator(bandwidth,1);
  PolynomialSplineFunction spline1=loess.interpolate(h1[0],h1[1]);
  PolynomialSplineFunction spline2=loess.interpolate(h1[0],h2[1]);
  PolynomialSplineFunction spline3=loess.interpolate(h1[0],h3[1]);
  LinearInterpolator lin=new LinearInterpolator();
  PolynomialSplineFunction spline1b=lin.interpolate(h1[0],h1[1]);
  PolynomialSplineFunction spline2b=lin.interpolate(h1[0],h2[1]);
  PolynomialSplineFunction spline3b=lin.interpolate(h1[0],h3[1]);
  double[] points=new double[bins * 5];
  limits=Maths.limits(h1[0]);
  final double interval=(limits[1] - limits[0]) / (points.length - 1);
  double[] v=new double[points.length];
  double[] v2=new double[points.length];
  double[] v3=new double[points.length];
  for (int i=0; i < points.length - 1; i++) {
    points[i]=limits[0] + i * interval;
    v[i]=getSplineValue(spline1,spline1b,points[i]);
    v2[i]=getSplineValue(spline2,spline2b,points[i]);
    v3[i]=getSplineValue(spline3,spline3b,points[i]);
    points[i]+=halfBinWidth;
  }
  int ii=points.length - 1;
  v[ii]=getSplineValue(spline1,spline1b,limits[1]);
  v2[ii]=getSplineValue(spline2,spline2b,limits[1]);
  v3[ii]=getSplineValue(spline3,spline3b,limits[1]);
  points[ii]=limits[1] + halfBinWidth;
  for (int i=0; i < v.length; i++) {
    v2[i]=v2[i] / v[i];
    v3[i]=v3[i] / v[i];
  }
  final double halfSummaryDepth=summaryDepth * 0.5;
  String title2=TITLE + "String_Node_Str";
  Plot2 plot2=new Plot2(title2,"String_Node_Str","String_Node_Str");
  plot2.setLimits(limits[0] + halfBinWidth,limits[1] + halfBinWidth,0,Maths.min(1,Maths.max(v2)));
  plot2.setColor(Color.black);
  plot2.addLabel(0,0,"String_Node_Str");
  plot2.setColor(Color.blue);
  plot2.addPoints(points,v2,Plot2.LINE);
  plot2.setColor(Color.red);
  plot2.addPoints(points,v3,Plot2.LINE);
  plot2.setColor(Color.magenta);
  if (-halfSummaryDepth - halfBinWidth >= limits[0]) {
    plot2.drawLine(-halfSummaryDepth,0,-halfSummaryDepth,getSplineValue(spline3,spline3b,-halfSummaryDepth - halfBinWidth) / getSplineValue(spline1,spline1b,-halfSummaryDepth - halfBinWidth));
  }
  if (halfSummaryDepth - halfBinWidth <= limits[1]) {
    plot2.drawLine(halfSummaryDepth,0,halfSummaryDepth,getSplineValue(spline3,spline3b,halfSummaryDepth - halfBinWidth) / getSplineValue(spline1,spline1b,halfSummaryDepth - halfBinWidth));
  }
  PlotWindow pw2=Utils.display(title2,plot2);
  if (Utils.isNewWindow())   idList[idCount++]=pw2.getImagePlus().getID();
  return results;
}