You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by ro...@apache.org on 2010/03/02 11:00:36 UTC

svn commit: r917939 - /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAInference.java

Author: robinanil
Date: Tue Mar  2 10:00:36 2010
New Revision: 917939

URL: http://svn.apache.org/viewvc?rev=917939&view=rev
Log:
Performance fix: Matrix in LDA was getting re-allocated for everydocument, added a reset code to reset/create the matrix values.

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAInference.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAInference.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAInference.java?rev=917939&r1=917938&r2=917939&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAInference.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/lda/LDAInference.java Tue Mar  2 10:00:36 2010
@@ -84,8 +84,7 @@
     Vector gamma = new DenseVector(state.numTopics);
     gamma.assign(state.topicSmoothing + docTotal / state.numTopics);
     Vector nextGamma = new DenseVector(state.numTopics);
-    
-    DenseMatrix phi = new DenseMatrix(state.numTopics, docLength);
+    createPhiMatrix(docLength);
     
     // digamma is expensive, precompute
     Vector digammaGamma = digamma(gamma);
@@ -141,6 +140,19 @@
     return new InferredDocument(wordCounts, gamma, columnMap, phi, oldLL);
   }
   
+  private void createPhiMatrix(int docLength) {
+    if (phi == null){
+      phi = new DenseMatrix(state.numTopics, docLength);
+    }
+    else if (phi.getRow(0).size() != docLength){
+      phi = new DenseMatrix(state.numTopics, docLength);
+    }
+    else {
+      phi.assign(0);
+    }
+  }
+  
+  private DenseMatrix phi;
   private final LDAState state;
   
   private double computeLikelihood(Vector wordCounts,