Program: 117233
Project: 117233
Buggy source:
/** 
 * Builds an elastic-net penalized binary classifier on sparse inputs. Each row of the input represents a feature (instead of a data point), i.e., in column-oriented format. This procedure does not assume the data is normalized or centered.
 * @param attrs the attribute list.
 * @param indices the indices.
 * @param values the values.
 * @param y the targets.
 * @param maxNumIters the maximum number of iterations.
 * @param lambda the lambda.
 * @param l1Ratio the L1 ratio.
 * @return an elastic-net penalized classifier.
 */
public GLM buildBinaryClassifier(int[] attrs,int[][] indices,double[][] values,int[] y,int maxNumIters,double lambda,double l1Ratio){
  double[] w=new double[attrs.length];
  double intercept=0;
  double[] pTrain=new double[y.length];
  double[] rTrain=new double[y.length];
  for (int i=0; i < rTrain.length; i++) {
    rTrain[i]=OptimUtils.getPseudoResidual(pTrain[i],y[i]);
  }
  double[] theta=new double[values.length];
  for (int i=0; i < values.length; i++) {
    theta[i]=StatUtils.sumSq(values[i]) / 4;
  }
  final double lambda1=lambda * l1Ratio;
  final double lambda2=lambda * (1 - l1Ratio);
  final double tl1=lambda1 * y.length;
  final double tl2=lambda2 * y.length;
  double prevLoss=GLMOptimUtils.computeElasticNetLoss(pTrain,y,w,lambda1,lambda2);
  for (int iter=0; iter < maxNumIters; iter++) {
    if (fitIntercept) {
      intercept+=OptimUtils.fitIntercept(pTrain,y);
    }
    doOnePass(indices,values,theta,y,tl1,tl2,w,pTrain,rTrain);
    double currLoss=GLMOptimUtils.computeElasticNetLoss(pTrain,y,w,lambda1,lambda2);
    if (verbose) {
      System.out.println("String_Node_Str" + iter + "String_Node_Str"+ "String_Node_Str"+ currLoss);
    }
    if (prevLoss - currLoss < epsilon) {
      break;
    }
    prevLoss=currLoss;
  }
  return GLMOptimUtils.getGLM(attrs,w,intercept);
}

Fixed version (ground truth):
/** 
 * Builds an elastic-net penalized binary classifier on sparse inputs. Each row of the input represents a feature (instead of a data point), i.e., in column-oriented format. This procedure does not assume the data is normalized or centered.
 * @param attrs the attribute list.
 * @param indices the indices.
 * @param values the values.
 * @param y the targets.
 * @param maxNumIters the maximum number of iterations.
 * @param lambda the lambda.
 * @param l1Ratio the L1 ratio.
 * @return an elastic-net penalized classifier.
 */
public GLM buildBinaryClassifier(int[] attrs,int[][] indices,double[][] values,int[] y,int maxNumIters,double lambda,double l1Ratio){
  double[] w=new double[attrs.length];
  double intercept=0;
  double[] pTrain=new double[y.length];
  double[] rTrain=new double[y.length];
  OptimUtils.computePseudoResidual(pTrain,y,rTrain);
  double[] theta=new double[values.length];
  for (int i=0; i < values.length; i++) {
    theta[i]=StatUtils.sumSq(values[i]) / 4;
  }
  final double lambda1=lambda * l1Ratio;
  final double lambda2=lambda * (1 - l1Ratio);
  final double tl1=lambda1 * y.length;
  final double tl2=lambda2 * y.length;
  double prevLoss=GLMOptimUtils.computeElasticNetLoss(pTrain,y,w,lambda1,lambda2);
  for (int iter=0; iter < maxNumIters; iter++) {
    if (fitIntercept) {
      intercept+=OptimUtils.fitIntercept(pTrain,rTrain,y);
    }
    doOnePass(indices,values,theta,y,tl1,tl2,w,pTrain,rTrain);
    double currLoss=GLMOptimUtils.computeElasticNetLoss(pTrain,y,w,lambda1,lambda2);
    if (verbose) {
      System.out.println("String_Node_Str" + iter + "String_Node_Str"+ "String_Node_Str"+ currLoss);
    }
    if (OptimUtils.isConverged(prevLoss,currLoss,epsilon)) {
      break;
    }
    prevLoss=currLoss;
  }
  return GLMOptimUtils.getGLM(attrs,w,intercept);
}