[mlpack-svn] r15857 - mlpack/trunk/src/mlpack/methods/nmf

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Sat Sep 28 00:21:51 EDT 2013


Author: rcurtin
Date: Sat Sep 28 00:21:50 2013
New Revision: 15857

Log:
More fixes for correct sparse NMF.


Modified:
   mlpack/trunk/src/mlpack/methods/nmf/mult_dist_update_rules.hpp
   mlpack/trunk/src/mlpack/methods/nmf/mult_div_update_rules.hpp
   mlpack/trunk/src/mlpack/methods/nmf/random_acol_init.hpp

Modified: mlpack/trunk/src/mlpack/methods/nmf/mult_dist_update_rules.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/nmf/mult_dist_update_rules.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/nmf/mult_dist_update_rules.hpp	Sat Sep 28 00:21:50 2013
@@ -37,8 +37,8 @@
    * @param W Basis matrix to be updated.
    * @param H Encoding matrix.
    */
-
-  inline static void Update(const arma::mat& V,
+  template<typename MatType>
+  inline static void Update(const MatType& V,
                             arma::mat& W,
                             const arma::mat& H)
   {
@@ -66,8 +66,8 @@
    * @param W Basis matrix.
    * @param H Encoding matrix to be updated.
    */
-
-  inline static void Update(const arma::mat& V,
+  template<typename MatType>
+  inline static void Update(const MatType& V,
                             const arma::mat& W,
                             arma::mat& H)
   {

Modified: mlpack/trunk/src/mlpack/methods/nmf/mult_div_update_rules.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/nmf/mult_div_update_rules.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/nmf/mult_div_update_rules.hpp	Sat Sep 28 00:21:50 2013
@@ -53,7 +53,16 @@
     {
       for (size_t j = 0; j < W.n_cols; ++j)
       {
-        t2 = H.row(j) % V.row(i) / t1.row(i);
+        // Writing this as a single expression does not work as of Armadillo
+        // 3.920.  This should be fixed in a future release, and then the code
+        // below can be fixed.
+        //t2 = H.row(j) % V.row(i) / t1.row(i);
+        t2.set_size(H.n_cols);
+        for (size_t k = 0; k < t2.n_elem; ++k)
+        {
+          t2(k) = H(j, k) * V(i, k) / t1(i, k);
+        }
+
         W(i, j) = W(i, j) * sum(t2) / sum(H.row(j));
       }
     }
@@ -95,7 +104,16 @@
     {
       for (size_t j = 0; j < H.n_cols; j++)
       {
-        t2 = W.col(i) % V.col(j) / t1.col(j);
+        // Writing this as a single expression does not work as of Armadillo
+        // 3.920.  This should be fixed in a future release, and then the code
+        // below can be fixed.
+        //t2 = W.col(i) % V.col(j) / t1.col(j);
+        t2.set_size(W.n_rows);
+        for (size_t k = 0; k < t2.n_elem; ++k)
+        {
+          t2(k) = W(k, i) * V(k, j) / t1(k, j);
+        }
+
         H(i,j) = H(i,j) * sum(t2) / sum(W.col(i));
       }
     }

Modified: mlpack/trunk/src/mlpack/methods/nmf/random_acol_init.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/nmf/random_acol_init.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/nmf/random_acol_init.hpp	Sat Sep 28 00:21:50 2013
@@ -53,7 +53,8 @@
     {
       for (size_t randCol = 0; randCol < p; randCol++)
       {
-        W.col(col) += V.col(math::RandInt(0, m));
+        // .col() does not work in this case, as of Armadillo 3.920.
+        W.unsafe_col(col) += V.col(math::RandInt(0, m));
       }
     }
 



More information about the mlpack-svn mailing list