<NME> App4.java
<BEF> ADDFILE
<MSG> add App4

<DFF> @@ -0,0 +1,55 @@
+package edu.neu.ccs.pyramid.application;
+
+import edu.neu.ccs.pyramid.configuration.Config;
+import edu.neu.ccs.pyramid.dataset.DataSetType;
+import edu.neu.ccs.pyramid.dataset.RegDataSet;
+import edu.neu.ccs.pyramid.dataset.TRECFormat;
+import edu.neu.ccs.pyramid.eval.RMSE;
+import edu.neu.ccs.pyramid.regression.linear_regression.ElasticNetLinearRegOptimizer;
+import edu.neu.ccs.pyramid.regression.linear_regression.LinearRegression;
+
+/**
+ * Linear Regression with Elasticnet (L1+L2) regularization
+ * Created by chengli on 2/25/16.
+ */
+public class App4 {
+
+    public static void main(String[] args) throws Exception{
+        if (args.length !=1){
+            throw new IllegalArgumentException("Please specify a properties file.");
+        }
+
+        Config config = new Config(args[0]);
+        System.out.println(config);
+
+        String sparsity = config.getString("featureMatrix.sparsity").toLowerCase();
+        DataSetType dataSetType = null;
+        switch (sparsity){
+            case "dense":
+                dataSetType = DataSetType.REG_DENSE;
+                break;
+            case "sparse":
+                dataSetType = DataSetType.REG_SPARSE;
+                break;
+            default:
+                throw new IllegalArgumentException("featureMatrix.sparsity can be either dense or sparse");
+        }
+
+        RegDataSet trainSet = TRECFormat.loadRegDataSet(config.getString("input.trainSet"),dataSetType,true);
+        RegDataSet testSet = TRECFormat.loadRegDataSet(config.getString("input.testSet"),dataSetType,true);
+
+        LinearRegression linearRegression = new LinearRegression(trainSet.getNumFeatures());
+        ElasticNetLinearRegOptimizer optimizer = new ElasticNetLinearRegOptimizer(linearRegression,trainSet);
+        optimizer.setRegularization(config.getDouble("regularization"));
+        optimizer.setL1Ratio(config.getDouble("l1Ratio"));
+        System.out.println("before training");
+        System.out.println("training set RMSE = "+ RMSE.rmse(linearRegression,trainSet));
+        System.out.println("test set RMSE = "+ RMSE.rmse(linearRegression,testSet));
+        System.out.println("start training");
+        optimizer.optimize();
+        System.out.println("training done");
+        System.out.println("after training");
+        System.out.println("training set RMSE = "+ RMSE.rmse(linearRegression,trainSet));
+        System.out.println("test set RMSE = "+ RMSE.rmse(linearRegression,testSet));
+    }
+}

add App4