hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1415527 - in /hama/trunk/examples/src: main/java/org/apache/hama/examples/GradientDescentExample.java test/java/org/apache/hama/examples/LinearRegressionTest.java
Date Fri, 30 Nov 2012 07:47:00 GMT
Author: tommaso
Date: Fri Nov 30 07:46:59 2012
New Revision: 1415527

URL: http://svn.apache.org/viewvc?rev=1415527&view=rev
Log:
[HAMA-682] - added usage string to GD example

Modified:
    hama/trunk/examples/src/main/java/org/apache/hama/examples/GradientDescentExample.java
    hama/trunk/examples/src/test/java/org/apache/hama/examples/LinearRegressionTest.java

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/GradientDescentExample.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/GradientDescentExample.java?rev=1415527&r1=1415526&r2=1415527&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/GradientDescentExample.java
(original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/GradientDescentExample.java
Fri Nov 30 07:46:59 2012
@@ -43,15 +43,30 @@ public class GradientDescentExample {
 
   public static void main(String[] args) throws InterruptedException,
       IOException, ClassNotFoundException {
+
+   if (!(args.length == 1 || args.length == 2)) {
+     System.out.println("USAGE: <INPUT_PATH> [<REGRESSION_MODEL>]");
+     return;
+   }
+
     // BSP job configuration
     HamaConfiguration conf = new HamaConfiguration();
     conf.setFloat(GradientDescentBSP.ALPHA, 0.002f);
     conf.setFloat(GradientDescentBSP.COST_THRESHOLD, 0.5f);
     conf.setInt(GradientDescentBSP.ITERATIONS_THRESHOLD, 300);
     conf.setInt(GradientDescentBSP.INITIAL_THETA_VALUES, 10);
-    if (args.length > 1 && args[1] != null && args[1].equals("logistic"))
{
-      conf.setClass(GradientDescentBSP.REGRESSION_MODEL_CLASS,
+    if (args.length == 2 && args[1] != null) {
+      if (args[1].equals("logistic")) {
+        conf.setClass(GradientDescentBSP.REGRESSION_MODEL_CLASS,
           LogisticRegressionModel.class, RegressionModel.class);
+      }
+      else if (args[1].equals("linear")) {
+        // do nothing as 'linear' is default
+      }
+      else {
+        throw new RuntimeException(new StringBuilder("unsupported RegressionModel").
+                append(args[1]).append(", use 'logistic' or 'linear'").toString());
+      }
     }
 
     BSPJob bsp = new BSPJob(conf, GradientDescentExample.class);
@@ -90,4 +105,5 @@ public class GradientDescentExample {
 
     fs.delete(TMP_OUTPUT, true);
   }
+
 }

Modified: hama/trunk/examples/src/test/java/org/apache/hama/examples/LinearRegressionTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/test/java/org/apache/hama/examples/LinearRegressionTest.java?rev=1415527&r1=1415526&r2=1415527&view=diff
==============================================================================
--- hama/trunk/examples/src/test/java/org/apache/hama/examples/LinearRegressionTest.java (original)
+++ hama/trunk/examples/src/test/java/org/apache/hama/examples/LinearRegressionTest.java Fri
Nov 30 07:46:59 2012
@@ -27,17 +27,7 @@ import static org.junit.Assert.fail;
 public class LinearRegressionTest {
   @Test
   public void testCorrectGDWithLinearRegressionExecution() throws Exception {
-    GradientDescentExample.main(new String[]{"src/test/resources/linear_regression_sample.txt"});
-  }
-
-  @Test
-  public void testWrongGDExecutionWithEmptyArgs() {
-    try {
-      GradientDescentExample.main(new String[0]);
-      fail("GradientDescentExample should fail if the argument list has size 0");
-    } catch (Exception e) {
-      // everything ok
-    }
+    GradientDescentExample.main(new String[]{"src/test/resources/linear_regression_sample.txt",
"linear"});
   }
 
 }



Mime
View raw message