Program: 144178
Project: 144178
Buggy source:
private double computeBeta(){
  Vector gradientsDifference;
  double denominator;
switch (method) {
case FLETCHER_RIEVES:
    return currentGradient.innerProduct(currentGradient) / previousGradient.innerProduct(previousGradient);
case POLAK_RIBIERE:
  return currentGradient.innerProduct(currentGradient.subtract(previousGradient)) / previousGradient.innerProduct(previousGradient);
case POLAK_RIBIERE_PLUS:
return Math.max(currentGradient.innerProduct(currentGradient.subtract(previousGradient)) / previousGradient.innerProduct(previousGradient),0);
case HESTENES_STIEFEL:
if (currentIteration != 0) {
gradientsDifference=currentGradient.subtract(previousGradient);
return currentGradient.innerProduct(gradientsDifference) / gradientsDifference.innerProduct(previousDirection);
}
 else {
return 0;
}
case FLETCHER_RIEVES_POLAK_RIBIERE:
denominator=previousGradient.innerProduct(previousGradient);
double betaFR=currentGradient.innerProduct(currentGradient) / denominator;
double betaPR=currentGradient.innerProduct(currentGradient.subtract(previousGradient)) / denominator;
if (betaPR < -betaFR) {
return -betaFR;
}
 else if (betaPR > betaFR) {
return betaFR;
}
 else {
return betaPR;
}
case DAI_YUAN:
if (currentIteration != 0) {
return currentGradient.innerProduct(currentGradient) / currentGradient.subtract(previousGradient).innerProduct(previousDirection);
}
 else {
return 0;
}
case HAGER_ZHANG:
if (currentIteration != 0) {
gradientsDifference=currentGradient.subtract(previousGradient);
denominator=gradientsDifference.innerProduct(previousDirection);
Vector temporaryTerm=gradientsDifference.subtract(previousDirection.multiply(2 * gradientsDifference.innerProduct(gradientsDifference) / denominator));
return temporaryTerm.innerProduct(currentGradient) / denominator;
}
 else {
return 0;
}
default :
throw new NotImplementedException();
}
}

Fixed version (ground truth):
private double computeBeta(){
  Vector gradientsDifference;
  double denominator;
switch (method) {
case FLETCHER_RIEVES:
    return currentGradient.innerProduct(currentGradient) / previousGradient.innerProduct(previousGradient);
case POLAK_RIBIERE:
  return currentGradient.innerProduct(currentGradient.subtract(previousGradient)) / previousGradient.innerProduct(previousGradient);
case POLAK_RIBIERE_PLUS:
return Math.max(currentGradient.innerProduct(currentGradient.subtract(previousGradient)) / previousGradient.innerProduct(previousGradient),0);
case HESTENES_STIEFEL:
gradientsDifference=currentGradient.subtract(previousGradient);
if (gradientsDifference.computeL2Norm() != 0) {
return currentGradient.innerProduct(gradientsDifference) / gradientsDifference.innerProduct(previousDirection);
}
 else {
return 0;
}
case FLETCHER_RIEVES_POLAK_RIBIERE:
denominator=previousGradient.innerProduct(previousGradient);
double betaFR=currentGradient.innerProduct(currentGradient) / denominator;
double betaPR=currentGradient.innerProduct(currentGradient.subtract(previousGradient)) / denominator;
if (betaPR < -betaFR) {
return -betaFR;
}
 else if (betaPR > betaFR) {
return betaFR;
}
 else {
return betaPR;
}
case DAI_YUAN:
gradientsDifference=currentGradient.subtract(previousGradient);
if (gradientsDifference.computeL2Norm() != 0) {
return currentGradient.innerProduct(currentGradient) / gradientsDifference.innerProduct(previousDirection);
}
 else {
return 0;
}
case HAGER_ZHANG:
gradientsDifference=currentGradient.subtract(previousGradient);
if (gradientsDifference.computeL2Norm() != 0) {
denominator=gradientsDifference.innerProduct(previousDirection);
Vector temporaryTerm=gradientsDifference.subtract(previousDirection.multiply(2 * gradientsDifference.innerProduct(gradientsDifference) / denominator));
return temporaryTerm.innerProduct(currentGradient) / denominator;
}
 else {
return 0;
}
default :
throw new NotImplementedException();
}
}