Program: 144207
Project: 144207
Buggy source:
/** 
 * Checks whether the Wolfe conditions are satisfied for a given objective function, point, direction and step size. The Wolfe conditions consist of the Armijo condition (also known as the sufficient decrease condition) and the curvature condition. The Armijo condition makes sure that the reduction in the objective function value is proportional to both the step size and the directional derivative. This condition is satisfied for all sufficiently small values of the step size and so, in order to ensure that the optimization algorithm makes sufficient progress, we also check for the curvature condition. Typical values for the proportionality constants are: for   {@code c1}, 1e-4, and for   {@code c2}, 0.9 when the search direction is chosen by a Newton or quasi-Newton method and 0.1 when the search direction is obtained from a nonlinear conjugate gradient method.
 * @param objective                       The objective function instance.
 * @param point                           The point at which we check whether the Wolfe conditions are satisfied.
 * @param direction                       The direction for which we check whether the Wolfe conditions aresatisfied.
 * @param stepSize                        The value of the step size for which we check whether the Wolfeconditions are satisfied.
 * @param c1                              The proportionality constant used for the first of the two Wolfeconditions (that is, the Armijo condition).
 * @param c2                              The proportionality constant used for the second of the two Wolfeconditions (that is, the curvature condition).
 * @param strong                          A boolean value indicating whether or not to check for the strong Wolfeconditions. The only difference is actually on the curvature condition and, when we use the strong Wolfe conditions instead of the simple Wolfe conditions, we effectively exclude points from the search that are far from the exact line search solution.
 * @param objectiveValueAtCurrentPoint    The value of the objective function at the current point.
 * @param objectiveGradientAtCurrentPoint The gradient of the objective function evaluated at the current point.
 * @return                                  A boolean value ind objective, point, direction and step size.
 */
public static boolean checkWolfeConditions(Function objective,RealVector point,RealVector direction,double stepSize,double c1,double c2,boolean strong,double objectiveValueAtCurrentPoint,RealVector objectiveGradientAtCurrentPoint){
  Preconditions.checkArgument(c1 > 0 && c1 < 1);
  Preconditions.checkArgument(c2 > c1 && c2 < 1);
  boolean armijoConditionSatisfied=checkArmijoCondition(objective,point,direction,stepSize,c1,objectiveValueAtCurrentPoint,objectiveGradientAtCurrentPoint);
  double leftTerm=objective.computeGradient(point.add(direction.mapMultiply(stepSize))).dotProduct(direction);
  double rightTerm=objectiveGradientAtCurrentPoint.dotProduct(direction);
  boolean curvatureConditionSatisfied;
  if (strong) {
    curvatureConditionSatisfied=Math.abs(leftTerm) >= c2 * Math.abs(rightTerm);
  }
 else {
    curvatureConditionSatisfied=leftTerm >= c2 * rightTerm;
  }
  return armijoConditionSatisfied && curvatureConditionSatisfied;
}

Fixed version (ground truth):
/** 
 * Checks whether the Wolfe conditions are satisfied for a given objective function, point, direction and step size. The Wolfe conditions consist of the Armijo condition (also known as the sufficient decrease condition) and the curvature condition. The Armijo condition makes sure that the reduction in the objective function value is proportional to both the step size and the directional derivative. This condition is satisfied for all sufficiently small values of the step size and so, in order to ensure that the optimization algorithm makes sufficient progress, we also check for the curvature condition. Typical values for the proportionality constants are: for   {@code c1}, 1e-4, and for   {@code c2}, 0.9 when the search direction is chosen by a Newton or quasi-Newton method and 0.1 when the search direction is obtained from a nonlinear conjugate gradient method.
 * @param objective                       The objective function instance.
 * @param point                           The point at which we check whether the Wolfe conditions are satisfied.
 * @param direction                       The direction for which we check whether the Wolfe conditions aresatisfied.
 * @param stepSize                        The value of the step size for which we check whether the Wolfeconditions are satisfied.
 * @param c1                              The proportionality constant used for the first of the two Wolfeconditions (that is, the Armijo condition).
 * @param c2                              The proportionality constant used for the second of the two Wolfeconditions (that is, the curvature condition).
 * @param strong                          A boolean value indicating whether or not to check for the strong Wolfeconditions. The only difference is actually on the curvature condition and, when we use the strong Wolfe conditions instead of the simple Wolfe conditions, we effectively exclude points from the search that are far from the exact line search solution.
 * @param objectiveValueAtCurrentPoint    The value of the objective function at the current point.
 * @param objectiveGradientAtCurrentPoint The gradient of the objective function evaluated at the current point.
 * @return                                  A boolean value ind objective, point, direction and step size.
 */
public static boolean checkWolfeConditions(Function objective,RealVector point,RealVector direction,double stepSize,double c1,double c2,boolean strong,double objectiveValueAtCurrentPoint,RealVector objectiveGradientAtCurrentPoint){
  Preconditions.checkArgument(c1 > 0 && c1 < 1);
  Preconditions.checkArgument(c2 > c1 && c2 < 1);
  boolean armijoConditionSatisfied=checkArmijoCondition(objective,point,direction,stepSize,c1,objectiveValueAtCurrentPoint,objectiveGradientAtCurrentPoint);
  double leftTerm=objective.computeGradient(point.add(direction.mapMultiply(stepSize))).dotProduct(direction);
  double rightTerm=objectiveGradientAtCurrentPoint.dotProduct(direction);
  boolean curvatureConditionSatisfied;
  if (strong) {
    curvatureConditionSatisfied=Math.abs(leftTerm) <= c2 * Math.abs(rightTerm);
  }
 else {
    curvatureConditionSatisfied=leftTerm >= c2 * rightTerm;
  }
  return armijoConditionSatisfied && curvatureConditionSatisfied;
}