Author: tommaso
Date: Tue May 29 07:29:08 2012
New Revision: 1343574
URL: http://svn.apache.org/viewvc?rev=1343574&view=rev
Log:
fixed FF strategy matrix multiplication, it'll need optimization to avoid
useless transposes
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=1343574&r1=1343573&r2=1343574&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
Tue May 29 07:29:08 2012
@@ -54,16 +54,17 @@ public class FeedForwardStrategy impleme
public Double predictOutput(Vector<Double> input, Set<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}));
+ RealMatrix x = v.outerProduct(new ArrayRealVector(new
Double[]{1d})).transpose(); // a 1xN matrix
for (WeightsMatrix weightsMatrix : weightsMatrixSet) {
// compute matrix multiplication
- x = weightsMatrix.transpose().multiply(x);
+ x = x.multiply(weightsMatrix.transpose());
+
// apply the activation function to each element in the matrix
for (int i = 0; i < x.getRowDimension(); i++) {
double[] doubles = x.getRow(i);
- final ArrayList<Double> row = new ArrayList<Double>();
+ final ArrayList<Double> row = new ArrayList<Double>(doubles.length);
for (int j = 0; j < doubles.length; j++) {
- row.set(j, doubles[j]);
+ row.add(j, doubles[j]);
}
CollectionUtils.transform(row, new RowTransformer());
double[] finRow = new double[row.size()];
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]