You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by to...@apache.org on 2012/11/10 09:16:04 UTC
svn commit: r1407730 - in /hama/trunk/examples/src:
main/java/org/apache/hama/examples/GradientDescentExample.java
test/java/org/apache/hama/examples/GradientDescentTest.java
Author: tommaso
Date: Sat Nov 10 08:16:03 2012
New Revision: 1407730
URL: http://svn.apache.org/viewvc?rev=1407730&view=rev
Log:
[HAMA-669] - fixed tests
Modified:
hama/trunk/examples/src/main/java/org/apache/hama/examples/GradientDescentExample.java
hama/trunk/examples/src/test/java/org/apache/hama/examples/GradientDescentTest.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=1407730&r1=1407729&r2=1407730&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 Sat Nov 10 08:16:03 2012
@@ -28,6 +28,8 @@ import org.apache.hama.bsp.BSPJob;
import org.apache.hama.bsp.FileOutputFormat;
import org.apache.hama.bsp.TextOutputFormat;
import org.apache.hama.ml.regression.GradientDescentBSP;
+import org.apache.hama.ml.regression.LogisticRegressionModel;
+import org.apache.hama.ml.regression.RegressionModel;
import org.apache.hama.ml.regression.VectorDoubleFileInputFormat;
import org.apache.hama.ml.writable.VectorWritable;
@@ -46,6 +48,10 @@ public class GradientDescentExample {
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, LogisticRegressionModel.class, RegressionModel.class);
+ }
BSPJob bsp = new BSPJob(conf, GradientDescentExample.class);
// Set the job name
@@ -62,9 +68,9 @@ public class GradientDescentExample {
long startTime = System.currentTimeMillis();
if (bsp.waitForCompletion(true)) {
- printOutput(conf);
- System.out.println("Job Finished in "
- + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds");
+ printOutput(conf);
+ System.out.println("Job Finished in "
+ + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds");
}
}
@@ -73,12 +79,12 @@ public class GradientDescentExample {
FileSystem fs = FileSystem.get(conf);
FileStatus[] files = fs.listStatus(TMP_OUTPUT);
for (int i = 0; i < files.length; i++) {
- if (files[i].getLen() > 0) {
- FSDataInputStream in = fs.open(files[i].getPath());
- IOUtils.copyBytes(in, System.out, conf, false);
- in.close();
- break;
- }
+ if (files[i].getLen() > 0) {
+ FSDataInputStream in = fs.open(files[i].getPath());
+ IOUtils.copyBytes(in, System.out, conf, false);
+ in.close();
+ break;
+ }
}
fs.delete(TMP_OUTPUT, true);
Modified: hama/trunk/examples/src/test/java/org/apache/hama/examples/GradientDescentTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/test/java/org/apache/hama/examples/GradientDescentTest.java?rev=1407730&r1=1407729&r2=1407730&view=diff
==============================================================================
--- hama/trunk/examples/src/test/java/org/apache/hama/examples/GradientDescentTest.java (original)
+++ hama/trunk/examples/src/test/java/org/apache/hama/examples/GradientDescentTest.java Sat Nov 10 08:16:03 2012
@@ -26,17 +26,17 @@ import static org.junit.Assert.fail;
*/
public class GradientDescentTest {
@Test
- public void testCorrectGDExecution() throws Exception {
+ public void testCorrectGDWithLinearRegressionExecution() throws Exception {
GradientDescentExample.main(new String[]{"src/test/resources/gd_file_sample.txt"});
}
@Test
public void testWrongGDExecutionWithEmptyArgs() {
try {
- GradientDescentExample.main(new String[0]);
- fail("GradientDescentExample should fail if the argument list has size 0");
+ GradientDescentExample.main(new String[0]);
+ fail("GradientDescentExample should fail if the argument list has size 0");
} catch (Exception e) {
- // everything ok
+ // everything ok
}
}