labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1509575 - /labs/yay/trunk/core/src/test/java/org/apache/yay/core/BasicPerceptronTest.java
Date Fri, 02 Aug 2013 07:52:23 GMT
Author: tommaso
Date: Fri Aug  2 07:52:23 2013
New Revision: 1509575

URL: http://svn.apache.org/r1509575
Log:
upgraded BasicPerceptronTest

Modified:
    labs/yay/trunk/core/src/test/java/org/apache/yay/core/BasicPerceptronTest.java

Modified: labs/yay/trunk/core/src/test/java/org/apache/yay/core/BasicPerceptronTest.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/test/java/org/apache/yay/core/BasicPerceptronTest.java?rev=1509575&r1=1509574&r2=1509575&view=diff
==============================================================================
--- labs/yay/trunk/core/src/test/java/org/apache/yay/core/BasicPerceptronTest.java (original)
+++ labs/yay/trunk/core/src/test/java/org/apache/yay/core/BasicPerceptronTest.java Fri Aug
 2 07:52:23 2013
@@ -21,6 +21,7 @@ package org.apache.yay.core;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedList;
+import java.util.Random;
 
 import org.apache.yay.Feature;
 import org.apache.yay.TrainingExample;
@@ -29,13 +30,15 @@ import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 /**
  * Testcase for {@link org.apache.yay.core.BasicPerceptron}
  */
 public class BasicPerceptronTest {
 
-  private TrainingSet<Double, Double> dataset;
+  private TrainingSet<Double, Double> smallDataset;
+  private TrainingSet<Double, Double> bigDataset;
 
   @Before
   public void setUp() throws Exception {
@@ -44,21 +47,67 @@ public class BasicPerceptronTest {
     samples.add(createTrainingExample(1d, 5d, 6d, 0.5d));
     samples.add(createTrainingExample(0.1d, 9d, 4d, 1.9d));
     samples.add(createTrainingExample(0.11d, 4d, 2.6d, 9.5d));
-    dataset = new TrainingSet<Double,Double>(samples);
+    smallDataset = new TrainingSet<Double,Double>(samples);
+
+    Collection<TrainingExample<Double, Double>> samples1 = new LinkedList<TrainingExample<Double,
Double>>() ;
+    Random r = new Random();
+    for (int i = 0; i < 100000; i++) {
+        samples1.add(createTrainingExample(1d, r.nextDouble(),
+                r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+                r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+                r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+                r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+                r.nextDouble(), r.nextDouble()));
+    }
+    bigDataset = new TrainingSet<Double,Double>(samples1);
+
   }
 
   @Test
   @SuppressWarnings("unchecked")
-  public void testLearnPhase() throws Exception {
-    BasicPerceptron basicPerceptron = new BasicPerceptron(1d, 2d, 3d, 4d);
-    basicPerceptron.learn(dataset);
+  public void testLearnPhaseWithBigDataset() throws Exception {
+    Random r = new Random();
+    BasicPerceptron basicPerceptron = new BasicPerceptron(1d, r.nextDouble(),
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble());
+    basicPerceptron.learn(bigDataset);
+  }
+
+  @Test
+  @SuppressWarnings("unchecked")
+  public void testLearnAndPredictWithBigDataset() throws Exception {
+    Random r = new Random();
+    BasicPerceptron basicPerceptron = new BasicPerceptron(1d, r.nextDouble(),
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble());
+    basicPerceptron.learn(bigDataset);
+    Double output = basicPerceptron.predict(createTrainingExample(null, 1d,
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+            r.nextDouble(), r.nextDouble()));
+    assertTrue(output == 0d || output == 1d);
   }
 
   @Test
   @SuppressWarnings("unchecked")
-  public void testPredictionPhase() throws Exception {
+  public void testLearnPhaseWithSmallDataset() throws Exception {
+    BasicPerceptron basicPerceptron = new BasicPerceptron(1d, 2d, 3d, 4d);
+    basicPerceptron.learn(smallDataset);
+}
+
+  @Test
+  @SuppressWarnings("unchecked")
+  public void testLearnAndPredictWithSmallDataset() throws Exception {
     BasicPerceptron basicPerceptron = new BasicPerceptron(1d, 2d, 3d, 4d);
-    basicPerceptron.learn(dataset);
+    basicPerceptron.learn(smallDataset);
     Double output = basicPerceptron.predict(createTrainingExample(null, 1d, 6d, 0.4d));
     assertEquals(Double.valueOf(1d), output);
   }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message