Program: 32953
Project: 32953
Buggy source:
private void optimizeOneClass(int classIndex){
  int numDataPoints=dataSet.getNumDataPoints();
  double[] labels=new double[numDataPoints];
  double[] instanceWeights=new double[numDataPoints];
  IntStream.range(0,numDataPoints).parallel().forEach(i -> {
    double prob=logisticRegression.predictClassProbs(dataSet.getRow(i))[classIndex];
    double classScore=logisticRegression.predictClassScore(dataSet.getRow(i),classIndex);
    double y=0;
    if (labels[i] == classIndex) {
      y=1;
    }
    double frac=0;
    if (prob != 0 && prob != 1) {
      frac=(y - prob) / (prob * (1 - prob));
    }
    if (frac > 1) {
      frac=1;
    }
    if (frac < -1) {
      frac=-1;
    }
    labels[i]=classScore + frac;
    instanceWeights[i]=(prob * (1 - prob)) / numDataPoints;
  }
);
  Weights oldWeights=logisticRegression.getWeights().deepCopy();
  Vector gradient=this.predictedCounts.minus(empiricalCounts).divide(numDataPoints);
  LinearRegression linearRegression=new LinearRegression(dataSet.getNumFeatures(),logisticRegression.getWeights().getWeightsForClass(classIndex));
  ElasticNetLinearRegOptimizer linearRegTrainer=new ElasticNetLinearRegOptimizer(linearRegression,dataSet,labels,instanceWeights);
  linearRegTrainer.setRegularization(this.regularization);
  linearRegTrainer.setL1Ratio(this.l1Ratio);
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str");
  }
  linearRegTrainer.optimize();
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str");
  }
  Weights newWeights=logisticRegression.getWeights().deepCopy();
  Vector searchDirection=newWeights.getAllWeights().minus(oldWeights.getAllWeights());
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + searchDirection.norm(2));
  }
  logisticRegression.getWeights().setWeightVector(oldWeights.getAllWeights());
  if (lineSearch) {
    lineSearch(searchDirection,gradient);
  }
 else {
    withoutLineSearch(searchDirection,gradient);
  }
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + loss());
  }
  updateClassProbMatrix();
  updatePredictedCounts();
}

Fixed version (ground truth):
private void optimizeOneClass(int classIndex){
  int numDataPoints=dataSet.getNumDataPoints();
  double[] realLabels=new double[numDataPoints];
  double[] instanceWeights=new double[numDataPoints];
  IntStream.range(0,numDataPoints).parallel().forEach(i -> {
    double prob=logisticRegression.predictClassProbs(dataSet.getRow(i))[classIndex];
    double classScore=logisticRegression.predictClassScore(dataSet.getRow(i),classIndex);
    double y=0;
    if (labels[i] == classIndex) {
      y=1;
    }
    double frac=0;
    if (prob != 0 && prob != 1) {
      frac=(y - prob) / (prob * (1 - prob));
    }
    if (frac > 1) {
      frac=1;
    }
    if (frac < -1) {
      frac=-1;
    }
    realLabels[i]=classScore + frac;
    instanceWeights[i]=(prob * (1 - prob)) / numDataPoints;
  }
);
  Weights oldWeights=logisticRegression.getWeights().deepCopy();
  Vector gradient=this.predictedCounts.minus(empiricalCounts).divide(numDataPoints);
  LinearRegression linearRegression=new LinearRegression(dataSet.getNumFeatures(),logisticRegression.getWeights().getWeightsForClass(classIndex));
  ElasticNetLinearRegOptimizer linearRegTrainer=new ElasticNetLinearRegOptimizer(linearRegression,dataSet,realLabels,instanceWeights);
  linearRegTrainer.setRegularization(this.regularization);
  linearRegTrainer.setL1Ratio(this.l1Ratio);
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str");
  }
  linearRegTrainer.optimize();
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str");
  }
  Weights newWeights=logisticRegression.getWeights().deepCopy();
  Vector searchDirection=newWeights.getAllWeights().minus(oldWeights.getAllWeights());
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + searchDirection.norm(2));
  }
  logisticRegression.getWeights().setWeightVector(oldWeights.getAllWeights());
  if (lineSearch) {
    lineSearch(searchDirection,gradient);
  }
 else {
    withoutLineSearch(searchDirection,gradient);
  }
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + loss());
  }
  updateClassProbMatrix();
  updatePredictedCounts();
}