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/02/10 17:59:59 UTC
svn commit: r1242855 - in /labs/yay/trunk: ./
core/src/main/java/org/apache/yay/ core/src/test/java/org/apache/yay/
Author: tommaso
Date: Fri Feb 10 16:59:58 2012
New Revision: 1242855
URL: http://svn.apache.org/viewvc?rev=1242855&view=rev
Log:
added learning and prediction strategies to the API, removed dependencies from the bio package in the base one, changed nnfactory behavior, weightmatrix extends now an array2drealmatrix
Added:
labs/yay/trunk/core/src/main/java/org/apache/yay/CreationException.java
labs/yay/trunk/core/src/main/java/org/apache/yay/FeedForwardStrategy.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/PredictionException.java
labs/yay/trunk/core/src/main/java/org/apache/yay/PredictionStrategy.java
Removed:
labs/yay/trunk/core/src/test/java/org/apache/yay/NeuralNetworkFactoryTest.java
Modified:
labs/yay/trunk/ (props changed)
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/Example.java
labs/yay/trunk/core/src/main/java/org/apache/yay/Layer.java
labs/yay/trunk/core/src/main/java/org/apache/yay/MatrixConverter.java
labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetwork.java
labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetworkFactory.java
labs/yay/trunk/core/src/main/java/org/apache/yay/SigmoidFunction.java
labs/yay/trunk/core/src/main/java/org/apache/yay/TrainingExample.java
labs/yay/trunk/core/src/main/java/org/apache/yay/WeightsMatrix.java
Propchange: labs/yay/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Feb 10 16:59:58 2012
@@ -4,3 +4,6 @@
.project
.settings
+
+.idea
+yay-parent.iws
Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/ActivationFunction.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/ActivationFunction.java?rev=1242855&r1=1242854&r2=1242855&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/ActivationFunction.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/ActivationFunction.java Fri Feb 10 16:59:58 2012
@@ -18,13 +18,11 @@
*/
package org.apache.yay;
-import org.apache.yay.bio.Signal;
-
/**
* An activation function receives a signal and generates a new signal AF : S -> S
*/
public interface ActivationFunction<T> {
- public Signal<T> apply(Signal<T> signal);
+ public T apply(T signal);
}
Modified: 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=1242855&r1=1242854&r2=1242855&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/BasicElaborationUnit.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/BasicElaborationUnit.java Fri Feb 10 16:59:58 2012
@@ -18,22 +18,18 @@
*/
package org.apache.yay;
-import org.apache.yay.bio.Nucleus;
-import org.apache.yay.bio.Signal;
-
/**
*
*/
-public class BasicElaborationUnit implements Nucleus {
+public class BasicElaborationUnit<T> {
- private ActivationFunction activationFunction;
+ private ActivationFunction<T> activationFunction;
public BasicElaborationUnit(ActivationFunction activationFunction) {
this.activationFunction = activationFunction;
}
- @Override
- public Signal elaborate(Signal signal) {
- return activationFunction.apply(signal);
+ public T elaborate(T input) {
+ return activationFunction.apply(input);
}
}
Added: labs/yay/trunk/core/src/main/java/org/apache/yay/CreationException.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/CreationException.java?rev=1242855&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/CreationException.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/CreationException.java Fri Feb 10 16:59:58 2012
@@ -0,0 +1,27 @@
+/*
+ * 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 CreationException extends Exception {
+ public CreationException(Exception e) {
+ super(e);
+ }
+}
Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/Example.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/Example.java?rev=1242855&r1=1242854&r2=1242855&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/Example.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/Example.java Fri Feb 10 16:59:58 2012
@@ -3,7 +3,7 @@ package org.apache.yay;
import java.util.Vector;
/**
- * A sample/input characterized by its features
+ * A sample/input characterized by its features (typed with type F)
*/
public interface Example<F> {
Added: 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=1242855&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/FeedForwardStrategy.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/FeedForwardStrategy.java Fri Feb 10 16:59:58 2012
@@ -0,0 +1,90 @@
+/*
+ * 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.collections.CollectionUtils;
+import org.apache.commons.collections.Transformer;
+import org.apache.commons.math.linear.ArrayRealVector;
+import org.apache.commons.math.linear.RealMatrix;
+import org.apache.commons.math.linear.RealVector;
+
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.Vector;
+
+/**
+ * Octave code for FF 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);
+ */
+public class FeedForwardStrategy implements PredictionStrategy<Double, Double> {
+
+ private final ActivationFunction<Double> hypothesis;
+
+ private final MatrixConverter matrixConverter;
+
+ public FeedForwardStrategy(ActivationFunction<Double> hypothesis) {
+ this.hypothesis = hypothesis;
+ this.matrixConverter = new MatrixConverter();
+ }
+
+
+ @Override
+ public Double predictOutput(Vector<Double> input, Set<WeightsMatrix> weightsMatrixSet) {
+ // TODO : fix this impl as it's very slow and commons-math Java1.4 constraint is so ugly to see...
+ RealVector v = matrixConverter.toRealVector(input);
+ RealMatrix x = v.outerProduct(new ArrayRealVector(new Double[]{1d}));
+ for (WeightsMatrix weightsMatrix : weightsMatrixSet) {
+ // compute matrix multiplication
+ x = weightsMatrix.transpose().multiply(x);
+ // apply the activation function to each element in the matrix
+ for (int i = 0; i < x.getRowDimension(); i++) {
+ double[] doubles = x.getRow(i);
+ final ArrayList<Double> row = new ArrayList<Double>();
+ for (int j = 0; j < doubles.length; j++) {
+ row.set(j, doubles[j]);
+ }
+ CollectionUtils.transform(row, new RowTransformer());
+ double[] finRow = new double[row.size()];
+ for (int h = 0; h < finRow.length; h++) {
+ finRow[h] = row.get(h);
+ }
+ x.setRow(i, finRow);
+ }
+ }
+ // TODO : define a pluggable decision strategy to get the output from the last layer
+ return null;
+ }
+
+ private class RowTransformer implements Transformer {
+
+ @Override
+ public Object transform(Object input) {
+ assert input instanceof Double;
+ final Double d = (Double) input;
+ return hypothesis.apply(d);
+ }
+ }
+
+}
\ No newline at end of file
Modified: 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=1242855&r1=1242854&r2=1242855&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/Layer.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/Layer.java Fri Feb 10 16:59:58 2012
@@ -18,16 +18,14 @@
*/
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 interface Layer<T> {
- public void add(Neuron n);
+ public void add(BasicElaborationUnit<T> n);
- public Collection<Neuron> getNeurons();
+ public Collection<BasicElaborationUnit<T>> getNeurons();
}
Added: labs/yay/trunk/core/src/main/java/org/apache/yay/LearningException.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/LearningException.java?rev=1242855&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/LearningException.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/LearningException.java Fri Feb 10 16:59:58 2012
@@ -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;
+
+/**
+ */
+public class LearningException extends Exception {
+
+ public LearningException(Throwable throwable) {
+ super(throwable);
+ }
+}
Added: labs/yay/trunk/core/src/main/java/org/apache/yay/LearningStrategy.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/LearningStrategy.java?rev=1242855&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/LearningStrategy.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/LearningStrategy.java Fri Feb 10 16:59:58 2012
@@ -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.Collection;
+import java.util.Set;
+
+/**
+ *
+ */
+public interface LearningStrategy<F, O> {
+
+ public Set<WeightsMatrix> learnWeights(Set<WeightsMatrix> weightsMatrixSet, Collection<TrainingExample<F, O>>
+ trainingExamples) throws WeightLearningException;
+
+ class WeightLearningException extends Exception {
+ public WeightLearningException(Throwable throwable) {
+ super(throwable);
+ }
+ }
+}
Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/MatrixConverter.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/MatrixConverter.java?rev=1242855&r1=1242854&r2=1242855&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/MatrixConverter.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/MatrixConverter.java Fri Feb 10 16:59:58 2012
@@ -19,11 +19,15 @@
package org.apache.yay;
import org.apache.commons.math.linear.Array2DRowRealMatrix;
+import org.apache.commons.math.linear.OpenMapRealVector;
import org.apache.commons.math.linear.RealMatrix;
+import org.apache.commons.math.linear.RealVector;
import java.util.Collection;
+import java.util.Vector;
/**
+ * Temporary class for conversion between model objects and commons-math matrices/vectors
*/
public class MatrixConverter {
@@ -49,4 +53,9 @@ public class MatrixConverter {
}
return ar;
}
+
+ public RealVector toRealVector(Vector<Double> input) {
+ return new OpenMapRealVector(input.toArray(new Double[input.size()]));
+ }
+
}
Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetwork.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetwork.java?rev=1242855&r1=1242854&r2=1242855&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetwork.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetwork.java Fri Feb 10 16:59:58 2012
@@ -18,13 +18,13 @@
*/
package org.apache.yay;
-import org.apache.yay.bio.Signal;
-
/**
* A neural network is a layered connected graph of elaboration units
*/
-public interface NeuralNetwork {
+public interface NeuralNetwork<I, O> {
+
+ public void learn(TrainingExample<I,O>... trainingExamples) throws LearningException;
- public Signal predict(Signal... input);
+ public O predict(Example<I> input) throws PredictionException;
}
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=1242855&r1=1242854&r2=1242855&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 Feb 10 16:59:58 2012
@@ -18,88 +18,63 @@
*/
package org.apache.yay;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.Transformer;
-import org.apache.commons.math.linear.RealMatrix;
-import org.apache.yay.bio.Signal;
-
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
+import java.util.Vector;
/**
* Factory class for creating {@link NeuralNetwork}s
*/
public class NeuralNetworkFactory {
+ /**
+ * creates a neural network via a supervised learning method, given a training set, the initial set of layers defined
+ * by a set of matrices, the learning and prediction strategies to be used.
+ *
+ * @param trainingExamples
+ * @param weightsMatrixSet
+ * @param learningStrategy
+ * @param predictionStrategy
+ * @return
+ * @throws CreationException
+ */
+ public static NeuralNetwork<Double, Double> create(final Collection<TrainingExample<Double, Double>> trainingExamples,
+ final Set<WeightsMatrix> weightsMatrixSet, final LearningStrategy learningStrategy,
+ final PredictionStrategy<Double, Double> predictionStrategy) throws CreationException {
+ NeuralNetwork<Double, Double> neuralNetwork = new NeuralNetwork<Double, Double>() {
- public static NeuralNetwork create(final Set<RealMatrix> weightsMatrixes, final Collection<Example<Double>> samples) throws InvalidWeightMatrixException {
-
- final MatrixConverter matrixConverter = new MatrixConverter();
-
- // ad bias units to each layer
-
+ private Set<WeightsMatrix> updatedWeightsMatrixSet = weightsMatrixSet;
- // 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);
-
- */
-
- // TODO : fix this impl as it's very slow and commons-math Java1.4 compatibility introduces more complexity
-
-
- // phase 1: feedforward
- final SigmoidFunction sigmoidFunction = new SigmoidFunction();
- RealMatrix x = matrixConverter.toMatrix(samples);
- for (RealMatrix weightsMatrix : weightsMatrixes) {
- // compute matrix multiplication
- x = weightsMatrix.transpose().multiply(x);
- // apply SigmoidFunction
- for (int i = 0; i < x.getRowDimension(); i++) {
- double[] doubles = x.getRow(i);
- ArrayList<Double> row = new ArrayList<Double>();
- for (int j = 0; j < doubles.length; j++) {
- row.set(j, doubles[j]);
- }
- CollectionUtils.transform(row, new Transformer() {
- @Override
- public Object transform(Object input) {
- assert input instanceof Double;
- final Double d = (Double) input;
- return sigmoidFunction.apply(new Signal<Double>() {
- @Override
- public Double getValue() {
- return d;
- }
- });
- }
- });
- double[] finRow = new double[row.size()];
- for (int h = 0; h < finRow.length; h++) {
- finRow[h] = row.get(h);
- }
- x.setRow(i, finRow);
- }
+ public void learn(TrainingExample<Double, Double>... samples) throws LearningException {
+ try {
+ updatedWeightsMatrixSet = learningStrategy.learnWeights(weightsMatrixSet, trainingExamples);
+ } catch (Exception e) {
+ throw new LearningException(e);
}
-
- return null;
}
-
+ @Override
+ public Double predict(Example<Double> input) throws PredictionException {
+ try {
+ Vector<Double> inputVector = toVector(input.getFeatureVector());
+ return predictionStrategy.predictOutput(inputVector, weightsMatrixSet);
+ } catch (Exception e) {
+ throw new PredictionException(e);
+ }
+ }
};
-
return neuralNetwork;
}
+
+ private static Vector<Double> toVector(Vector<Feature<Double>> featureVector) {
+ // TODO : remove this and change APIs in a way that doesn't force to go through this ugly loop
+ Vector<Double> resultVector = new Vector<Double>(featureVector.size());
+ for (Feature<Double> feature : featureVector) {
+ resultVector.add(feature.getValue());
+ }
+ return resultVector;
+ }
+
}
Added: labs/yay/trunk/core/src/main/java/org/apache/yay/PredictionException.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/PredictionException.java?rev=1242855&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/PredictionException.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/PredictionException.java Fri Feb 10 16:59:58 2012
@@ -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;
+
+/**
+ */
+public class PredictionException extends Exception {
+
+ public PredictionException(Throwable throwable) {
+ super(throwable);
+ }
+
+}
Added: labs/yay/trunk/core/src/main/java/org/apache/yay/PredictionStrategy.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/PredictionStrategy.java?rev=1242855&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/PredictionStrategy.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/PredictionStrategy.java Fri Feb 10 16:59:58 2012
@@ -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.Set;
+import java.util.Vector;
+
+/**
+ */
+public interface PredictionStrategy<I, O> {
+
+ public O predictOutput(Vector<I> input, Set<WeightsMatrix> weightsMatrixSet);
+
+}
Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/SigmoidFunction.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/SigmoidFunction.java?rev=1242855&r1=1242854&r2=1242855&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/SigmoidFunction.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/SigmoidFunction.java Fri Feb 10 16:59:58 2012
@@ -1,19 +1,12 @@
package org.apache.yay;
-import org.apache.yay.bio.Signal;
-
/**
* See <a href="http://en.wikipedia.org/wiki/Sigmoid_function">here</a>.
*/
public class SigmoidFunction implements ActivationFunction<Double> {
- public Signal<Double> apply(final Signal<Double> doubleSignal) {
- return new Signal<Double>() {
- @Override
- public Double getValue() {
- return 1d / (1d + Math.exp(-1 * doubleSignal.getValue()));
- }
- };
+ public Double apply(final Double input) {
+ return 1d / (1d + Math.exp(-1 * input));
}
}
Modified: 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=1242855&r1=1242854&r2=1242855&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/TrainingExample.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/TrainingExample.java Fri Feb 10 16:59:58 2012
@@ -18,13 +18,11 @@
*/
package org.apache.yay;
-import org.apache.yay.bio.Signal;
-
/**
* A training example with input features and associated output
*/
public interface TrainingExample<F, O> extends Example {
- public Signal<O> getOutput();
+ public O getOutput();
}
Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/WeightsMatrix.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/WeightsMatrix.java?rev=1242855&r1=1242854&r2=1242855&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/WeightsMatrix.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/WeightsMatrix.java Fri Feb 10 16:59:58 2012
@@ -18,20 +18,12 @@
*/
package org.apache.yay;
-import java.util.ArrayList;
+import org.apache.commons.math.linear.Array2DRowRealMatrix;
/**
- *
+ * A matrix representing the weights applied to links between elaboration units of different adjacent {@link Layer}s in
+ * a {@link NeuralNetwork}
*/
-public class WeightsMatrix {
+public class WeightsMatrix extends Array2DRowRealMatrix {
- ArrayList<Long[]> columns = new ArrayList<Long[]>(3);
-
- public void addColumn(Long[] column) {
- columns.add(column);
- }
-
- public ArrayList<Long[]> getColumns() {
- return columns;
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org