Author: tommaso
Date: Fri Jan 6 04:55:21 2012
New Revision: 1227953
URL: http://svn.apache.org/viewvc?rev=1227953&view=rev
Log:
moved some classes out of bio package (ActivationUnit, NeuralNetwork)
added Layer and BasicElaborationUnit classes
Added:
labs/yay/trunk/core/src/main/java/org/apache/yay/ActivationFunction.java
- copied, changed from r1222601,
labs/yay/trunk/core/src/main/java/org/apache/yay/bio/ActivationFunction.java
labs/yay/trunk/core/src/main/java/org/apache/yay/BasicElaborationUnit.java
labs/yay/trunk/core/src/main/java/org/apache/yay/Layer.java
labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetwork.java
- copied, changed from r1226813,
labs/yay/trunk/core/src/main/java/org/apache/yay/bio/NeuralNetwork.java
labs/yay/trunk/core/src/main/java/org/apache/yay/WeightsMatrix.java
- copied, changed from r1222601,
labs/yay/trunk/core/src/main/java/org/apache/yay/WeightMatrix.java
Removed:
labs/yay/trunk/core/src/main/java/org/apache/yay/WeightMatrix.java
labs/yay/trunk/core/src/main/java/org/apache/yay/bio/ActivationFunction.java
labs/yay/trunk/core/src/main/java/org/apache/yay/bio/NeuralNetwork.java
Modified:
labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetworkFactory.java
labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java
Copied:
labs/yay/trunk/core/src/main/java/org/apache/yay/ActivationFunction.java (from
r1222601,
labs/yay/trunk/core/src/main/java/org/apache/yay/bio/ActivationFunction.java)
URL:
http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/ActivationFunction.java?p2=labs/yay/trunk/core/src/main/java/org/apache/yay/ActivationFunction.java&p1=labs/yay/trunk/core/src/main/java/org/apache/yay/bio/ActivationFunction.java&r1=1222601&r2=1227953&rev=1227953&view=diff
==============================================================================
---
labs/yay/trunk/core/src/main/java/org/apache/yay/bio/ActivationFunction.java
(original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/ActivationFunction.java
Fri Jan 6 04:55:21 2012
@@ -16,7 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.yay.bio;
+package org.apache.yay;
+
+import org.apache.yay.bio.Signal;
/**
* An activation function receives a signal and generates a new signal AF : S
-> S
Added:
labs/yay/trunk/core/src/main/java/org/apache/yay/BasicElaborationUnit.java
URL:
http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/BasicElaborationUnit.java?rev=1227953&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/BasicElaborationUnit.java
(added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/BasicElaborationUnit.java
Fri Jan 6 04:55:21 2012
@@ -0,0 +1,39 @@
+/*
+ * 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.Nucleus;
+import org.apache.yay.bio.Signal;
+
+/**
+ *
+ */
+public class BasicElaborationUnit implements Nucleus {
+
+ private ActivationFunction activationFunction;
+
+ public BasicElaborationUnit(ActivationFunction activationFunction) {
+ this.activationFunction = activationFunction;
+ }
+
+ @Override
+ public Signal elaborate(Signal signal) {
+ return activationFunction.apply(signal);
+ }
+}
Added: labs/yay/trunk/core/src/main/java/org/apache/yay/Layer.java
URL:
http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/Layer.java?rev=1227953&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/Layer.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/Layer.java Fri Jan 6
04:55:21 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.Neuron;
+
+import java.util.Collection;
+
+/**
+ * A layer groups a collection of neurons placed at the same level of a neural
network
+ */
+public interface Layer {
+
+ public void add(Neuron n);
+
+ public Collection<Neuron> getNeurons();
+}
Copied: labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetwork.java
(from r1226813,
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/NeuralNetwork.java?p2=labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetwork.java&p1=labs/yay/trunk/core/src/main/java/org/apache/yay/bio/NeuralNetwork.java&r1=1226813&r2=1227953&rev=1227953&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/NeuralNetwork.java Fri Jan
6 04:55:21 2012
@@ -16,10 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.yay.bio;
+package org.apache.yay;
+
+import org.apache.yay.bio.Signal;
/**
- * A neural network is a layered connected graph of neurons
+ * A neural network is a layered connected graph of elaboration units
*/
public interface NeuralNetwork {
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=1227953&r1=1227952&r2=1227953&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
Fri Jan 6 04:55:21 2012
@@ -18,20 +18,31 @@
*/
package org.apache.yay;
-import org.apache.yay.bio.NeuralNetwork;
+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;
+
/**
*
*/
public class NeuralNetworkFactory {
- public static NeuralNetwork create(WeightMatrix weightWeightMatrix) throws
InvalidWeightMatrixException {
+ public static NeuralNetwork create(WeightsMatrix weightsMatrix) throws
InvalidWeightMatrixException {
- // TODO : implement it!
+ // TODO : validate the weights matrix
// traverse the weight matrix to create layers of neurons
- for (Long[] column : weightWeightMatrix.getColumns()) {
-
+ 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);
+ }
}
// ad bias units to each layer
Copied: labs/yay/trunk/core/src/main/java/org/apache/yay/WeightsMatrix.java
(from r1222601,
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/WeightsMatrix.java?p2=labs/yay/trunk/core/src/main/java/org/apache/yay/WeightsMatrix.java&p1=labs/yay/trunk/core/src/main/java/org/apache/yay/WeightMatrix.java&r1=1222601&r2=1227953&rev=1227953&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/WeightMatrix.java
(original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/WeightsMatrix.java Fri Jan
6 04:55:21 2012
@@ -23,7 +23,7 @@ import java.util.ArrayList;
/**
*
*/
-public class WeightMatrix {
+public class WeightsMatrix {
ArrayList<Long[]> columns = new ArrayList<Long[]>(3);
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=1227953&r1=1227952&r2=1227953&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
Fri Jan 6 04:55:21 2012
@@ -18,7 +18,6 @@
*/
package org.apache.yay;
-import org.apache.yay.bio.NeuralNetwork;
import org.junit.Test;
import java.util.ArrayList;
@@ -36,9 +35,9 @@ public class NeuralNetworkFactoryTest {
@Test
public void emptyWeightMatrixBasedCreation() {
try {
- WeightMatrix weightWeightMatrix = mock(WeightMatrix.class);
- when(weightWeightMatrix.getColumns()).thenReturn(new
ArrayList<Long[]>());
- NeuralNetworkFactory.create(weightWeightMatrix);
+ WeightsMatrix weightsMatrix = mock(WeightsMatrix.class);
+ when(weightsMatrix.getColumns()).thenReturn(new ArrayList<Long[]>());
+ NeuralNetworkFactory.create(weightsMatrix);
fail("an empty weight matrix has no meaning");
} catch (InvalidWeightMatrixException e) {
// everything ok
@@ -48,10 +47,10 @@ public class NeuralNetworkFactoryTest {
@Test
public void nullWeightMatrixBasedCreation() {
try {
- WeightMatrix weightWeightMatrix = mock(WeightMatrix.class);
- when(weightWeightMatrix.getColumns()).thenReturn(null);
- NeuralNetworkFactory.create(weightWeightMatrix);
- fail("it should fail");
+ WeightsMatrix weightsMatrix = mock(WeightsMatrix.class);
+ when(weightsMatrix.getColumns()).thenReturn(null);
+ NeuralNetworkFactory.create(weightsMatrix);
+ fail("a null weight matrix is not a valid parameter");
} catch (InvalidWeightMatrixException e) {
// everything ok
}
@@ -60,10 +59,10 @@ public class NeuralNetworkFactoryTest {
@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);
+ WeightsMatrix weightsMatrix = new WeightsMatrix();
+ weightsMatrix.addColumn(new Long[]{10l, -23l, 123l});
+ weightsMatrix.addColumn(new Long[]{12l});
+ NeuralNetwork neuralNetwork = NeuralNetworkFactory.create(weightsMatrix);
assertNotNull(neuralNetwork);
} catch (Exception e) {
fail(e.getLocalizedMessage());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]