Author: tommaso
Date: Tue May 29 07:39:01 2012
New Revision: 1343582

URL: http://svn.apache.org/viewvc?rev=1343582&view=rev
Log:
added test for an AND NN creation based on FF strategy

Added:
    
labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java

Added: 
labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java
URL: 
http://svn.apache.org/viewvc/labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java?rev=1343582&view=auto
==============================================================================
--- 
labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java 
(added)
+++ 
labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java 
Tue May 29 07:39:01 2012
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.yay;
+
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.Vector;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Testcase for {@link NeuralNetworkFactory}
+ */
+public class NeuralNetworkFactoryTest {
+
+  @Test
+  public void andNNCreationTest() throws Exception {
+    Set<WeightsMatrix> andWeightsMatrixSet = new HashSet<WeightsMatrix>();
+    double[][] weights = {{-30d, 20d, 20d}};
+    WeightsMatrix singleAndLayerWeights = new WeightsMatrix(weights);
+    andWeightsMatrixSet.add(singleAndLayerWeights);
+    NeuralNetwork<Double,Double> andNN = NeuralNetworkFactory.create(new 
LinkedList<TrainingExample<Double, Double>>(), andWeightsMatrixSet, new 
VoidLearningStrategy(), new FeedForwardStrategy(new SigmoidFunction()));
+    assertEquals(0l, Math.round(andNN.predict(createSample(1d, 0d))));
+    assertEquals(1l, Math.round(andNN.predict(createSample(1d, 1d))));
+  }
+
+  private Example<Double> createSample(final Double x, final Double y) {
+    return new Example<Double>() {
+      @Override
+      public Vector<Feature<Double>> getFeatureVector() {
+        Vector<Feature<Double>> features = new Vector<Feature<Double>>();
+        Feature<Double> byasFeature = new Feature<Double>();
+        byasFeature.setValue(1d);
+        features.add(byasFeature);
+        Feature<Double> trueFeature = new Feature<Double>();
+        trueFeature.setValue(x);
+        features.add(trueFeature);
+        Feature<Double> falseFeature = new Feature<Double>();
+        falseFeature.setValue(y);
+        features.add(falseFeature);
+        return features;
+      }
+    };
+  }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to