You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by ss...@apache.org on 2012/06/22 10:19:10 UTC
svn commit: r1352796 -
/mahout/trunk/math/src/main/java/org/apache/mahout/math/als/ImplicitFeedbackAlternatingLeastSquaresSolver.java
Author: ssc
Date: Fri Jun 22 08:19:10 2012
New Revision: 1352796
URL: http://svn.apache.org/viewvc?rev=1352796&view=rev
Log:
MAHOUT-960 Reduce memory usage of ImplicitFeedbackAlternatingLeastSquaresSolver
Modified:
mahout/trunk/math/src/main/java/org/apache/mahout/math/als/ImplicitFeedbackAlternatingLeastSquaresSolver.java
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/als/ImplicitFeedbackAlternatingLeastSquaresSolver.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/als/ImplicitFeedbackAlternatingLeastSquaresSolver.java?rev=1352796&r1=1352795&r2=1352796&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/als/ImplicitFeedbackAlternatingLeastSquaresSolver.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/als/ImplicitFeedbackAlternatingLeastSquaresSolver.java Fri Jun 22 08:19:10 2012
@@ -63,16 +63,26 @@ public class ImplicitFeedbackAlternating
/* Y' Y */
private Matrix getYtransposeY(OpenIntObjectHashMap<Vector> Y) {
- Matrix compactedY = new DenseMatrix(Y.size(), numFeatures);
IntArrayList indexes = Y.keys();
indexes.quickSort();
- int row = 0;
- for (int index : indexes.elements()) {
- compactedY.assignRow(row++, Y.get(index));
- }
+ Matrix YTY = new DenseMatrix(numFeatures, numFeatures);
- return compactedY.transpose().times(compactedY);
+ // Compute Y'Y by dot products between the 'columns' of Y
+ for (int i = 0; i < numFeatures; i++) {
+ for (int j = i; j < numFeatures; j++) {
+ double dot = 0;
+ for (int k = 0; k < indexes.size(); k++) {
+ Vector row = Y.get(indexes.getQuick(k));
+ dot += row.getQuick(i) * row.getQuick(j);
+ }
+ YTY.setQuick(i, j, dot);
+ if (i != j) {
+ YTY.setQuick(j, i, dot);
+ }
+ }
+ }
+ return YTY;
}
/** Y' (Cu - I) Y + λ I */