Return-Path: X-Original-To: apmail-labs-commits-archive@minotaur.apache.org Delivered-To: apmail-labs-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F37B5100B8 for ; Thu, 5 Dec 2013 20:15:42 +0000 (UTC) Received: (qmail 35338 invoked by uid 500); 5 Dec 2013 20:15:42 -0000 Delivered-To: apmail-labs-commits-archive@labs.apache.org Received: (qmail 35227 invoked by uid 500); 5 Dec 2013 20:15:42 -0000 Mailing-List: contact commits-help@labs.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: labs@labs.apache.org Delivered-To: mailing list commits@labs.apache.org Received: (qmail 35220 invoked by uid 99); 5 Dec 2013 20:15:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Dec 2013 20:15:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Dec 2013 20:15:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A1B682388994; Thu, 5 Dec 2013 20:15:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@labs.apache.org From: tommaso@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131205201518.A1B682388994@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 trainingExamples) throws LearningException { for (TrainingExample example : trainingExamples) { - Collection 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 example) { + Collection 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