labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1239882 - in /labs/yay/trunk/core/src/main/java/org/apache/yay: Example.java MatrixConverter.java NeuralNetworkFactory.java TrainingExample.java
Date Thu, 02 Feb 2012 22:15:39 GMT
Author: tommaso
Date: Thu Feb  2 22:15:38 2012
New Revision: 1239882

URL: http://svn.apache.org/viewvc?rev=1239882&view=rev
Log:
introduced Example class and made the TrainingExample extend it
NNFactory main method signature fixed with Example
MatrixConverter methods apply to Examples now

Added:
    labs/yay/trunk/core/src/main/java/org/apache/yay/Example.java
Modified:
    labs/yay/trunk/core/src/main/java/org/apache/yay/MatrixConverter.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/NeuralNetworkFactory.java
    labs/yay/trunk/core/src/main/java/org/apache/yay/TrainingExample.java

Added: 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=1239882&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/Example.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/Example.java Thu Feb  2 22:15:38 2012
@@ -0,0 +1,12 @@
+package org.apache.yay;
+
+import java.util.Vector;
+
+/**
+ * A sample/input characterized by its features
+ */
+public interface Example<F> {
+
+  public Vector<Feature<F>> getFeatureVector();
+
+}

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=1239882&r1=1239881&r2=1239882&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 Thu Feb  2 22:15:38
2012
@@ -27,11 +27,11 @@ import java.util.Collection;
  */
 public class MatrixConverter {
 
-  public RealMatrix toMatrix(Collection<TrainingExample<Double, Double>> trainingSet)
{
+  public RealMatrix toMatrix(Collection<Example<Double>> trainingSet) {
     double[][] matrixData = new double[trainingSet.size()][];
 
     int i = 0;
-    for (TrainingExample<Double, Double> sample : trainingSet) {
+    for (Example<Double> sample : trainingSet) {
       double[] sampleRow = toDoubleArray(sample);
       matrixData[i] = sampleRow;
       i++;
@@ -40,14 +40,13 @@ public class MatrixConverter {
     return new Array2DRowRealMatrix(matrixData);
   }
 
-  private double[] toDoubleArray(TrainingExample<Double, Double> sample) {
-    double[] ar = new double[sample.getFeatureVector().size() + 1];
+  private double[] toDoubleArray(Example<Double> sample) {
+    double[] ar = new double[sample.getFeatureVector().size()];
     int i = 0;
     for (Feature<Double> f : sample.getFeatureVector()) {
       ar[i] = f.getValue().doubleValue();
       i++;
     }
-    ar[i + 1] = sample.getOutput().getValue();
     return ar;
   }
 }

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=1239882&r1=1239881&r2=1239882&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 Thu Feb  2
22:15:38 2012
@@ -33,7 +33,7 @@ import java.util.Set;
 public class NeuralNetworkFactory {
 
 
-  public static NeuralNetwork create(final Set<RealMatrix> weightsMatrixes, final Collection<TrainingExample<Double,
Double>> trainingSet) throws InvalidWeightMatrixException {
+  public static NeuralNetwork create(final Set<RealMatrix> weightsMatrixes, final Collection<Example<Double>>
samples) throws InvalidWeightMatrixException {
 
     final MatrixConverter matrixConverter = new MatrixConverter();
 
@@ -58,8 +58,10 @@ public class NeuralNetworkFactory {
 
         // 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(trainingSet);
+        RealMatrix x = matrixConverter.toMatrix(samples);
         for (RealMatrix weightsMatrix : weightsMatrixes) {
           // compute matrix multiplication
           x = weightsMatrix.transpose().multiply(x);

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=1239882&r1=1239881&r2=1239882&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 Thu Feb  2 22:15:38
2012
@@ -20,14 +20,11 @@ package org.apache.yay;
 
 import org.apache.yay.bio.Signal;
 
-import java.util.Vector;
-
 /**
  * A training example with input features and associated output
  */
-public interface TrainingExample<F, O> {
-
-  public Vector<Feature<F>> getFeatureVector();
+public interface TrainingExample<F, O> extends Example {
 
   public Signal<O> getOutput();
+
 }



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


Mime
View raw message