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 2013/01/30 10:42:41 UTC

svn commit: r1440320 - in /labs/yay/trunk: ./ api/ api/src/ api/src/main/ api/src/main/java/ api/src/main/java/org/ api/src/main/java/org/apache/ api/src/main/java/org/apache/yay/ core/ core/src/main/java/org/apache/yay/ core/src/main/java/org/apache/y...

Author: tommaso
Date: Wed Jan 30 09:42:40 2013
New Revision: 1440320

URL: http://svn.apache.org/viewvc?rev=1440320&view=rev
Log:
refactoring API in a separated module

Added:
    labs/yay/trunk/api/
    labs/yay/trunk/api/pom.xml
    labs/yay/trunk/api/src/
    labs/yay/trunk/api/src/main/
    labs/yay/trunk/api/src/main/java/
    labs/yay/trunk/api/src/main/java/org/
    labs/yay/trunk/api/src/main/java/org/apache/
    labs/yay/trunk/api/src/main/java/org/apache/yay/
    labs/yay/trunk/api/src/main/java/org/apache/yay/ActivationFunction.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/BasicElaborationUnit.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/CostFunction.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/CreationException.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/Example.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/Feature.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/InvalidWeightMatrixException.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/Layer.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/LearningException.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/LearningStrategy.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/NeuralNetwork.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/PredictionException.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/PredictionStrategy.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/SelectionFunction.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/TrainingExample.java
    labs/yay/trunk/api/src/main/java/org/apache/yay/WeightLearningException.java
Removed:
    labs/yay/trunk/core/src/main/java/org/apache/yay/ActivationFunction.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/BasicElaborationUnit.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/CostFunction.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/CreationException.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/Example.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/Feature.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/InvalidWeightMatrixException.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/Layer.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/LearningException.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/LearningStrategy.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetwork.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/PredictionException.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/PredictionStrategy.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/SelectionFunction.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/TrainingExample.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/WeightLearningException.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/WeightsMatrix.java
Modified:
    labs/yay/trunk/core/pom.xml
    labs/yay/trunk/core/src/main/java/org/apache/yay/BackPropagationLearningStrategy.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/FeedForwardStrategy.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/LogisticRegressionCostFunction.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetworkFactory.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/VoidLearningStrategy.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/BinaryThresholdNeuron.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/LinearNeuron.java
    labs/yay/trunk/core/src/test/java/org/apache/yay/LogisticRegressionCostFunctionTest.java
    labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java
    labs/yay/trunk/core/src/test/java/org/apache/yay/VoidLearningStrategyTest.java
    labs/yay/trunk/pom.xml

Added: labs/yay/trunk/api/pom.xml
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/pom.xml?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/pom.xml (added)
+++ labs/yay/trunk/api/pom.xml Wed Jan 30 09:42:40 2013
@@ -0,0 +1,20 @@
+<project
+        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+        xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>yay-api</artifactId>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-math3</artifactId>
+            <version>3.0</version>
+        </dependency>
+    </dependencies>
+    <parent>
+        <groupId>org.apache.yay</groupId>
+        <artifactId>yay-parent</artifactId>
+        <version>0.1-SNAPSHOT</version>
+        <relativePath>../</relativePath>
+    </parent>
+    <name>Yay API</name>
+</project>
\ No newline at end of file

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/ActivationFunction.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/ActivationFunction.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/ActivationFunction.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/ActivationFunction.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * An activation function AF : S -> S receives a signal and generates a new signal.
+ * An activation function AF has horizontal asymptotes at 0 and 1 and a non
+ * decreasing first derivative AF' with AF and AF' both being computable.
+ *
+ */
+public interface ActivationFunction<T> {
+
+  public T apply(T signal);
+
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/BasicElaborationUnit.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/BasicElaborationUnit.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/BasicElaborationUnit.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/BasicElaborationUnit.java Wed Jan 30 09:42:40 2013
@@ -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;
+
+/**
+ * A node in a neural network
+ */
+public abstract class BasicElaborationUnit<T> {
+
+  protected ActivationFunction<T> activationFunction;
+
+  public BasicElaborationUnit(ActivationFunction<T> activationFunction) {
+    this.activationFunction = activationFunction;
+  }
+
+  public T elaborate(T... inputs) {
+    return activationFunction.apply(combine(inputs));
+  }
+
+  protected abstract T combine(T... inputs);
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/CostFunction.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/CostFunction.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/CostFunction.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/CostFunction.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,35 @@
+/*
+ * 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.Collection;
+
+/**
+ * A cost function calculates the cost of using a specified model (via its
+ * {@link ActivationFunction}) for fitting the given corpus (a {@link Collection}
+ * of {@link TrainingExample}s).
+ *
+ */
+public interface CostFunction<T, S> {
+
+  public Double calculateCost(Collection<TrainingExample<S, S>> trainingExamples,
+                              ActivationFunction<S> activationFunction,
+                              T... parameters) throws Exception;
+
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/CreationException.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/CreationException.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/CreationException.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/CreationException.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+/**
+ * Exception thrown when an error occurs while creating a neural network
+ */
+@SuppressWarnings("serial")
+public class CreationException extends Exception {
+  public CreationException(Exception e) {
+    super(e);
+  }
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/Example.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/Example.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/Example.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/Example.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+/**
+ * A sample/input characterized by its features (typed with type F)
+ */
+public interface Example<F> {
+
+  public ArrayList<Feature<F>> getFeatures();
+
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/Feature.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/Feature.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/Feature.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/Feature.java Wed Jan 30 09:42:40 2013
@@ -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;
+  }
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/InvalidWeightMatrixException.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/InvalidWeightMatrixException.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/InvalidWeightMatrixException.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/InvalidWeightMatrixException.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+/**
+ * {@link Exception} thrown when a {@link org.apache.commons.math3.linear.RealMatrix} is verified to be invalid
+ */
+@SuppressWarnings("serial")
+public class InvalidWeightMatrixException extends Exception {
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/Layer.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/Layer.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/Layer.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/Layer.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.Collection;
+
+/**
+ * A layer groups a collection of neurons placed at the same level of a neural network
+ */
+public interface Layer<T> {
+
+  public void add(BasicElaborationUnit<T> n);
+
+  public Collection<BasicElaborationUnit<T>> getNeurons();
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/LearningException.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/LearningException.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/LearningException.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/LearningException.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * Exception thrown when an error occurs while the neural network is learning its
+ * parameters
+ */
+@SuppressWarnings("serial")
+public class LearningException extends Exception {
+
+  public LearningException(Throwable throwable) {
+    super(throwable);
+  }
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/LearningStrategy.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/LearningStrategy.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/LearningStrategy.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/LearningStrategy.java Wed Jan 30 09:42:40 2013
@@ -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.commons.math3.linear.RealMatrix;
+
+import java.util.Collection;
+
+/**
+ * A {@link LearningStrategy}<F,O> defines a learning algorithm to learn the weights of the neural network's layer
+ */
+public interface LearningStrategy<F, O> {
+
+  public RealMatrix[] learnWeights(RealMatrix[] weightsMatrixSet, Collection<TrainingExample<F, O>>
+          trainingExamples) throws WeightLearningException;
+
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/NeuralNetwork.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/NeuralNetwork.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/NeuralNetwork.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/NeuralNetwork.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,30 @@
+/*
+ * 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 neural network is a layered connected graph of elaboration units
+ */
+public interface NeuralNetwork<I, O> {
+
+  public void learn(TrainingExample<I,O>... trainingExamples) throws LearningException;
+
+  public O predict(Example<I> input) throws PredictionException;
+
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/PredictionException.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/PredictionException.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/PredictionException.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/PredictionException.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+/**
+ * Exception thrown when an error occurs when a neural network is trying to 
+ * predict an output for a given input
+ */
+@SuppressWarnings("serial")
+public class PredictionException extends Exception {
+
+  public PredictionException(Throwable throwable) {
+    super(throwable);
+  }
+
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/PredictionStrategy.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/PredictionStrategy.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/PredictionStrategy.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/PredictionStrategy.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,34 @@
+/*
+ * 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.commons.math3.linear.RealMatrix;
+
+import java.util.Collection;
+
+/**
+ * A {@link PredictionStrategy} defines an algorithm for the prediction of an output of type O given an input of type I
+ */
+public interface PredictionStrategy<I, O> {
+
+  public O predictOutput(Collection<I> input, RealMatrix[] weightsMatrixSet);
+
+  public RealMatrix[] debugOutput(Collection<I> input, RealMatrix[] weightsMatrixSet);
+
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/SelectionFunction.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/SelectionFunction.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/SelectionFunction.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/SelectionFunction.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,29 @@
+/*
+ * 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 function to apply on the raw output of a {@link NeuralNetwork} in order to
+ * transform it in a more convenient format / type
+ */
+public interface SelectionFunction<N, O> {
+
+  public O selectOutput(N neuralNetworkOutput);
+
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/TrainingExample.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/TrainingExample.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/TrainingExample.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/TrainingExample.java Wed Jan 30 09:42:40 2013
@@ -0,0 +1,28 @@
+/*
+ * 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 training example with input features and associated output
+ */
+public interface TrainingExample<F, O> extends Example<F> {
+
+  public O getOutput();
+
+}

Added: labs/yay/trunk/api/src/main/java/org/apache/yay/WeightLearningException.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/api/src/main/java/org/apache/yay/WeightLearningException.java?rev=1440320&view=auto
==============================================================================
--- labs/yay/trunk/api/src/main/java/org/apache/yay/WeightLearningException.java (added)
+++ labs/yay/trunk/api/src/main/java/org/apache/yay/WeightLearningException.java Wed Jan 30 09:42:40 2013
@@ -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;
+
+/**
+ * Exception raised when something goes wrong during the learning algorithm execution
+ */
+@SuppressWarnings("serial")
+public class WeightLearningException extends Exception {
+  public WeightLearningException(Throwable throwable) {
+    super(throwable);
+  }
+
+  public WeightLearningException(String s, Exception e) {
+    super(s, e);
+  }
+}

Modified: labs/yay/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/pom.xml?rev=1440320&r1=1440319&r2=1440320&view=diff
==============================================================================
--- labs/yay/trunk/core/pom.xml (original)
+++ labs/yay/trunk/core/pom.xml Wed Jan 30 09:42:40 2013
@@ -12,6 +12,11 @@
     <name>Yay core</name>
     <dependencies>
         <dependency>
+            <groupId>org.apache.yay</groupId>
+            <artifactId>yay-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
             <version>1.9.5</version>

Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/BackPropagationLearningStrategy.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/BackPropagationLearningStrategy.java?rev=1440320&r1=1440319&r2=1440320&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/BackPropagationLearningStrategy.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/BackPropagationLearningStrategy.java Wed Jan 30 09:42:40 2013
@@ -18,14 +18,14 @@
  */
 package org.apache.yay;
 
-import java.util.Collection;
-
 import org.apache.commons.math3.linear.Array2DRowRealMatrix;
 import org.apache.commons.math3.linear.ArrayRealVector;
 import org.apache.commons.math3.linear.RealMatrix;
 import org.apache.commons.math3.linear.RealVector;
 import org.apache.yay.utils.ConversionUtils;
 
+import java.util.Collection;
+
 /**
  * Back propagation learning algorithm for neural networks implementation (see
  * <code>http://en.wikipedia.org/wiki/Backpropagation</code>).
@@ -33,15 +33,15 @@ import org.apache.yay.utils.ConversionUt
 public class BackPropagationLearningStrategy implements LearningStrategy<Double, Double[]> {
 
   private final PredictionStrategy<Double, Double[]> predictionStrategy;
-  private CostFunction<WeightsMatrix, Double> costFunction;
+  private CostFunction<RealMatrix, Double> costFunction;
 
-  public BackPropagationLearningStrategy(PredictionStrategy<Double, Double[]> predictionStrategy, CostFunction<WeightsMatrix, Double> costFunction) {
+  public BackPropagationLearningStrategy(PredictionStrategy<Double, Double[]> predictionStrategy, CostFunction<RealMatrix, Double> costFunction) {
     this.predictionStrategy = predictionStrategy;
     this.costFunction = costFunction;
   }
 
   @Override
-  public WeightsMatrix[] learnWeights(WeightsMatrix[] weightsMatrixSet, Collection<TrainingExample<Double, Double[]>> trainingExamples) throws WeightLearningException {
+  public RealMatrix[] learnWeights(RealMatrix[] weightsMatrixSet, Collection<TrainingExample<Double, Double[]>> trainingExamples) throws WeightLearningException {
     // set up the accumulator matrix(es)
     RealMatrix[] triangle = new RealMatrix[weightsMatrixSet.length];
     for (TrainingExample<Double, Double[]> trainingExample : trainingExamples) {
@@ -65,7 +65,7 @@ public class BackPropagationLearningStra
         // back prop the error and update the activationErrors accordingly
         // TODO : remove the bias term from the error calculations
         for (int l = weightsMatrixSet.length - 2; l >= 0; l--) {
-          WeightsMatrix thetaL = weightsMatrixSet[l];
+          RealMatrix thetaL = weightsMatrixSet[l];
           ArrayRealVector activationsVector = new ArrayRealVector(activations[l].getRowVector(0)); // get l-th nn layer activations
           ArrayRealVector identity = new ArrayRealVector(activationsVector.getDimension(), 1d);
           RealVector gz = activationsVector.ebeMultiply(identity.subtract(activationsVector)); // = a^l .* (1-a^l)

Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/FeedForwardStrategy.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/FeedForwardStrategy.java?rev=1440320&r1=1440319&r2=1440320&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/FeedForwardStrategy.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/FeedForwardStrategy.java Wed Jan 30 09:42:40 2013
@@ -19,12 +19,6 @@
 
 package org.apache.yay;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Vector;
-
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.Transformer;
 import org.apache.commons.lang3.ArrayUtils;
@@ -33,6 +27,11 @@ import org.apache.commons.math3.linear.R
 import org.apache.commons.math3.linear.RealVector;
 import org.apache.yay.utils.ConversionUtils;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
 /**
  * Octave code for FF to be converted :
  * m = size(X, 1);
@@ -51,27 +50,27 @@ public class FeedForwardStrategy impleme
   }
 
   @Override
-  public Double predictOutput(Collection<Double> input, WeightsMatrix[] weightsMatrixSet) {
-    RealMatrix[] realMatrixes = applyFF(input, weightsMatrixSet);
+  public Double predictOutput(Collection<Double> input, RealMatrix[] RealMatrixSet) {
+    RealMatrix[] realMatrixes = applyFF(input, RealMatrixSet);
     RealMatrix x = realMatrixes[realMatrixes.length - 1];
     double[] lastColumn = x.getColumn(x.getColumnDimension() - 1);
     return Collections.max(Arrays.asList(ArrayUtils.toObject(lastColumn)));
   }
 
-  public RealMatrix[] debugOutput(Collection<Double> input, WeightsMatrix[] weightsMatrixSet) {
-    return applyFF(input, weightsMatrixSet);
+  public RealMatrix[] debugOutput(Collection<Double> input, RealMatrix[] RealMatrixSet) {
+    return applyFF(input, RealMatrixSet);
   }
 
-  private RealMatrix[] applyFF(Collection<Double> input, WeightsMatrix[] weightsMatrixSet) {
-    RealMatrix[] debugOutput = new RealMatrix[weightsMatrixSet.length];
+  private RealMatrix[] applyFF(Collection<Double> input, RealMatrix[] RealMatrixSet) {
+    RealMatrix[] debugOutput = new RealMatrix[RealMatrixSet.length];
 
     // TODO : fix this impl as it's very slow
     RealVector v = ConversionUtils.toRealVector(input);
     RealMatrix x = v.outerProduct(new ArrayRealVector(new Double[]{1d})).transpose(); // a 1xN matrix
-    for (int w = 0; w < weightsMatrixSet.length; w++) {
-      WeightsMatrix weightsMatrix = weightsMatrixSet[w];
+    for (int w = 0; w < RealMatrixSet.length; w++) {
+      RealMatrix RealMatrix = RealMatrixSet[w];
       // compute matrix multiplication
-      x = x.multiply(weightsMatrix.transpose());
+      x = x.multiply(RealMatrix.transpose());
 
       // apply the activation function to each element in the matrix
       for (int i = 0; i < x.getRowDimension(); i++) {

Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/LogisticRegressionCostFunction.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/LogisticRegressionCostFunction.java?rev=1440320&r1=1440319&r2=1440320&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/LogisticRegressionCostFunction.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/LogisticRegressionCostFunction.java Wed Jan 30 09:42:40 2013
@@ -18,12 +18,14 @@
  */
 package org.apache.yay;
 
+import org.apache.commons.math3.linear.RealMatrix;
+
 import java.util.Collection;
 
 /**
  * This calculates the logistic regression cost function for neural networks
  */
-public class LogisticRegressionCostFunction implements CostFunction<WeightsMatrix, Double> {
+public class LogisticRegressionCostFunction implements CostFunction<RealMatrix, Double> {
 
   private final Double lambda;
 
@@ -33,17 +35,17 @@ public class LogisticRegressionCostFunct
 
   @Override
   public Double calculateCost(Collection<TrainingExample<Double, Double>> trainingExamples,
-          ActivationFunction<Double> hypothesis, WeightsMatrix... parameters) throws Exception {
+          ActivationFunction<Double> hypothesis, RealMatrix... parameters) throws Exception {
 
     Double errorTerm = calculateErrorTerm(parameters, hypothesis, trainingExamples);
     Double regularizationTerm = calculateRegularizationTerm(parameters, trainingExamples);
     return errorTerm + regularizationTerm;
   }
 
-  private Double calculateRegularizationTerm(WeightsMatrix[] parameters,
+  private Double calculateRegularizationTerm(RealMatrix[] parameters,
           Collection<TrainingExample<Double, Double>> trainingExamples) {
     Double res = 1d;
-    for (WeightsMatrix layerMatrix : parameters) {
+    for (RealMatrix layerMatrix : parameters) {
       for (int i = 0; i < layerMatrix.getColumnDimension(); i++) {
         double[] column = layerMatrix.getColumn(i);
         // starting from 1 to avoid including the bias unit in regularization
@@ -55,7 +57,7 @@ public class LogisticRegressionCostFunct
     return (lambda / (2d * trainingExamples.size())) * res;
   }
 
-  private Double calculateErrorTerm(WeightsMatrix[] parameters,
+  private Double calculateErrorTerm(RealMatrix[] parameters,
           ActivationFunction<Double> hypothesis,
           Collection<TrainingExample<Double, Double>> trainingExamples) throws PredictionException,
           CreationException {

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=1440320&r1=1440319&r2=1440320&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 Wed Jan 30 09:42:40 2013
@@ -18,11 +18,11 @@
  */
 package org.apache.yay;
 
-import java.util.Collection;
-import java.util.Vector;
-
+import org.apache.commons.math3.linear.RealMatrix;
 import org.apache.yay.utils.ConversionUtils;
 
+import java.util.Collection;
+
 /**
  * Factory class for creating {@link NeuralNetwork}s
  */
@@ -33,23 +33,23 @@ public class NeuralNetworkFactory {
    * by a set of matrices, the learning and prediction strategies to be used.
    *
    * @param trainingExamples   the training set
-   * @param weightsMatrixSet   the initial settings for weights matrices
+   * @param RealMatrixSet   the initial settings for weights matrices
    * @param learningStrategy   a learning strategy
    * @param predictionStrategy a prediction strategy
    * @return a NeuralNetwork instance
    * @throws CreationException
    */
   public static NeuralNetwork<Double, Double> create(final Collection<TrainingExample<Double, Double>> trainingExamples,
-                                                     final WeightsMatrix[] weightsMatrixSet, final LearningStrategy<Double, Double> learningStrategy,
+                                                     final RealMatrix[] RealMatrixSet, final LearningStrategy<Double, Double> learningStrategy,
                                                      final PredictionStrategy<Double, Double> predictionStrategy) {
     return new NeuralNetwork<Double, Double>() {
 
-      private WeightsMatrix[] updatedWeightsMatrixSet = weightsMatrixSet;
+      private RealMatrix[] updatedRealMatrixSet = RealMatrixSet;
 
       @Override
       public void learn(TrainingExample<Double, Double>... samples) throws LearningException {
         try {
-          updatedWeightsMatrixSet = learningStrategy.learnWeights(weightsMatrixSet, trainingExamples);
+          updatedRealMatrixSet = learningStrategy.learnWeights(RealMatrixSet, trainingExamples);
         } catch (WeightLearningException e) {
           throw new LearningException(e);
         }
@@ -59,7 +59,7 @@ public class NeuralNetworkFactory {
       public Double predict(Example<Double> input) throws PredictionException {
         try {
           Collection<Double> inputVector = ConversionUtils.toValuesCollection(input.getFeatures());
-          return predictionStrategy.predictOutput(inputVector, updatedWeightsMatrixSet);
+          return predictionStrategy.predictOutput(inputVector, updatedRealMatrixSet);
         } catch (Exception e) {
           throw new PredictionException(e);
         }

Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/VoidLearningStrategy.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/VoidLearningStrategy.java?rev=1440320&r1=1440319&r2=1440320&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/VoidLearningStrategy.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/VoidLearningStrategy.java Wed Jan 30 09:42:40 2013
@@ -18,6 +18,8 @@
  */
 package org.apache.yay;
 
+import org.apache.commons.math3.linear.RealMatrix;
+
 import java.util.Collection;
 
 /**
@@ -26,7 +28,7 @@ import java.util.Collection;
 public class VoidLearningStrategy<F, O> implements LearningStrategy<F, O> {
 
   @Override
-  public WeightsMatrix[] learnWeights(WeightsMatrix[] weightsMatrixSet, Collection<TrainingExample<F, O>> trainingExamples) throws WeightLearningException {
+  public RealMatrix[] learnWeights(RealMatrix[] weightsMatrixSet, Collection<TrainingExample<F, O>> trainingExamples) throws WeightLearningException {
     return weightsMatrixSet;
   }
 }

Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/BinaryThresholdNeuron.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/BinaryThresholdNeuron.java?rev=1440320&r1=1440319&r2=1440320&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/BinaryThresholdNeuron.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/BinaryThresholdNeuron.java Wed Jan 30 09:42:40 2013
@@ -33,7 +33,7 @@ public class BinaryThresholdNeuron exten
   private double[] weights;
 
   public BinaryThresholdNeuron(double threshold, double... weights) {
-    this.activationFunction = new StepActivationFunction(threshold);
+    super(new StepActivationFunction(threshold));
     this.weights = weights;
   }
 

Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/LinearNeuron.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/LinearNeuron.java?rev=1440320&r1=1440319&r2=1440320&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/LinearNeuron.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/LinearNeuron.java Wed Jan 30 09:42:40 2013
@@ -31,7 +31,7 @@ public class LinearNeuron extends BasicE
   private final Double bias;
 
   public LinearNeuron(Double bias, double... weights) {
-    this.activationFunction = new IdentityActivationFunction<Double>();
+    super(new IdentityActivationFunction<Double>());
     this.bias = bias;
     this.weights = weights;
   }

Modified: labs/yay/trunk/core/src/test/java/org/apache/yay/LogisticRegressionCostFunctionTest.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/test/java/org/apache/yay/LogisticRegressionCostFunctionTest.java?rev=1440320&r1=1440319&r2=1440320&view=diff
==============================================================================
--- labs/yay/trunk/core/src/test/java/org/apache/yay/LogisticRegressionCostFunctionTest.java (original)
+++ labs/yay/trunk/core/src/test/java/org/apache/yay/LogisticRegressionCostFunctionTest.java Wed Jan 30 09:42:40 2013
@@ -18,12 +18,14 @@
  */
 package org.apache.yay;
 
-import java.util.Collection;
-import java.util.LinkedList;
-
+import org.apache.commons.math3.linear.Array2DRowRealMatrix;
+import org.apache.commons.math3.linear.RealMatrix;
 import org.apache.yay.utils.ExamplesFactory;
 import org.junit.Test;
 
+import java.util.Collection;
+import java.util.LinkedList;
+
 import static org.junit.Assert.assertTrue;
 
 /**
@@ -33,7 +35,7 @@ public class LogisticRegressionCostFunct
 
   @Test
   public void testORParametersCost() throws Exception {
-    CostFunction<WeightsMatrix, Double> costFunction = new LogisticRegressionCostFunction(0.1d);
+    CostFunction<RealMatrix, Double> costFunction = new LogisticRegressionCostFunction(0.1d);
     Collection<TrainingExample<Double, Double>> trainingExamples = new LinkedList<TrainingExample<Double, Double>>();
     TrainingExample<Double, Double> example1 = ExamplesFactory.createDoubleTrainingExample(1d, 0d, 1d);
     TrainingExample<Double, Double> example2 = ExamplesFactory.createDoubleTrainingExample(1d, 1d, 1d);
@@ -44,8 +46,8 @@ public class LogisticRegressionCostFunct
     trainingExamples.add(example3);
     trainingExamples.add(example4);
     double[][] weights = { { -10d, 20d, 20d } };
-    WeightsMatrix singleOrLayerWeights = new WeightsMatrix(weights);
-    WeightsMatrix[] orWeightsMatrixSet = new WeightsMatrix[] { singleOrLayerWeights };
+    RealMatrix singleOrLayerWeights = new Array2DRowRealMatrix(weights);
+    RealMatrix[] orWeightsMatrixSet = new RealMatrix[] { singleOrLayerWeights };
     Double cost = costFunction.calculateCost(trainingExamples, new SigmoidFunction(),
             orWeightsMatrixSet);
     assertTrue("cost should not be negative", cost > 0d);

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=1440320&r1=1440319&r2=1440320&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 Wed Jan 30 09:42:40 2013
@@ -18,11 +18,12 @@
  */
 package org.apache.yay;
 
+import org.apache.commons.math3.linear.Array2DRowRealMatrix;
+import org.apache.commons.math3.linear.RealMatrix;
 import org.junit.Test;
 
 import java.util.ArrayList;
 import java.util.LinkedList;
-import java.util.Vector;
 
 import static org.junit.Assert.assertEquals;
 
@@ -34,9 +35,9 @@ public class NeuralNetworkFactoryTest {
   @Test
   public void andNNCreationTest() throws Exception {
     double[][] weights = {{-30d, 20d, 20d}};
-    WeightsMatrix singleAndLayerWeights = new WeightsMatrix(weights);
-    WeightsMatrix[] andWeightsMatrixSet = new WeightsMatrix[]{singleAndLayerWeights};
-    NeuralNetwork<Double,Double> andNN = createFFNN(andWeightsMatrixSet);
+    RealMatrix singleAndLayerWeights = new Array2DRowRealMatrix(weights);
+    RealMatrix[] andRealMatrixSet = new RealMatrix[]{singleAndLayerWeights};
+    NeuralNetwork<Double,Double> andNN = createFFNN(andRealMatrixSet);
     assertEquals(0l, Math.round(andNN.predict(createSample(1d, 0d))));
     assertEquals(0l, Math.round(andNN.predict(createSample(0d, 1d))));
     assertEquals(0l, Math.round(andNN.predict(createSample(0d, 0d))));
@@ -46,9 +47,9 @@ public class NeuralNetworkFactoryTest {
   @Test
   public void orNNCreationTest() throws Exception {
     double[][] weights = {{-10d, 20d, 20d}};
-    WeightsMatrix singleOrLayerWeights = new WeightsMatrix(weights);
-    WeightsMatrix[] orWeightsMatrixSet = new WeightsMatrix[]{singleOrLayerWeights};
-    NeuralNetwork<Double,Double> orNN = createFFNN(orWeightsMatrixSet);
+    RealMatrix singleOrLayerWeights = new Array2DRowRealMatrix(weights);
+    RealMatrix[] orRealMatrixSet = new RealMatrix[]{singleOrLayerWeights};
+    NeuralNetwork<Double,Double> orNN = createFFNN(orRealMatrixSet);
     assertEquals(1l, Math.round(orNN.predict(createSample(1d, 0d))));
     assertEquals(1l, Math.round(orNN.predict(createSample(0d, 1d))));
     assertEquals(0l, Math.round(orNN.predict(createSample(0d, 0d))));
@@ -58,19 +59,19 @@ public class NeuralNetworkFactoryTest {
   @Test
   public void notNNCreationTest() throws Exception {
     double[][] weights = {{10d, -20d}};
-    WeightsMatrix singleNotLayerWeights = new WeightsMatrix(weights);
-    WeightsMatrix[] notWeightsMatrixSet = new WeightsMatrix[]{singleNotLayerWeights};
-    NeuralNetwork<Double,Double> orNN = createFFNN(notWeightsMatrixSet);
+    RealMatrix singleNotLayerWeights = new Array2DRowRealMatrix(weights);
+    RealMatrix[] notRealMatrixSet = new RealMatrix[]{singleNotLayerWeights};
+    NeuralNetwork<Double,Double> orNN = createFFNN(notRealMatrixSet);
     assertEquals(1l, Math.round(orNN.predict(createSample(0d))));
     assertEquals(0l, Math.round(orNN.predict(createSample(1d))));
   }
 
   @Test
   public void norNNCreationTest() throws Exception {
-    WeightsMatrix firstNorLayerWeights = new WeightsMatrix(new double[][]{{0, 0, 0},{-30d, 20d, 20d}, {10d, -20d, -20d}});
-    WeightsMatrix secondNorLayerWeights = new WeightsMatrix(new double[][]{{-10d, 20d, 20d}});
-    WeightsMatrix[] norWeightsMatrixSet = new WeightsMatrix[]{firstNorLayerWeights,secondNorLayerWeights};
-    NeuralNetwork<Double,Double> norNN = createFFNN(norWeightsMatrixSet);
+    RealMatrix firstNorLayerWeights = new Array2DRowRealMatrix(new double[][]{{0, 0, 0},{-30d, 20d, 20d}, {10d, -20d, -20d}});
+    RealMatrix secondNorLayerWeights = new Array2DRowRealMatrix(new double[][]{{-10d, 20d, 20d}});
+    RealMatrix[] norRealMatrixSet = new RealMatrix[]{firstNorLayerWeights,secondNorLayerWeights};
+    NeuralNetwork<Double,Double> norNN = createFFNN(norRealMatrixSet);
     assertEquals(0l, Math.round(norNN.predict(createSample(1d, 0d))));
     assertEquals(0l, Math.round(norNN.predict(createSample(0d, 1d))));
     assertEquals(1l, Math.round(norNN.predict(createSample(0d, 0d))));
@@ -79,19 +80,19 @@ public class NeuralNetworkFactoryTest {
 
   @Test
   public void sampleCreationTest() throws Exception {
-    WeightsMatrix firstLayer = new WeightsMatrix(new double[][]{{1d, 1d, 2d, 3d},{1d, 1d, 2d, 3d}, {1d, 1d, 2d, 3d}});
-    WeightsMatrix secondLayer = new WeightsMatrix(new double[][]{{1d, 2d, 3d}});
-    WeightsMatrix[] weightsMatrixes = new WeightsMatrix[]{firstLayer,secondLayer};
-    NeuralNetwork<Double,Double> neuralNetwork = createFFNN(weightsMatrixes);
+    RealMatrix firstLayer = new Array2DRowRealMatrix(new double[][]{{1d, 1d, 2d, 3d},{1d, 1d, 2d, 3d}, {1d, 1d, 2d, 3d}});
+    RealMatrix secondLayer = new Array2DRowRealMatrix(new double[][]{{1d, 2d, 3d}});
+    RealMatrix[] RealMatrixes = new RealMatrix[]{firstLayer,secondLayer};
+    NeuralNetwork<Double,Double> neuralNetwork = createFFNN(RealMatrixes);
     Double prdictedValue = neuralNetwork.predict(createSample(5d, 6d, 7d));
     assertEquals(1l, Math.round(prdictedValue));
     assertEquals(Double.valueOf(0.9975273768433653d), prdictedValue);
   }
 
-  private NeuralNetwork<Double, Double> createFFNN(WeightsMatrix[] andWeightsMatrixSet)
+  private NeuralNetwork<Double, Double> createFFNN(RealMatrix[] andRealMatrixSet)
           throws CreationException {
     return NeuralNetworkFactory.create(new LinkedList<TrainingExample<Double, Double>>(), 
-            andWeightsMatrixSet, new VoidLearningStrategy<Double, Double>(), 
+            andRealMatrixSet, new VoidLearningStrategy<Double, Double>(), 
             new FeedForwardStrategy(new SigmoidFunction()));
   }
 

Modified: labs/yay/trunk/core/src/test/java/org/apache/yay/VoidLearningStrategyTest.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/test/java/org/apache/yay/VoidLearningStrategyTest.java?rev=1440320&r1=1440319&r2=1440320&view=diff
==============================================================================
--- labs/yay/trunk/core/src/test/java/org/apache/yay/VoidLearningStrategyTest.java (original)
+++ labs/yay/trunk/core/src/test/java/org/apache/yay/VoidLearningStrategyTest.java Wed Jan 30 09:42:40 2013
@@ -18,12 +18,14 @@
  */
 package org.apache.yay;
 
+import org.apache.commons.math3.linear.Array2DRowRealMatrix;
+import org.apache.commons.math3.linear.RealMatrix;
+import org.junit.Test;
+
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.LinkedList;
 
-import org.junit.Test;
-
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
@@ -36,10 +38,10 @@ public class VoidLearningStrategyTest {
   public void testNoLearning() throws Exception {
     VoidLearningStrategy<String, String> learningStrategy = new VoidLearningStrategy<String, String>();
     Collection<TrainingExample<String, String>> trainingExamples = new LinkedList<TrainingExample<String, String>>();
-    WeightsMatrix[] weightsMatrixSet = new WeightsMatrix[1];
+    RealMatrix[] weightsMatrixSet = new RealMatrix[1];
     double[][] weights = { { 1d, 2d, }, { 2d, 4d } };
-    weightsMatrixSet[0] = new WeightsMatrix(weights);
-    WeightsMatrix[] learnedWeights = learningStrategy.learnWeights(weightsMatrixSet,
+    weightsMatrixSet[0] = new Array2DRowRealMatrix(weights);
+    RealMatrix[] learnedWeights = learningStrategy.learnWeights(weightsMatrixSet,
             trainingExamples);
     assertNotNull(learnedWeights);
     assertTrue(Arrays.equals(learnedWeights, weightsMatrixSet));

Modified: labs/yay/trunk/pom.xml
URL: http://svn.apache.org/viewvc/labs/yay/trunk/pom.xml?rev=1440320&r1=1440319&r2=1440320&view=diff
==============================================================================
--- labs/yay/trunk/pom.xml (original)
+++ labs/yay/trunk/pom.xml Wed Jan 30 09:42:40 2013
@@ -53,8 +53,8 @@
       <id>tommaso</id>
       <name>Tommaso Teofili</name>
       <email>tommaso at apache dot org</email>
-      <organization>Sourcesense S.r.l.</organization>
-      <organizationUrl>http://www.sourcesense.com/</organizationUrl>
+      <organization>Adobe Systems</organization>
+      <organizationUrl>http://www.adobe.com/</organizationUrl>
       <roles>
         <role>Committer</role>
       </roles>
@@ -197,6 +197,7 @@
     </resources>
   </build>
   <modules>
+    <module>api</module>
     <module>core</module>
     <module>bio</module>
   </modules>



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