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 2011/12/23 08:54:32 UTC

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

Author: tommaso
Date: Fri Dec 23 07:54:31 2011
New Revision: 1222600

URL: http://svn.apache.org/viewvc?rev=1222600&view=rev
Log:
start implementing the NN build API

Added:
    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/main/java/org/apache/yay/WeightMatrix.java
    labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java
Removed:
    labs/yay/trunk/core/src/test/java/org/apache/yay/ForwardPropagationTest.java
Modified:
    labs/yay/trunk/core/pom.xml
    labs/yay/trunk/core/src/main/java/org/apache/yay/bio/NeuralNetwork.java

Modified: labs/yay/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/pom.xml?rev=1222600&r1=1222599&r2=1222600&view=diff
==============================================================================
--- labs/yay/trunk/core/pom.xml (original)
+++ labs/yay/trunk/core/pom.xml Fri Dec 23 07:54:31 2011
@@ -11,4 +11,12 @@
     <relativePath>../</relativePath>
   </parent>
   <name>Yay core</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <version>1.9.0-rc1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
 </project>
\ No newline at end of file

Added: 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=1222600&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/InvalidWeightMatrixException.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/InvalidWeightMatrixException.java Fri Dec 23 07:54:31 2011
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+/**
+ *
+ */
+public class InvalidWeightMatrixException extends Exception {
+}

Added: 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=1222600&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetworkFactory.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetworkFactory.java Fri Dec 23 07:54:31 2011
@@ -0,0 +1,50 @@
+/*
+ * 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.NeuralNetwork;
+import org.apache.yay.bio.Signal;
+
+/**
+ *
+ */
+public class NeuralNetworkFactory {
+  public static NeuralNetwork create(WeightMatrix weightWeightMatrix) throws InvalidWeightMatrixException {
+
+    // TODO : implement it!
+
+    // traverse the weight matrix to create layers of neurons
+    for (Long[] column : weightWeightMatrix.getColumns()) {
+
+    }
+
+    // ad bias units to each layer
+
+    // return the NN
+    NeuralNetwork neuralNetwork = new NeuralNetwork() {
+      @Override
+      public Signal predict(Signal... input) {
+        return null;
+      }
+    };
+
+
+    return neuralNetwork;
+  }
+}

Added: labs/yay/trunk/core/src/main/java/org/apache/yay/WeightMatrix.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/WeightMatrix.java?rev=1222600&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/WeightMatrix.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/WeightMatrix.java Fri Dec 23 07:54:31 2011
@@ -0,0 +1,37 @@
+/*
+ * 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 java.util.ArrayList;
+
+/**
+ *
+ */
+public class WeightMatrix {
+
+  ArrayList<Long[]> columns = new ArrayList<Long[]>(3);
+
+  public void addColumn(Long[] column) {
+    columns.add(column);
+  }
+
+  public ArrayList<Long[]> getColumns() {
+    return columns;
+  }
+}

Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/bio/NeuralNetwork.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/bio/NeuralNetwork.java?rev=1222600&r1=1222599&r2=1222600&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/bio/NeuralNetwork.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/bio/NeuralNetwork.java Fri Dec 23 07:54:31 2011
@@ -23,6 +23,6 @@ package org.apache.yay.bio;
  */
 public interface NeuralNetwork {
 
-  Signal predict(Signal... input);
+  public Signal predict(Signal... input);
 
 }

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=1222600&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 Fri Dec 23 07:54:31 2011
@@ -0,0 +1,81 @@
+/*
+ * 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.NeuralNetwork;
+import org.junit.Test;
+
+import java.util.ArrayList;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ *
+ */
+public class NeuralNetworkFactoryTest {
+
+  @Test
+  public void emptyWeightMatrixBasedCreation() {
+    try {
+      WeightMatrix weightWeightMatrix = mock(WeightMatrix.class);
+      when(weightWeightMatrix.getColumns()).thenReturn(new ArrayList<Long[]>());
+      NeuralNetworkFactory.create(weightWeightMatrix);
+      fail("an empty weight matrix has no meaning");
+    } catch (InvalidWeightMatrixException e) {
+      // everything ok
+    }
+  }
+
+  @Test
+  public void nullWeightMatrixBasedCreation() {
+    try {
+      WeightMatrix weightWeightMatrix = mock(WeightMatrix.class);
+      when(weightWeightMatrix.getColumns()).thenReturn(null);
+      NeuralNetworkFactory.create(weightWeightMatrix);
+      fail("it should fail");
+    } catch (InvalidWeightMatrixException e) {
+      // everything ok
+    }
+  }
+
+  @Test
+  public void weightMatrixBasedCreation() {
+    try {
+      WeightMatrix weightWeightMatrix = new WeightMatrix();
+      weightWeightMatrix.addColumn(new Long[]{10l, -23l, 123l});
+      weightWeightMatrix.addColumn(new Long[]{12l});
+      NeuralNetwork neuralNetwork = NeuralNetworkFactory.create(weightWeightMatrix);
+      assertNotNull(neuralNetwork);
+    } catch (Exception e) {
+      fail(e.getLocalizedMessage());
+    }
+  }
+
+  @Test
+  public void explicitBuilderBasedCreation() {
+    try {
+//      NeuralNetworkFactory.create().newLayer().addBias().withWeight(-30).addUnit().withWeight(10).addUnit().withWeight(20);
+    } 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