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/05/06 23:24:40 UTC

svn commit: r1334783 - /labs/yay/trunk/core/src/main/java/org/apache/yay/BackPropagationLearningStrategy.java

Author: tommaso
Date: Sun May  6 21:24:39 2012
New Revision: 1334783

URL: http://svn.apache.org/viewvc?rev=1334783&view=rev
Log:
started sketching up the back propagation algorithm for learning

Added:
    labs/yay/trunk/core/src/main/java/org/apache/yay/BackPropagationLearningStrategy.java

Added: 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=1334783&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/BackPropagationLearningStrategy.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/BackPropagationLearningStrategy.java Sun May  6 21:24:39 2012
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.yay;
+
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * Backpropagation learning algorithm for neural networks implementation (see http://en.wikipedia.org/wiki/Backpropagation).
+ */
+public class BackPropagationLearningStrategy implements LearningStrategy<Long, Long> {
+
+  private NeuralNetwork<Long, Long> neuralNetwork;
+
+  public BackPropagationLearningStrategy(NeuralNetwork neuralNetwork) {
+    this.neuralNetwork = neuralNetwork;
+  }
+
+  @Override
+  public Set<WeightsMatrix> learnWeights(Set<WeightsMatrix> weightsMatrixSet, Collection<TrainingExample<Long, Long>> trainingExamples) throws WeightLearningException {
+    for (TrainingExample<Long, Long> trainingExample : trainingExamples) {
+      try {
+        Long output = neuralNetwork.predict(trainingExample);
+        Long learnedOutput = trainingExample.getOutput();
+        Long error = learnedOutput - output;
+        // TODO : back prop the error and update the weights accordingly
+
+      } catch (PredictionException e) {
+        throw new WeightLearningException("error during phase 1 of backpropagation algorithm", e);
+      }
+    }
+    return null;
+  }
+}



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