Program: 117236
Project: 117236
Buggy source:
/** 
 * Builds an elastic-net penalized regressor 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 regressor.
 */
public GLM buildRegressor(int[] attrs,int[][] indices,double[][] values,double[] y,int maxNumIters,double lambda,double l1Ratio){
  double[] w=new double[attrs.length];
  double intercept=0;
  double[] rTrain=new double[y.length];
  for (int i=0; i < rTrain.length; i++) {
    rTrain[i]=y[i];
  }
  double[] sq=new double[attrs.length];
  for (int i=0; i < values.length; i++) {
    sq[i]=StatUtils.sumSq(values[i]);
  }
  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(rTrain,w,lambda1,lambda2);
  for (int iter=0; iter < maxNumIters; iter++) {
    if (fitIntercept) {
      intercept+=OptimUtils.fitIntercept(rTrain);
    }
    doOnePass(indices,values,sq,tl1,tl2,w,rTrain);
    double currLoss=GLMOptimUtils.computeElasticNetLoss(rTrain,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 regressor 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 regressor.
 */
public GLM buildRegressor(int[] attrs,int[][] indices,double[][] values,double[] y,int maxNumIters,double lambda,double l1Ratio){
  double[] w=new double[attrs.length];
  double intercept=0;
  double[] rTrain=new double[y.length];
  for (int i=0; i < rTrain.length; i++) {
    rTrain[i]=y[i];
  }
  double[] sq=new double[attrs.length];
  for (int i=0; i < values.length; i++) {
    sq[i]=StatUtils.sumSq(values[i]);
  }
  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(rTrain,w,lambda1,lambda2);
  for (int iter=0; iter < maxNumIters; iter++) {
    if (fitIntercept) {
      intercept+=OptimUtils.fitIntercept(rTrain);
    }
    doOnePass(indices,values,sq,tl1,tl2,w,rTrain);
    double currLoss=GLMOptimUtils.computeElasticNetLoss(rTrain,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);
}