labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1548265 - /labs/yay/trunk/core/src/main/java/org/apache/yay/core/BasicPerceptron.java
Date Thu, 05 Dec 2013 20:15:18 GMT
Author: tommaso
Date: Thu Dec  5 20:15:18 2013
New Revision: 1548265

URL: http://svn.apache.org/r1548265
Log:
make it possible to do online learning in perceptron (by single example instead of dataset)

Modified:
    labs/yay/trunk/core/src/main/java/org/apache/yay/core/BasicPerceptron.java

Modified: labs/yay/trunk/core/src/main/java/org/apache/yay/core/BasicPerceptron.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/core/BasicPerceptron.java?rev=1548265&r1=1548264&r2=1548265&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/core/BasicPerceptron.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/core/BasicPerceptron.java Thu Dec  5
20:15:18 2013
@@ -55,21 +55,25 @@ public class BasicPerceptron implements 
   @Override
   public void learn(TrainingSet<Double, Double> trainingExamples) throws LearningException
{
     for (TrainingExample<Double, Double> example : trainingExamples) {
-      Collection<Double> doubles = ConversionUtils.toValuesCollection(example.getFeatures());
-      Double[] inputs = doubles.toArray(new Double[doubles.size()]);
-      Double calculatedOutput = perceptronNeuron.elaborate(inputs);
-      int diff = calculatedOutput.compareTo(example.getOutput());
-      if (diff > 0) {
-        for (int i = 0; i < currentWeights.length; i++) {
-          currentWeights[i] += inputs[i];
-        }
-      } else if (diff < 0) {
-        for (int i = 0; i < currentWeights.length; i++) {
-          currentWeights[i] -= inputs[i];
-        }
+        learn(example);
+    }
+  }
+
+  public void learn(TrainingExample<Double, Double> example) {
+    Collection<Double> doubles = ConversionUtils.toValuesCollection(example.getFeatures());
+    Double[] inputs = doubles.toArray(new Double[doubles.size()]);
+    Double calculatedOutput = perceptronNeuron.elaborate(inputs);
+    int diff = calculatedOutput.compareTo(example.getOutput());
+    if (diff > 0) {
+      for (int i = 0; i < currentWeights.length; i++) {
+        currentWeights[i] += inputs[i];
+      }
+    } else if (diff < 0) {
+      for (int i = 0; i < currentWeights.length; i++) {
+        currentWeights[i] -= inputs[i];
       }
-      perceptronNeuron.updateWeights(currentWeights);
     }
+    perceptronNeuron.updateWeights(currentWeights);
   }
 
   @Override



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


Mime
View raw message