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/07/12 21:47:15 UTC

svn commit: r1360886 - /labs/yay/trunk/core/src/main/java/org/apache/yay/FeedForwardStrategy.java

Author: tommaso
Date: Thu Jul 12 19:47:14 2012
New Revision: 1360886

URL: http://svn.apache.org/viewvc?rev=1360886&view=rev
Log:
slight refactoring of FFStrategy

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

Modified: 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=1360886&r1=1360885&r2=1360886&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/FeedForwardStrategy.java (original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/FeedForwardStrategy.java Thu Jul 12 19:47:14 2012
@@ -27,7 +27,10 @@ import org.apache.commons.math.linear.Re
 import org.apache.commons.math.linear.RealVector;
 import org.apache.yay.utils.MatrixConverter;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Vector;
 
 /**
  * Octave code for FF to be converted :
@@ -52,6 +55,16 @@ public class FeedForwardStrategy impleme
 
   @Override
   public Double predictOutput(Vector<Double> input, WeightsMatrix[] weightsMatrixSet) {
+    RealMatrix x = applyFF(input, weightsMatrixSet);
+    double[] lastColumn = x.getColumn(x.getColumnDimension() - 1);
+    return Collections.max(Arrays.asList(ArrayUtils.toObject(lastColumn)));
+  }
+
+  public RealMatrix debugOutput(Vector<Double> input, WeightsMatrix[] weightsMatrixSet) {
+    return applyFF(input, weightsMatrixSet);
+  }
+
+  private RealMatrix applyFF(Vector<Double> input, 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})).transpose(); // a 1xN matrix
@@ -66,7 +79,7 @@ public class FeedForwardStrategy impleme
         for (int j = 0; j < doubles.length; j++) {
           row.add(j, doubles[j]);
         }
-        CollectionUtils.transform(row, new RowTransformer());
+        CollectionUtils.transform(row, new HypothesisRowTransformer());
         double[] finRow = new double[row.size()];
         for (int h = 0; h < finRow.length; h++) {
           finRow[h] = row.get(h);
@@ -74,12 +87,10 @@ public class FeedForwardStrategy impleme
         x.setRow(i, finRow);
       }
     }
-    double[] lastColumn = x.getColumn(x.getColumnDimension() - 1);
-    return Collections.max(Arrays.asList(ArrayUtils.toObject(lastColumn)));
+    return x;
   }
 
-  private class RowTransformer implements Transformer {
-
+  private class HypothesisRowTransformer implements Transformer {
     @Override
     public Object transform(Object input) {
       assert input instanceof Double;



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