Program: 117234
Project: 117234
Buggy source:
/** 
 * Builds elastic-net penalized binary classifiers on sparse inputs for a sequence of regularization parameter lambdas. 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 numLambdas the number of lambdas.
 * @param minLambdaRatio the minimum lambda is minLambdaRatio * max lambda.
 * @param l1Ratio the L1 ratio.
 * @return an elastic-net penalized classifier.
 */
public GLM[] buildBinaryClassifiers(int[] attrs,int[][] indices,double[][] values,int[] y,int maxNumIters,int numLambdas,double minLambdaRatio,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;
  }
  double maxLambda=findMaxLambda(indices,values,y,pTrain,l1Ratio);
  double alpha=Math.pow(minLambdaRatio,1.0 / numLambdas);
  GLM[] glms=new GLM[numLambdas];
  double lambda=maxLambda;
  for (int g=0; g < glms.length; g++) {
    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;
    }
    glms[g]=GLMOptimUtils.getGLM(attrs,w,intercept);
    lambda*=alpha;
  }
  return glms;
}

Fixed version (ground truth):
/** 
 * Builds elastic-net penalized binary classifiers on sparse inputs for a sequence of regularization parameter lambdas. 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 numLambdas the number of lambdas.
 * @param minLambdaRatio the minimum lambda is minLambdaRatio * max lambda.
 * @param l1Ratio the L1 ratio.
 * @return an elastic-net penalized classifier.
 */
public GLM[] buildBinaryClassifiers(int[] attrs,int[][] indices,double[][] values,int[] y,int maxNumIters,int numLambdas,double minLambdaRatio,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;
  }
  double maxLambda=findMaxLambda(indices,values,y,pTrain,rTrain,l1Ratio);
  double alpha=Math.pow(minLambdaRatio,1.0 / numLambdas);
  GLM[] glms=new GLM[numLambdas];
  double lambda=maxLambda;
  for (int g=0; g < glms.length; g++) {
    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;
    }
    glms[g]=GLMOptimUtils.getGLM(attrs,w,intercept);
    lambda*=alpha;
  }
  return glms;
}