Program: 20183
Project: 20183
Buggy source:
public boolean optimize(int numIterations){
  if (converged)   return true;
  int n=optimizable.getNumParameters();
  double prevStepSize=initialStepSize;
  boolean searchingGradient=true;
  if (xi == null) {
    fp=optimizable.getValue();
    xi=new double[n];
    g=new double[n];
    h=new double[n];
    optimizable.getValueGradient(xi);
    System.arraycopy(xi,0,g,0,n);
    System.arraycopy(xi,0,h,0,n);
    step=initialStepSize;
    iterations=0;
  }
  for (int iterationCount=0; iterationCount < numIterations; iterationCount++) {
    logger.info("String_Node_Str" + iterations + "String_Node_Str"+ fp);
    try {
      prevStepSize=step;
      step=lineMaximizer.optimize(xi,step);
    }
 catch (    IllegalArgumentException e) {
      System.out.println("String_Node_Str" + e.toString());
      TestOptimizable.testValueAndGradientCurrentParameters(optimizable);
      TestOptimizable.testValueAndGradientInDirection(optimizable,xi);
    }
    if (step == 0) {
      if (searchingGradient) {
        System.err.println("String_Node_Str" + "String_Node_Str" + MatrixOps.absNorm(xi));
        converged=true;
        return true;
      }
 else       System.err.println("String_Node_Str" + "String_Node_Str" + MatrixOps.absNorm(xi));
      fp=optimizable.getValue();
      optimizable.getValueGradient(xi);
      searchingGradient=true;
      System.arraycopy(xi,0,g,0,n);
      System.arraycopy(xi,0,h,0,n);
      step=prevStepSize;
      continue;
    }
    fret=optimizable.getValue();
    if (2.0 * Math.abs(fret - fp) <= tolerance * (Math.abs(fret) + Math.abs(fp) + eps)) {
      System.out.println("String_Node_Str" + fp + "String_Node_Str"+ fret+ "String_Node_Str"+ tolerance);
      converged=true;
      return true;
    }
    fp=fret;
    optimizable.getValueGradient(xi);
    logger.info("String_Node_Str" + MatrixOps.infinityNorm(xi));
    if (MatrixOps.infinityNorm(xi) < tolerance) {
      System.err.println("String_Node_Str" + MatrixOps.infinityNorm(xi) + "String_Node_Str"+ tolerance);
      converged=true;
      return true;
    }
    dgg=gg=0.0;
    double gj, xj;
    for (j=0; j < xi.length; j++) {
      gj=g[j];
      gg+=gj * gj;
      xj=-xi[j];
      dgg=(xj + gj) * xj;
    }
    if (gg == 0.0) {
      System.err.println("String_Node_Str");
      converged=true;
      return true;
    }
    gam=dgg / gg;
    double hj;
    for (j=0; j < xi.length; j++) {
      xj=xi[j];
      g[j]=xj;
      hj=h[j];
      hj=xj + gam * hj;
      h[j]=hj;
    }
    assert(!MatrixOps.isNaN(h));
    MatrixOps.set(xi,h);
    searchingGradient=false;
    iterations++;
    if (iterations > maxIterations) {
      System.err.println("String_Node_Str");
      converged=true;
      return true;
    }
    if (eval != null)     eval.evaluate(optimizable,iterations);
  }
  return false;
}

Fixed version (ground truth):
public boolean optimize(int numIterations){
  if (converged)   return true;
  int n=optimizable.getNumParameters();
  if (xi == null) {
    fp=optimizable.getValue();
    xi=new double[n];
    g=new double[n];
    h=new double[n];
    optimizable.getValueGradient(xi);
    System.arraycopy(xi,0,g,0,n);
    System.arraycopy(xi,0,h,0,n);
    step=initialStepSize;
    iterations=0;
  }
  for (int iterationCount=0; iterationCount < numIterations; iterationCount++) {
    logger.info("String_Node_Str" + iterations + "String_Node_Str"+ fp);
    step=lineMaximizer.optimize(xi,step);
    fret=optimizable.getValue();
    optimizable.getValueGradient(xi);
    if (2.0 * Math.abs(fret - fp) <= tolerance * (Math.abs(fret) + Math.abs(fp) + eps)) {
      logger.info("String_Node_Str" + fp + "String_Node_Str"+ fret+ "String_Node_Str"+ tolerance);
      converged=true;
      return true;
    }
    fp=fret;
    double twoNorm=MatrixOps.twoNorm(xi);
    if (twoNorm < gradientTolerance) {
      logger.info("String_Node_Str" + twoNorm + "String_Node_Str"+ gradientTolerance);
      converged=true;
      return true;
    }
    dgg=gg=0.0;
    for (j=0; j < xi.length; j++) {
      gg+=g[j] * g[j];
      dgg+=xi[j] * (xi[j] - g[j]);
    }
    gam=dgg / gg;
    for (j=0; j < xi.length; j++) {
      g[j]=xi[j];
      h[j]=xi[j] + gam * h[j];
    }
    assert(!MatrixOps.isNaN(h));
    if (MatrixOps.dotProduct(xi,h) > 0) {
      MatrixOps.set(xi,h);
    }
 else {
      logger.warning("String_Node_Str");
      MatrixOps.set(h,xi);
    }
    iterations++;
    if (iterations > maxIterations) {
      logger.info("String_Node_Str");
      converged=true;
      return true;
    }
    if (eval != null) {
      eval.evaluate(optimizable,iterations);
    }
  }
  return false;
}