You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by to...@apache.org on 2012/01/10 15:12:51 UTC

svn commit: r1229548 - in /labs/yay/trunk/core/src: main/java/org/apache/yay/ test/java/org/apache/yay/

Author: tommaso
Date: Tue Jan 10 14:12:51 2012
New Revision: 1229548

URL: http://svn.apache.org/viewvc?rev=1229548&view=rev
Log:
introduced TrainingExample and Feature classes
modified NNfactory getting rid of bio package as bio must depend on basic classes rather than viceversa
NNFactory is initialized with a Set of WeightMatrixes and a Collection<TrainingExample>

Added:
    labs/yay/trunk/core/src/main/java/org/apache/yay/Feature.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/TrainingExample.java
Modified:
    labs/yay/trunk/core/src/main/java/org/apache/yay/InvalidWeightMatrixException.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetworkFactory.java
    labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java

Added: labs/yay/trunk/core/src/main/java/org/apache/yay/Feature.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/Feature.java?rev=1229548&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/Feature.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/Feature.java Tue Jan 10 14:12:51 2012
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+/**
+ * A feature of a training example
+ */
+public class Feature<T> {
+
+  private String name;
+  private T value;
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public T getValue() {
+    return value;
+  }
+
+  public void setValue(T value) {
+    this.value = value;
+  }
+}

Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/InvalidWeightMatrixException.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/InvalidWeightMatrixException.java?rev=1229548&r1=1229547&r2=1229548&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/InvalidWeightMatrixException.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/InvalidWeightMatrixException.java Tue Jan 10 14:12:51 2012
@@ -19,7 +19,7 @@
 package org.apache.yay;
 
 /**
- *
+ * {@link Exception} thrown when a {@link WeightsMatrix} is verified to be invalid
  */
 public class InvalidWeightMatrixException extends Exception {
 }

Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetworkFactory.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetworkFactory.java?rev=1229548&r1=1229547&r2=1229548&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetworkFactory.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetworkFactory.java Tue Jan 10 14:12:51 2012
@@ -18,39 +18,35 @@
  */
 package org.apache.yay;
 
-import org.apache.yay.bio.Axon;
-import org.apache.yay.bio.Dendrite;
-import org.apache.yay.bio.Neuron;
 import org.apache.yay.bio.Signal;
 
 import java.util.Collection;
+import java.util.Set;
 
 /**
- *
+ * Factory class for creating {@link NeuralNetwork}s
  */
 public class NeuralNetworkFactory {
-  public static NeuralNetwork create(WeightsMatrix weightsMatrix) throws InvalidWeightMatrixException {
-
-    // TODO : validate the weights matrix
-
-    // traverse the weight matrix to create layers of neurons
-    for (Long[] column : weightsMatrix.getColumns()) {
-      Layer l = null;
-      for (Long weight : column) {
-        ActivationFunction activationFunction = null;
-        Axon axon = null;
-        Collection<Dendrite> dendrites = null;
-        Neuron n = new Neuron(new BasicElaborationUnit(activationFunction), dendrites, axon);
-        l.add(n);
-      }
-    }
+  public static NeuralNetwork create(Set<WeightsMatrix> weightsMatrixes, Collection<TrainingExample> trainingSet) throws InvalidWeightMatrixException {
 
     // ad bias units to each layer
 
+
     // return the NN
     NeuralNetwork neuralNetwork = new NeuralNetwork() {
       @Override
       public Signal predict(Signal... input) {
+        /* Octave code to be converted :
+        * m = size(X, 1);
+        num_labels = size(Theta2, 1);
+
+        p = zeros(size(X, 1), 1);
+
+        h1 = sigmoid([ones(m, 1) X] * Theta1');
+        h2 = sigmoid([ones(m, 1) h1] * Theta2');
+        [dummy, p] = max(h2, [], 2);
+
+         */
         return null;
       }
     };

Added: labs/yay/trunk/core/src/main/java/org/apache/yay/TrainingExample.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/TrainingExample.java?rev=1229548&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/TrainingExample.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/TrainingExample.java Tue Jan 10 14:12:51 2012
@@ -0,0 +1,33 @@
+/*
+ * 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.apache.yay.bio.Signal;
+
+import java.util.Vector;
+
+/**
+ * A training example with input features and associated output
+ */
+public interface TrainingExample<F, O> {
+
+  public Vector<Feature<F>> getFeatureVector();
+
+  public Signal<O> getOutput();
+}

Modified: 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=1229548&r1=1229547&r2=1229548&view=diff
==============================================================================
--- labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java (original)
+++ labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java Tue Jan 10 14:12:51 2012
@@ -21,6 +21,8 @@ package org.apache.yay;
 import org.junit.Test;
 
 import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
@@ -37,7 +39,9 @@ public class NeuralNetworkFactoryTest {
     try {
       WeightsMatrix weightsMatrix = mock(WeightsMatrix.class);
       when(weightsMatrix.getColumns()).thenReturn(new ArrayList<Long[]>());
-      NeuralNetworkFactory.create(weightsMatrix);
+      Set<WeightsMatrix> weightsMatrixes = new HashSet<WeightsMatrix>(1);
+      weightsMatrixes.add(weightsMatrix);
+      NeuralNetworkFactory.create(weightsMatrixes);
       fail("an empty weight matrix has no meaning");
     } catch (InvalidWeightMatrixException e) {
       // everything ok
@@ -49,7 +53,9 @@ public class NeuralNetworkFactoryTest {
     try {
       WeightsMatrix weightsMatrix = mock(WeightsMatrix.class);
       when(weightsMatrix.getColumns()).thenReturn(null);
-      NeuralNetworkFactory.create(weightsMatrix);
+      Set<WeightsMatrix> weightsMatrixes = new HashSet<WeightsMatrix>(1);
+      weightsMatrixes.add(weightsMatrix);
+      NeuralNetworkFactory.create(weightsMatrixes);
       fail("a null weight matrix is not a valid parameter");
     } catch (InvalidWeightMatrixException e) {
       // everything ok
@@ -62,7 +68,9 @@ public class NeuralNetworkFactoryTest {
       WeightsMatrix weightsMatrix = new WeightsMatrix();
       weightsMatrix.addColumn(new Long[]{10l, -23l, 123l});
       weightsMatrix.addColumn(new Long[]{12l});
-      NeuralNetwork neuralNetwork = NeuralNetworkFactory.create(weightsMatrix);
+      Set<WeightsMatrix> weightsMatrixes = new HashSet<WeightsMatrix>(1);
+      weightsMatrixes.add(weightsMatrix);
+      NeuralNetwork neuralNetwork = NeuralNetworkFactory.create(weightsMatrixes);
       assertNotNull(neuralNetwork);
     } catch (Exception e) {
       fail(e.getLocalizedMessage());



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