[mlpack] 34/324: Changing LMF(Latent Matrix Factorization) to AMF(Alternating Matrix Factorization). NMF and CF modules are updted.

Barak A. Pearlmutter barak+git at cs.nuim.ie
Sun Aug 17 08:21:53 UTC 2014


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit 70f5d69a5c392118bb1345f7d2efc0b1810f5c00
Author: sumedhghaisas <sumedhghaisas at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Tue May 27 23:49:17 2014 +0000

    Changing LMF(Latent Matrix Factorization) to AMF(Alternating Matrix Factorization). NMF and CF modules are updted.
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16567 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/methods/CMakeLists.txt                  |   3 +-
 src/mlpack/methods/{lmf => amf}/CMakeLists.txt     |  12 +-
 src/mlpack/methods/{lmf/lmf.hpp => amf/amf.hpp}    |  22 +--
 .../methods/{lmf/lmf_impl.hpp => amf/amf_impl.hpp} |   8 +-
 .../methods/{lmf/lmf_main.cpp => amf/amf_main.cpp} |  24 ++--
 .../methods/{lmf => amf}/init_rules/CMakeLists.txt |   0
 .../{nmf => amf/init_rules}/random_acol_init.hpp   |   8 +-
 .../{nmf => amf/init_rules}/random_init.hpp        |   8 +-
 .../{lmf => amf}/update_rules/CMakeLists.txt       |   0
 .../methods/{lmf => amf}/update_rules/nmf_als.hpp  |  23 +--
 .../{lmf => amf}/update_rules/nmf_mult_dist.hpp    |  23 +--
 .../{lmf => amf}/update_rules/nmf_mult_div.hpp     |  25 +---
 src/mlpack/methods/cf/cf.hpp                       |   8 +-
 .../methods/lmf/init_rules/random_acol_init.hpp    |  87 ------------
 src/mlpack/methods/lmf/init_rules/random_init.hpp  |  56 --------
 src/mlpack/methods/nmf/CMakeLists.txt              |  21 ---
 src/mlpack/methods/nmf/als_update_rules.hpp        | 102 -------------
 src/mlpack/methods/nmf/mult_dist_update_rules.hpp  |  81 -----------
 src/mlpack/methods/nmf/mult_div_update_rules.hpp   | 138 ------------------
 src/mlpack/methods/nmf/nmf.hpp                     | 158 ---------------------
 src/mlpack/methods/nmf/nmf_impl.hpp                | 111 ---------------
 src/mlpack/methods/nmf/nmf_main.cpp                |  28 ++--
 src/mlpack/tests/nmf_test.cpp                      |  34 ++---
 src/mlpack/tests/to_string_test.cpp                |   6 +-
 24 files changed, 89 insertions(+), 897 deletions(-)

diff --git a/src/mlpack/methods/CMakeLists.txt b/src/mlpack/methods/CMakeLists.txt
index a434eca..fb6a0d4 100644
--- a/src/mlpack/methods/CMakeLists.txt
+++ b/src/mlpack/methods/CMakeLists.txt
@@ -1,5 +1,6 @@
 # Recurse into each method mlpack provides.
 set(DIRS
+  amf
   cf
   det
   emst
@@ -18,7 +19,7 @@ set(DIRS
   nca
   neighbor_search
   nmf
-  lmf
+#  lmf
   pca
   radical
   range_search
diff --git a/src/mlpack/methods/lmf/CMakeLists.txt b/src/mlpack/methods/amf/CMakeLists.txt
similarity index 79%
rename from src/mlpack/methods/lmf/CMakeLists.txt
rename to src/mlpack/methods/amf/CMakeLists.txt
index e9205ae..1cdec9e 100644
--- a/src/mlpack/methods/lmf/CMakeLists.txt
+++ b/src/mlpack/methods/amf/CMakeLists.txt
@@ -1,8 +1,8 @@
 # Define the files we need to compile
 # Anything not in this list will not be compiled into MLPACK.
 set(SOURCES
-  lmf.hpp
-  lmf_impl.hpp
+  amf.hpp
+  amf_impl.hpp
 )
 
 # Add directory name to sources.
@@ -17,10 +17,10 @@ set(MLPACK_SRCS ${MLPACK_SRCS} ${DIR_SRCS} PARENT_SCOPE)
 add_subdirectory(update_rules)
 add_subdirectory(init_rules)
 
-add_executable(lmf
-  lmf_main.cpp
+add_executable(amf
+  amf_main.cpp
 )
-target_link_libraries(lmf
+target_link_libraries(amf
   mlpack
 )
-install(TARGETS lmf RUNTIME DESTINATION bin)
+install(TARGETS amf RUNTIME DESTINATION bin)
diff --git a/src/mlpack/methods/lmf/lmf.hpp b/src/mlpack/methods/amf/amf.hpp
similarity index 91%
rename from src/mlpack/methods/lmf/lmf.hpp
rename to src/mlpack/methods/amf/amf.hpp
index 16d4c63..1cfb3fb 100644
--- a/src/mlpack/methods/lmf/lmf.hpp
+++ b/src/mlpack/methods/amf/amf.hpp
@@ -6,10 +6,10 @@
 #include "init_rules/random_init.hpp"
 
 namespace mlpack {
-namespace lmf {
+namespace amf {
 
 /**
- * This class implements the LMF on the given matrix V. Latent Matrix
+ * This class implements the AMF on the given matrix V. Alternaing Matrix
  * Factorization decomposes V in the form \f$ V \approx WH \f$ where W is
  * called the basis matrix and H is called the encoding matrix. V is taken
  * to be of size n x m and the obtained W is n x r and H is r x m. The size r is
@@ -21,7 +21,7 @@ namespace lmf {
  * user to try various update rules (including ones not supplied with MLPACK)
  * for factorization.
  *
- * A simple example of how to run LMF is shown below.
+ * A simple example of how to run AMF is shown below.
  *
  * @code
  * extern arma::mat V; // Matrix that we want to perform LMF on.
@@ -29,8 +29,8 @@ namespace lmf {
  * arma::mat W; // Basis matrix
  * arma::mat H; // Encoding matrix
  *
- * LMF<> lmf; // Default options
- * lmf.Apply(V, W, H, r);
+ * AMF<> amf; // Default options
+ * amf.Apply(V, W, H, r);
  * @endcode
  *
  * @tparam InitializationRule The initialization rule for initializing W and H
@@ -41,8 +41,8 @@ namespace lmf {
  * @see NMF_MultiplicativeDistanceUpdate
  */
 template<typename InitializationRule = RandomInitialization,
-         typename UpdateRule = NMF_MultiplicativeDistanceUpdate>
-class LMF
+         typename UpdateRule = NMFMultiplicativeDistanceUpdate>
+class AMF
 {
  public:
   /**
@@ -62,7 +62,7 @@ class LMF
    * @param Update Optional UpdateRule object; for when the update rule for
    *     the W and H vector has states that it needs to store
    */
-  LMF(const size_t maxIterations = 10000,
+  AMF(const size_t maxIterations = 10000,
       const double minResidue = 1e-10,
       const InitializationRule initializeRule = InitializationRule(),
       const UpdateRule update = UpdateRule());
@@ -109,12 +109,12 @@ class LMF
   //! Modify the update rule.
   UpdateRule& Update() { return update; }
 
-}; // class LMF
+}; // class AMF
 
-}; // namespace lmf
+}; // namespace amf
 }; // namespace mlpack
 
 // Include implementation.
-#include "lmf_impl.hpp"
+#include "amf_impl.hpp"
 
 #endif
diff --git a/src/mlpack/methods/lmf/lmf_impl.hpp b/src/mlpack/methods/amf/amf_impl.hpp
similarity index 91%
rename from src/mlpack/methods/lmf/lmf_impl.hpp
rename to src/mlpack/methods/amf/amf_impl.hpp
index d4bf896..e0c0adf 100644
--- a/src/mlpack/methods/lmf/lmf_impl.hpp
+++ b/src/mlpack/methods/amf/amf_impl.hpp
@@ -1,12 +1,12 @@
 namespace mlpack {
-namespace lmf {
+namespace amf {
 
 /**
  * Construct the LMF object.
  */
 template<typename InitializationRule,
          typename UpdateRule>
-LMF<InitializationRule, UpdateRule>::LMF(
+AMF<InitializationRule, UpdateRule>::AMF(
     const size_t maxIterations,
     const double minResidue,
     const InitializationRule initializeRule,
@@ -18,7 +18,7 @@ LMF<InitializationRule, UpdateRule>::LMF(
 {
   if (minResidue < 0.0)
   {
-    Log::Warn << "LMF::LMF(): minResidue must be a positive value ("
+    Log::Warn << "AMF::AMF(): minResidue must be a positive value ("
         << minResidue << " given). Setting to the default value of 1e-10.\n";
     this->minResidue = 1e-10;
   }
@@ -35,7 +35,7 @@ LMF<InitializationRule, UpdateRule>::LMF(
 template<typename InitializationRule,
          typename UpdateRule>
 template<typename MatType>
-void LMF<InitializationRule, UpdateRule>::Apply(
+void AMF<InitializationRule, UpdateRule>::Apply(
     const MatType& V,
     const size_t r,
     arma::mat& W,
diff --git a/src/mlpack/methods/lmf/lmf_main.cpp b/src/mlpack/methods/amf/amf_main.cpp
similarity index 86%
rename from src/mlpack/methods/lmf/lmf_main.cpp
rename to src/mlpack/methods/amf/amf_main.cpp
index 04a79dc..a470dab 100644
--- a/src/mlpack/methods/lmf/lmf_main.cpp
+++ b/src/mlpack/methods/amf/amf_main.cpp
@@ -1,6 +1,6 @@
 #include <mlpack/core.hpp>
 
-#include "lmf.hpp"
+#include "amf.hpp"
 
 #include "init_rules/random_init.hpp"
 #include "update_rules/nmf_mult_dist.hpp"
@@ -8,11 +8,11 @@
 #include "update_rules/nmf_als.hpp"
 
 using namespace mlpack;
-using namespace mlpack::lmf;
+using namespace mlpack::amf;
 using namespace std;
 
 // Document program.
-PROGRAM_INFO("Latent Matrix Factorization", "This program performs "
+PROGRAM_INFO("Alternating Matrix Factorization", "This program performs "
     "matrix factorization on the given dataset, storing the "
     "resulting decomposed matrices in the specified files.  For an input "
     "dataset V, LMF decomposes V into two matrices W and H such that "
@@ -23,7 +23,7 @@ PROGRAM_INFO("Latent Matrix Factorization", "This program performs "
     " then W will be of size (n x r) and H will be of size (r x m), where r is "
     "the rank of the factorization (specified by --rank)."
     "\n\n"
-    "Optionally, the desired update rules for each LMF iteration can be chosen "
+    "Optionally, the desired update rules for each AMF iteration can be chosen "
     "from the following list:"
     "\n\n"
     " - multdist: multiplicative distance-based update rules (Lee and Seung "
@@ -41,7 +41,7 @@ PROGRAM_INFO("Latent Matrix Factorization", "This program performs "
     "--min_residue.");
 
 // Parameters for program.
-PARAM_STRING_REQ("input_file", "Input dataset to perform NMF on.", "i");
+PARAM_STRING_REQ("input_file", "Input dataset to perform AMF on.", "i");
 PARAM_STRING_REQ("w_file", "File to save the calculated W matrix to.", "W");
 PARAM_STRING_REQ("h_file", "File to save the calculated H matrix to.", "H");
 PARAM_INT_REQ("rank", "Rank of the factorization.", "r");
@@ -100,24 +100,24 @@ int main(int argc, char** argv)
   // Perform NMF with the specified update rules.
   if (updateRules == "multdist")
   {
-    Log::Info << "Performing LMF with multiplicative distance-based update(Non-negative Matrix Factorization) "
+    Log::Info << "Performing AMF with multiplicative distance-based update(Non-negative Matrix Factorization) "
         << "rules." << std::endl;
-    LMF<> nmf(maxIterations, minResidue);
-    nmf.Apply(V, r, W, H);
+    AMF<> amf(maxIterations, minResidue);
+    amf.Apply(V, r, W, H);
   }
   else if (updateRules == "multdiv")
   {
     Log::Info << "Performing NMF with multiplicative divergence-based update(Non-negative Matrix Factorization) "
         << "rules." << std::endl;
-    LMF<RandomInitialization,NMF_MultiplicativeDivergenceUpdate> lmf(maxIterations, minResidue);
-    lmf.Apply(V, r, W, H);
+    AMF<RandomInitialization,NMFMultiplicativeDivergenceUpdate> amf(maxIterations, minResidue);
+    amf.Apply(V, r, W, H);
   }
   else if (updateRules == "als")
   {
     Log::Info << "Performing NMF with alternating least squared update rules.(Non-negative Matrix Factorization)"
         << std::endl;
-    LMF<RandomInitialization, NMF_ALSUpdate> lmf(maxIterations, minResidue);
-    lmf.Apply(V, r, W, H);
+    AMF<RandomInitialization, NMFALSUpdate> amf(maxIterations, minResidue);
+    amf.Apply(V, r, W, H);
   }
 
   // Save results.
diff --git a/src/mlpack/methods/lmf/init_rules/CMakeLists.txt b/src/mlpack/methods/amf/init_rules/CMakeLists.txt
similarity index 100%
rename from src/mlpack/methods/lmf/init_rules/CMakeLists.txt
rename to src/mlpack/methods/amf/init_rules/CMakeLists.txt
diff --git a/src/mlpack/methods/nmf/random_acol_init.hpp b/src/mlpack/methods/amf/init_rules/random_acol_init.hpp
similarity index 93%
rename from src/mlpack/methods/nmf/random_acol_init.hpp
rename to src/mlpack/methods/amf/init_rules/random_acol_init.hpp
index 43d9b39..722e59a 100644
--- a/src/mlpack/methods/nmf/random_acol_init.hpp
+++ b/src/mlpack/methods/amf/init_rules/random_acol_init.hpp
@@ -8,13 +8,13 @@
  * This method sets each of the columns of W by averaging p randomly chosen
  * columns of V.
  */
-#ifndef __MLPACK_METHODS_NMF_RANDOM_ACOL_INIT_HPP
-#define __MLPACK_METHODS_NMF_RANDOM_ACOL_INIT_HPP
+#ifndef __MLPACK_METHODS_LMF_RANDOM_ACOL_INIT_HPP
+#define __MLPACK_METHODS_LMF_RANDOM_ACOL_INIT_HPP
 
 #include <mlpack/core.hpp>
 
 namespace mlpack {
-namespace nmf {
+namespace amf {
 
 /**
  * This class initializes the W matrix of the NMF algorithm by averaging p
@@ -66,7 +66,7 @@ class RandomAcolInitialization
   }
 }; // Class RandomAcolInitialization
 
-}; // namespace nmf
+}; // namespace amf
 }; // namespace mlpack
 
 #endif
diff --git a/src/mlpack/methods/nmf/random_init.hpp b/src/mlpack/methods/amf/init_rules/random_init.hpp
similarity index 87%
rename from src/mlpack/methods/nmf/random_init.hpp
rename to src/mlpack/methods/amf/init_rules/random_init.hpp
index 0ec52ae..8a17ba3 100644
--- a/src/mlpack/methods/nmf/random_init.hpp
+++ b/src/mlpack/methods/amf/init_rules/random_init.hpp
@@ -5,13 +5,13 @@
  * Intialization rule for Non-Negative Matrix Factorization (NMF). This simple
  * initialization is performed by assigning a random matrix to W and H.
  */
-#ifndef __MLPACK_METHODS_NMF_RANDOM_INIT_HPP
-#define __MLPACK_METHODS_NMF_RANDOM_INIT_HPP
+#ifndef __MLPACK_METHODS_LMF_RANDOM_INIT_HPP
+#define __MLPACK_METHODS_LMF_RANDOM_INIT_HPP
 
 #include <mlpack/core.hpp>
 
 namespace mlpack {
-namespace nmf {
+namespace amf {
 
 class RandomInitialization
 {
@@ -35,7 +35,7 @@ class RandomInitialization
   }
 };
 
-}; // namespace nmf
+}; // namespace amf
 }; // namespace mlpack
 
 #endif
diff --git a/src/mlpack/methods/lmf/update_rules/CMakeLists.txt b/src/mlpack/methods/amf/update_rules/CMakeLists.txt
similarity index 100%
rename from src/mlpack/methods/lmf/update_rules/CMakeLists.txt
rename to src/mlpack/methods/amf/update_rules/CMakeLists.txt
diff --git a/src/mlpack/methods/lmf/update_rules/nmf_als.hpp b/src/mlpack/methods/amf/update_rules/nmf_als.hpp
similarity index 75%
rename from src/mlpack/methods/lmf/update_rules/nmf_als.hpp
rename to src/mlpack/methods/amf/update_rules/nmf_als.hpp
index d559ea3..2ad3606 100644
--- a/src/mlpack/methods/lmf/update_rules/nmf_als.hpp
+++ b/src/mlpack/methods/amf/update_rules/nmf_als.hpp
@@ -9,21 +9,6 @@
  * squares projection formula to reduce the error value of
  * \f$ \sqrt{\sum_i \sum_j(V-WH)^2} \f$ by alternately calculating W and H
  * respectively while holding the other matrix constant.
- *
- * This file is part of MLPACK 1.0.8.
- *
- * MLPACK is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation, either version 3 of the License, or (at your option) any
- * later version.
- *
- * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
- * details (LICENSE.txt).
- *
- * You should have received a copy of the GNU General Public License along with
- * MLPACK.  If not, see <http://www.gnu.org/licenses/>.
  */
 #ifndef __MLPACK_METHODS_LMF_UPDATE_RULES_NMF_ALS_HPP
 #define __MLPACK_METHODS_LMF_UPDATE_RULES_NMF_ALS_HPP
@@ -31,16 +16,16 @@
 #include <mlpack/core.hpp>
 
 namespace mlpack {
-namespace lmf {
+namespace amf {
 
 /**
  * The alternating least square update rules of matrices W and H.
  */
-class NMF_ALSUpdate
+class NMFALSUpdate
 {
  public:
   // Empty constructor required for the UpdateRule template.
-  NMF_ALSUpdate() { }
+  NMFALSUpdate() { }
 
   /**
    * The update rule for the basis matrix W. The formula used is
@@ -103,7 +88,7 @@ class NMF_ALSUpdate
   }
 };
 
-}; // namespace lmf
+}; // namespace amf
 }; // namespace mlpack
 
 #endif
diff --git a/src/mlpack/methods/lmf/update_rules/nmf_mult_dist.hpp b/src/mlpack/methods/amf/update_rules/nmf_mult_dist.hpp
similarity index 71%
rename from src/mlpack/methods/lmf/update_rules/nmf_mult_dist.hpp
rename to src/mlpack/methods/amf/update_rules/nmf_mult_dist.hpp
index 72a3541..90c0744 100644
--- a/src/mlpack/methods/lmf/update_rules/nmf_mult_dist.hpp
+++ b/src/mlpack/methods/amf/update_rules/nmf_mult_dist.hpp
@@ -8,21 +8,6 @@
  * that the Frobenius norm \f$ \sqrt{\sum_i \sum_j(V-WH)^2} \f$ is
  * non-increasing between subsequent iterations. Both of the update rules
  * for W and H are defined in this file.
- *
- * This file is part of MLPACK 1.0.8.
- *
- * MLPACK is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation, either version 3 of the License, or (at your option) any
- * later version.
- *
- * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
- * details (LICENSE.txt).
- *
- * You should have received a copy of the GNU General Public License along with
- * MLPACK.  If not, see <http://www.gnu.org/licenses/>.
  */
 #ifndef __MLPACK_METHODS_LMF_UPDATE_RULES_NMF_MULT_DIST_UPDATE_RULES_HPP
 #define __MLPACK_METHODS_LMF_UPDATE_RULES_NMF_MULT_DIST_UPDATE_RULES_HPP
@@ -30,16 +15,16 @@
 #include <mlpack/core.hpp>
 
 namespace mlpack {
-namespace lmf {
+namespace amf {
 
 /**
  * The multiplicative distance update rules for matrices W and H.
  */
-class NMF_MultiplicativeDistanceUpdate
+class NMFMultiplicativeDistanceUpdate
 {
  public:
   // Empty constructor required for the UpdateRule template.
-  NMF_MultiplicativeDistanceUpdate() { }
+  NMFMultiplicativeDistanceUpdate() { }
 
   /**
    * The update rule for the basis matrix W. The formula used is
@@ -81,7 +66,7 @@ class NMF_MultiplicativeDistanceUpdate
   }
 };
 
-}; // namespace lmf
+}; // namespace amf
 }; // namespace mlpack
 
 #endif
diff --git a/src/mlpack/methods/lmf/update_rules/nmf_mult_div.hpp b/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp
similarity index 79%
rename from src/mlpack/methods/lmf/update_rules/nmf_mult_div.hpp
rename to src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp
index 73ee0d5..4890643 100644
--- a/src/mlpack/methods/lmf/update_rules/nmf_mult_div.hpp
+++ b/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp
@@ -1,5 +1,5 @@
 /**
- * @file nmf_mult_div.hpp
+ * @file mult_div_update_rules.hpp
  * @author Mohan Rajendran
  *
  * Update rules for the Non-negative Matrix Factorization. This follows a method
@@ -9,21 +9,6 @@
  * \f$ \sum_i \sum_j (V_{ij} log\frac{V_{ij}}{(WH)_{ij}}-V_{ij}+(WH)_{ij}) \f$is
  * non-increasing between subsequent iterations. Both of the update rules
  * for W and H are defined in this file.
- *
- * This file is part of MLPACK 1.0.8.
- *
- * MLPACK is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation, either version 3 of the License, or (at your option) any
- * later version.
- *
- * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
- * details (LICENSE.txt).
- *
- * You should have received a copy of the GNU General Public License along with
- * MLPACK.  If not, see <http://www.gnu.org/licenses/>.
  */
 #ifndef __MLPACK_METHODS_LMF_UPDATE_RULES_NMF_MULT_DIV_HPP
 #define __MLPACK_METHODS_LMF_UPDATE_RULES_NMF_MULT_DIV_HPP
@@ -31,14 +16,14 @@
 #include <mlpack/core.hpp>
 
 namespace mlpack {
-namespace lmf {
+namespace amf {
 
 
-class NMF_MultiplicativeDivergenceUpdate
+class NMFMultiplicativeDivergenceUpdate
 {
  public:
   // Empty constructor required for the WUpdateRule template.
-  NMF_MultiplicativeDivergenceUpdate() { }
+  NMFMultiplicativeDivergenceUpdate() { }
 
   /**
    * The update rule for the basis matrix W. The formula used is
@@ -125,7 +110,7 @@ class NMF_MultiplicativeDivergenceUpdate
   }
 };
 
-}; // namespace lmf
+}; // namespace amf
 }; // namespace mlpack
 
 #endif
diff --git a/src/mlpack/methods/cf/cf.hpp b/src/mlpack/methods/cf/cf.hpp
index 3e12902..7ca02cb 100644
--- a/src/mlpack/methods/cf/cf.hpp
+++ b/src/mlpack/methods/cf/cf.hpp
@@ -12,8 +12,8 @@
 
 #include <mlpack/core.hpp>
 #include <mlpack/methods/neighbor_search/neighbor_search.hpp>
-#include <mlpack/methods/lmf/lmf.hpp>
-#include <mlpack/methods/lmf/update_rules/nmf_als.hpp>
+#include <mlpack/methods/amf/amf.hpp>
+#include <mlpack/methods/amf/update_rules/nmf_als.hpp>
 #include <set>
 #include <map>
 #include <iostream>
@@ -54,8 +54,8 @@ namespace cf /** Collaborative filtering. */{
  *     Apply(arma::sp_mat& data, size_t rank, arma::mat& W, arma::mat& H).
  */
 template<
-    typename FactorizerType = lmf::LMF<lmf::RandomInitialization, 
-                                       lmf::NMF_ALSUpdate> >
+    typename FactorizerType = amf::AMF<amf::RandomInitialization, 
+                                       amf::NMFALSUpdate> >
 class CF
 {
  public:
diff --git a/src/mlpack/methods/lmf/init_rules/random_acol_init.hpp b/src/mlpack/methods/lmf/init_rules/random_acol_init.hpp
deleted file mode 100644
index b110e49..0000000
--- a/src/mlpack/methods/lmf/init_rules/random_acol_init.hpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * @file random_acol_init.hpp
- * @author Mohan Rajendran
- *
- * Intialization rule for Non-Negative Matrix Factorization. This simple
- * initialization is performed by the random Acol initialization introduced in
- * the paper 'Algorithms, Initializations and Convergence' by Langville et al.
- * This method sets each of the columns of W by averaging p randomly chosen
- * columns of V.
- *
- * This file is part of MLPACK 1.0.8.
- *
- * MLPACK is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation, either version 3 of the License, or (at your option) any
- * later version.
- *
- * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
- * details (LICENSE.txt).
- *
- * You should have received a copy of the GNU General Public License along with
- * MLPACK.  If not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef __MLPACK_METHODS_LMF_RANDOM_ACOL_INIT_HPP
-#define __MLPACK_METHODS_LMF_RANDOM_ACOL_INIT_HPP
-
-#include <mlpack/core.hpp>
-
-namespace mlpack {
-namespace lmf {
-
-/**
- * This class initializes the W matrix of the NMF algorithm by averaging p
- * randomly chosen columns of V.  In this case, p is a template parameter.  H is
- * then set randomly.
- *
- * @tparam The number of random columns to average for each column of W.
- */
-template<int p = 5>
-class RandomAcolInitialization
-{
- public:
-  // Empty constructor required for the InitializeRule template
-  RandomAcolInitialization()
-  { }
-
-  template<typename MatType>
-  inline static void Initialize(const MatType& V,
-                                const size_t r,
-                                arma::mat& W,
-                                arma::mat& H)
-  {
-    const size_t n = V.n_rows;
-    const size_t m = V.n_cols;
-
-    if (p > m)
-    {
-      Log::Warn << "Number of random columns is more than the number of columns"
-          << "available in the V matrix; weird results may ensue!" << std::endl;
-    }
-
-    W.zeros(n, r);
-
-    // Initialize W matrix with random columns.
-    for (size_t col = 0; col < r; col++)
-    {
-      for (size_t randCol = 0; randCol < p; randCol++)
-      {
-        // .col() does not work in this case, as of Armadillo 3.920.
-        W.unsafe_col(col) += V.col(math::RandInt(0, m));
-      }
-    }
-
-    // Now divide by p.
-    W /= p;
-
-    // Initialize H to random values.
-    H.randu(r, m);
-  }
-}; // Class RandomAcolInitialization
-
-}; // namespace lmf
-}; // namespace mlpack
-
-#endif
diff --git a/src/mlpack/methods/lmf/init_rules/random_init.hpp b/src/mlpack/methods/lmf/init_rules/random_init.hpp
deleted file mode 100644
index de91724..0000000
--- a/src/mlpack/methods/lmf/init_rules/random_init.hpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * @file random_init.hpp
- * @author Mohan Rajendran
- *
- * Intialization rule for Non-Negative Matrix Factorization (NMF). This simple
- * initialization is performed by assigning a random matrix to W and H.
- *
- * This file is part of MLPACK 1.0.8.
- *
- * MLPACK is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation, either version 3 of the License, or (at your option) any
- * later version.
- *
- * MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
- * details (LICENSE.txt).
- *
- * You should have received a copy of the GNU General Public License along with
- * MLPACK.  If not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef __MLPACK_METHODS_LMF_RANDOM_INIT_HPP
-#define __MLPACK_METHODS_LMF_RANDOM_INIT_HPP
-
-#include <mlpack/core.hpp>
-
-namespace mlpack {
-namespace lmf {
-
-class RandomInitialization
-{
- public:
-  // Empty constructor required for the InitializeRule template
-  RandomInitialization() { }
-
-  template<typename MatType>
-  inline static void Initialize(const MatType& V,
-                                const size_t r,
-                                arma::mat& W,
-                                arma::mat& H)
-  {
-    // Simple implementation (left in the header file due to its simplicity).
-    size_t n = V.n_rows;
-    size_t m = V.n_cols;
-
-    // Intialize to random values.
-    W.randu(n, r);
-    H.randu(r, m);
-  }
-};
-
-}; // namespace lmf
-}; // namespace mlpack
-
-#endif
diff --git a/src/mlpack/methods/nmf/CMakeLists.txt b/src/mlpack/methods/nmf/CMakeLists.txt
index f3d5673..b1c2b51 100644
--- a/src/mlpack/methods/nmf/CMakeLists.txt
+++ b/src/mlpack/methods/nmf/CMakeLists.txt
@@ -1,24 +1,3 @@
-# Define the files we need to compile
-# Anything not in this list will not be compiled into MLPACK.
-set(SOURCES
-  mult_dist_update_rules.hpp
-  mult_div_update_rules.hpp
-  als_update_rules.hpp
-  random_init.hpp
-  random_acol_init.hpp
-  nmf.hpp
-  nmf_impl.hpp
-)
-
-# Add directory name to sources.
-set(DIR_SRCS)
-foreach(file ${SOURCES})
-  set(DIR_SRCS ${DIR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/${file})
-endforeach()
-# Append sources (with directory name) to list of all MLPACK sources (used at
-# the parent scope).
-set(MLPACK_SRCS ${MLPACK_SRCS} ${DIR_SRCS} PARENT_SCOPE)
-
 add_executable(nmf
   nmf_main.cpp
 )
diff --git a/src/mlpack/methods/nmf/als_update_rules.hpp b/src/mlpack/methods/nmf/als_update_rules.hpp
deleted file mode 100644
index 787bfad..0000000
--- a/src/mlpack/methods/nmf/als_update_rules.hpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * @file als_update_rules.hpp
- * @author Mohan Rajendran
- *
- * Update rules for the Non-negative Matrix Factorization. This follows a method
- * titled 'Alternating Least Squares' described in the paper 'Positive Matrix
- * Factorization: A Non-negative Factor Model with Optimal Utilization of
- * Error Estimates of Data Values' by P. Paatero and U. Tapper. It uses least
- * squares projection formula to reduce the error value of
- * \f$ \sqrt{\sum_i \sum_j(V-WH)^2} \f$ by alternately calculating W and H
- * respectively while holding the other matrix constant.
- */
-#ifndef __MLPACK_METHODS_NMF_ALS_UPDATE_RULES_HPP
-#define __MLPACK_METHODS_NMF_ALS_UPDATE_RULES_HPP
-
-#include <mlpack/core.hpp>
-
-namespace mlpack {
-namespace nmf {
-
-/**
- * The update rule for the basis matrix W. The formula used is
- * \f[
- * W^T = \frac{HV^T}{HH^T}
- * \f]
- */
-class WAlternatingLeastSquaresRule
-{
- public:
-  // Empty constructor required for the WUpdateRule template.
-  WAlternatingLeastSquaresRule() { }
-
-  /**
-   * The update function that actually updates the W matrix. The function takes
-   * in all the matrices and only changes the value of the W matrix.
-   *
-   * @param V Input matrix to be factorized.
-   * @param W Basis matrix to be updated.
-   * @param H Encoding matrix.
-   */
-  template<typename MatType>
-  inline static void Update(const MatType& V,
-                            arma::mat& W,
-                            const arma::mat& H)
-  {
-    // The call to inv() sometimes fails; so we are using the psuedoinverse.
-    // W = (inv(H * H.t()) * H * V.t()).t();
-    W = V * H.t() * pinv(H * H.t());
-
-    // Set all negative numbers to machine epsilon
-    for (size_t i = 0; i < W.n_elem; i++)
-    {
-      if (W(i) < 0.0)
-      {
-        W(i) = 0.0;
-      }
-    }
-  }
-};
-
-/**
- * The update rule for the encoding matrix H. The formula used is
- * \f[
- * H = \frac{W^TV}{W^TW}
- * \f]
- */
-class HAlternatingLeastSquaresRule
-{
- public:
-  // Empty constructor required for the HUpdateRule template.
-  HAlternatingLeastSquaresRule() { }
-
-  /**
-   * The update function that actually updates the H matrix. The function takes
-   * in all the matrices and only changes the value of the H matrix.
-   *
-   * @param V Input matrix to be factorized.
-   * @param W Basis matrix.
-   * @param H Encoding matrix to be updated.
-   */
-  template<typename MatType>
-  inline static void Update(const MatType& V,
-                            const arma::mat& W,
-                            arma::mat& H)
-  {
-    H = pinv(W.t() * W) * W.t() * V;
-
-    // Set all negative numbers to 0.
-    for (size_t i = 0; i < H.n_elem; i++)
-    {
-      if (H(i) < 0.0)
-      {
-        H(i) = 0.0;
-      }
-    }
-  }
-};
-
-}; // namespace nmf
-}; // namespace mlpack
-
-#endif
diff --git a/src/mlpack/methods/nmf/mult_dist_update_rules.hpp b/src/mlpack/methods/nmf/mult_dist_update_rules.hpp
deleted file mode 100644
index 6a7c9c5..0000000
--- a/src/mlpack/methods/nmf/mult_dist_update_rules.hpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * @file mult_dist_update_rules.hpp
- * @author Mohan Rajendran
- *
- * Update rules for the Non-negative Matrix Factorization. This follows a method
- * described in the paper 'Algorithms for Non-negative Matrix Factorization'
- * by D. D. Lee and H. S. Seung. This is a multiplicative rule that ensures
- * that the Frobenius norm \f$ \sqrt{\sum_i \sum_j(V-WH)^2} \f$ is
- * non-increasing between subsequent iterations. Both of the update rules
- * for W and H are defined in this file.
- */
-#ifndef __MLPACK_METHODS_NMF_MULT_DIST_UPDATE_RULES_HPP
-#define __MLPACK_METHODS_NMF_MULT_DIST_UPDATE_RULES_HPP
-
-#include <mlpack/core.hpp>
-
-namespace mlpack {
-namespace nmf {
-
-/**
- * The update rule for the basis matrix W. The formula used is
- * \f[
- * W_{ia} \leftarrow W_{ia} \frac{(VH^T)_{ia}}{(WHH^T)_{ia}}
- * \f]
- */
-class WMultiplicativeDistanceRule
-{
- public:
-  // Empty constructor required for the WUpdateRule template.
-  WMultiplicativeDistanceRule() { }
-
-  /**
-   * The update function that actually updates the W matrix. The function takes
-   * in all the matrices and only changes the value of the W matrix.
-   *
-   * @param V Input matrix to be factorized.
-   * @param W Basis matrix to be updated.
-   * @param H Encoding matrix.
-   */
-  template<typename MatType>
-  inline static void Update(const MatType& V,
-                            arma::mat& W,
-                            const arma::mat& H)
-  {
-    W = (W % (V * H.t())) / (W * H * H.t());
-  }
-};
-
-/**
- * The update rule for the encoding matrix H. The formula used is
- * \f[
- * H_{a\mu} \leftarrow H_{a\mu} \frac{(W^T V)_{a\mu}}{(W^T WH)_{a\mu}}
- * \f]
- */
-class HMultiplicativeDistanceRule
-{
- public:
-  // Empty constructor required for the HUpdateRule template.
-  HMultiplicativeDistanceRule() { }
-
-  /**
-   * The update function that actually updates the H matrix. The function takes
-   * in all the matrices and only changes the value of the H matrix.
-   *
-   * @param V Input matrix to be factorized.
-   * @param W Basis matrix.
-   * @param H Encoding matrix to be updated.
-   */
-  template<typename MatType>
-  inline static void Update(const MatType& V,
-                            const arma::mat& W,
-                            arma::mat& H)
-  {
-    H = (H % (W.t() * V)) / (W.t() * W * H);
-  }
-};
-
-}; // namespace nmf
-}; // namespace mlpack
-
-#endif
diff --git a/src/mlpack/methods/nmf/mult_div_update_rules.hpp b/src/mlpack/methods/nmf/mult_div_update_rules.hpp
deleted file mode 100644
index ca8eb9f..0000000
--- a/src/mlpack/methods/nmf/mult_div_update_rules.hpp
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * @file mult_div_update_rules.hpp
- * @author Mohan Rajendran
- *
- * Update rules for the Non-negative Matrix Factorization. This follows a method
- * described in the paper 'Algorithms for Non-negative Matrix Factorization'
- * by D. D. Lee and H. S. Seung. This is a multiplicative rule that ensures
- * that the Kullback–Leibler divergence
- * \f$ \sum_i \sum_j (V_{ij} log\frac{V_{ij}}{(WH)_{ij}}-V_{ij}+(WH)_{ij}) \f$is
- * non-increasing between subsequent iterations. Both of the update rules
- * for W and H are defined in this file.
- */
-#ifndef __MLPACK_METHODS_NMF_MULT_DIV_UPDATE_RULES_HPP
-#define __MLPACK_METHODS_NMF_MULT_DIV_UPDATE_RULES_HPP
-
-#include <mlpack/core.hpp>
-
-namespace mlpack {
-namespace nmf {
-
-/**
- * The update rule for the basis matrix W. The formula used is
- * \f[
- * W_{ia} \leftarrow W_{ia} \frac{\sum_{\mu} H_{a\mu} V_{i\mu}/(WH)_{i\mu}}
- * {\sum_{\nu} H_{a\nu}}
- * \f]
- */
-class WMultiplicativeDivergenceRule
-{
- public:
-  // Empty constructor required for the WUpdateRule template.
-  WMultiplicativeDivergenceRule() { }
-
-  /**
-   * The update function that actually updates the W matrix. The function takes
-   * in all the matrices and only changes the value of the W matrix.
-   *
-   * @param V Input matrix to be factorized.
-   * @param W Basis matrix to be updated.
-   * @param H Encoding matrix.
-   */
-  template<typename MatType>
-  inline static void Update(const MatType& V,
-                            arma::mat& W,
-                            const arma::mat& H)
-  {
-    // Simple implementation left in the header file.
-    arma::mat t1;
-    arma::rowvec t2;
-
-    t1 = W * H;
-    for (size_t i = 0; i < W.n_rows; ++i)
-    {
-      for (size_t j = 0; j < W.n_cols; ++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 = 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)
-        {
-          // This may produce NaNs if V(i, k) = 0.
-          // Technically the math in the paper does not define what to do in
-          // this case, but considering the basic intent of the update rules,
-          // we'll make this modification and take t2(k) = 0.0.
-          t2(k) = H(j, k) * V(i, k) / t1(i, k);
-          if (t2(k) != t2(k))
-            t2(k) = 0.0;
-        }
-
-        W(i, j) *= sum(t2) / sum(H.row(j));
-      }
-    }
-  }
-};
-
-/**
- * The update rule for the encoding matrix H. The formula used is
- * \f[
- * H_{a\mu} \leftarrow H_{a\mu} \frac{\sum_{i} W_{ia} V_{i\mu}/(WH)_{i\mu}}
- * {\sum_{k} H_{ka}}
- * \f]
- */
-class HMultiplicativeDivergenceRule
-{
- public:
-  // Empty constructor required for the HUpdateRule template.
-  HMultiplicativeDivergenceRule() { }
-
-  /**
-   * The update function that actually updates the H matrix. The function takes
-   * in all the matrices and only changes the value of the H matrix.
-   *
-   * @param V Input matrix to be factorized.
-   * @param W Basis matrix.
-   * @param H Encoding matrix to updated.
-   */
-  template<typename MatType>
-  inline static void Update(const MatType& V,
-                            const arma::mat& W,
-                            arma::mat& H)
-  {
-    // Simple implementation left in the header file.
-    arma::mat t1;
-    arma::colvec t2;
-
-    t1 = W * H;
-    for (size_t i = 0; i < H.n_rows; i++)
-    {
-      for (size_t j = 0; j < H.n_cols; 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)
-        {
-          // This may produce NaNs if V(i, k) = 0.
-          // Technically the math in the paper does not define what to do in
-          // this case, but considering the basic intent of the update rules,
-          // we'll make this modification and take t2(k) = 0.0.
-          t2(k) = W(k, i) * V(k, j) / t1(k, j);
-          if (t2(k) != t2(k))
-            t2(k) = 0.0;
-        }
-
-        H(i, j) *= sum(t2) / sum(W.col(i));
-      }
-    }
-  }
-};
-
-}; // namespace nmf
-}; // namespace mlpack
-
-#endif
diff --git a/src/mlpack/methods/nmf/nmf.hpp b/src/mlpack/methods/nmf/nmf.hpp
deleted file mode 100644
index bdc0d25..0000000
--- a/src/mlpack/methods/nmf/nmf.hpp
+++ /dev/null
@@ -1,158 +0,0 @@
-/**
- * @file nmf.hpp
- * @author Mohan Rajendran
- *
- * Defines the NMF class to perform Non-negative Matrix Factorization
- * on the given matrix.
- */
-#ifndef __MLPACK_METHODS_NMF_NMF_HPP
-#define __MLPACK_METHODS_NMF_NMF_HPP
-
-#include <mlpack/core.hpp>
-#include "mult_dist_update_rules.hpp"
-#include "random_init.hpp"
-
-namespace mlpack {
-namespace nmf {
-
-/**
- * This class implements the NMF on the given matrix V. Non-negative Matrix
- * Factorization decomposes V in the form \f$ V \approx WH \f$ where W is
- * called the basis matrix and H is called the encoding matrix. V is taken
- * to be of size n x m and the obtained W is n x r and H is r x m. The size r is
- * called the rank of the factorization.
- *
- * The implementation requires two template types; the first contains the update
- * rule for the W matrix during each iteration and the other contains the update
- * rule for the H matrix during each iteration.  This templatization allows the
- * user to try various update rules (including ones not supplied with MLPACK)
- * for factorization.
- *
- * A simple example of how to run NMF is shown below.
- *
- * @code
- * extern arma::mat V; // Matrix that we want to perform NMF on.
- * size_t r = 10; // Rank of decomposition
- * arma::mat W; // Basis matrix
- * arma::mat H; // Encoding matrix
- *
- * NMF<> nmf(); // Default options
- * nmf.Apply(V, W, H, r);
- * @endcode
- *
- * For more information on non-negative matrix factorization, see the following
- * paper:
- *
- * @code
- * @article{
- *   title = {{Learning the parts of objects by non-negative matrix
- *       factorization}},
- *   author = {Lee, Daniel D. and Seung, H. Sebastian},
- *   journal = {Nature},
- *   month = {Oct},
- *   year = {1999},
- *   number = {6755},
- *   pages = {788--791},
- *   publisher = {Nature Publishing Group},
- *   url = {http://dx.doi.org/10.1038/44565}
- * }
- * @endcode
- *
- * @tparam WUpdateRule The update rule for calculating W matrix at each
- *     iteration.
- * @tparam HUpdateRule The update rule for calculating H matrix at each
- *     iteration.
- *
- * @see WMultiplicativeDistanceRule, HMultiplicativeDistanceRule
- */
-template<typename InitializationRule = RandomInitialization,
-         typename WUpdateRule = WMultiplicativeDistanceRule,
-         typename HUpdateRule = HMultiplicativeDistanceRule>
-class NMF
-{
- public:
-  /**
-   * Create the NMF object and (optionally) set the parameters which NMF will
-   * run with.  The minimum residue refers to the root mean square of the
-   * difference between two subsequent iterations of the product W * H.  A low
-   * residue indicates that subsequent iterations are not producing much change
-   * in W and H.  Once the residue goes below the specified minimum residue, the
-   * algorithm terminates.
-   *
-   * @param maxIterations Maximum number of iterations allowed before giving up.
-   *     A value of 0 indicates no limit.
-   * @param minResidue The minimum allowed residue before the algorithm
-   *     terminates.
-   * @param Initialize Optional Initialization object for initializing the
-   *     W and H matrices
-   * @param WUpdate Optional WUpdateRule object; for when the update rule for
-   *     the W vector has states that it needs to store.
-   * @param HUpdate Optional HUpdateRule object; for when the update rule for
-   *     the H vector has states that it needs to store.
-   */
-  NMF(const size_t maxIterations = 10000,
-      const double minResidue = 1e-10,
-      const InitializationRule initializeRule = InitializationRule(),
-      const WUpdateRule wUpdate = WUpdateRule(),
-      const HUpdateRule hUpdate = HUpdateRule());
-
-  /**
-   * Apply Non-Negative Matrix Factorization to the provided matrix.
-   *
-   * @param V Input matrix to be factorized.
-   * @param W Basis matrix to be output.
-   * @param H Encoding matrix to output.
-   * @param r Rank r of the factorization.
-   */
-  template<typename MatType>
-  void Apply(const MatType& V,
-             const size_t r,
-             arma::mat& W,
-             arma::mat& H) const;
-
- private:
-  //! The maximum number of iterations allowed before giving up.
-  size_t maxIterations;
-  //! The minimum residue, below which iteration is considered converged.
-  double minResidue;
-  //! Instantiated initialization Rule.
-  InitializationRule initializeRule;
-  //! Instantiated W update rule.
-  WUpdateRule wUpdate;
-  //! Instantiated H update rule.
-  HUpdateRule hUpdate;
-
- public:
-  //! Access the maximum number of iterations.
-  size_t MaxIterations() const { return maxIterations; }
-  //! Modify the maximum number of iterations.
-  size_t& MaxIterations() { return maxIterations; }
-  //! Access the minimum residue before termination.
-  double MinResidue() const { return minResidue; }
-  //! Modify the minimum residue before termination.
-  double& MinResidue() { return minResidue; }
-  //! Access the initialization rule.
-  const InitializationRule& InitializeRule() const { return initializeRule; }
-  //! Modify the initialization rule.
-  InitializationRule& InitializeRule() { return initializeRule; }
-  //! Access the W update rule.
-  const WUpdateRule& WUpdate() const { return wUpdate; }
-  //! Modify the W update rule.
-  WUpdateRule& WUpdate() { return wUpdate; }
-  //! Access the H update rule.
-  const HUpdateRule& HUpdate() const { return hUpdate; }
-  //! Modify the H update rule.
-  HUpdateRule& HUpdate() { return hUpdate; }
-
-  // Returns a string representation of this object. 
-  std::string ToString() const;
-
-}; // class NMF
-
-}; // namespace nmf
-}; // namespace mlpack
-
-// Include implementation.
-#include "nmf_impl.hpp"
-
-#endif
diff --git a/src/mlpack/methods/nmf/nmf_impl.hpp b/src/mlpack/methods/nmf/nmf_impl.hpp
deleted file mode 100644
index 5cc097b..0000000
--- a/src/mlpack/methods/nmf/nmf_impl.hpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * @file nmf.cpp
- * @author Mohan Rajendran
- *
- * Implementation of NMF class to perform Non-Negative Matrix Factorization
- * on the given matrix.
- */
-
-namespace mlpack {
-namespace nmf {
-
-/**
- * Construct the NMF object.
- */
-template<typename InitializationRule,
-         typename WUpdateRule,
-         typename HUpdateRule>
-NMF<InitializationRule, WUpdateRule, HUpdateRule>::NMF(
-    const size_t maxIterations,
-    const double minResidue,
-    const InitializationRule initializeRule,
-    const WUpdateRule wUpdate,
-    const HUpdateRule hUpdate) :
-    maxIterations(maxIterations),
-    minResidue(minResidue),
-    initializeRule(initializeRule),
-    wUpdate(wUpdate),
-    hUpdate(hUpdate)
-{
-  if (minResidue < 0.0)
-  {
-    Log::Warn << "NMF::NMF(): minResidue must be a positive value ("
-        << minResidue << " given). Setting to the default value of 1e-10.\n";
-    this->minResidue = 1e-10;
-  }
-}
-
-/**
- * Apply Non-Negative Matrix Factorization to the provided matrix.
- *
- * @param V Input matrix to be factorized
- * @param W Basis matrix to be output
- * @param H Encoding matrix to output
- * @param r Rank r of the factorization
- */
-template<typename InitializationRule,
-         typename WUpdateRule,
-         typename HUpdateRule>
-template<typename MatType>
-void NMF<InitializationRule, WUpdateRule, HUpdateRule>::Apply(
-    const MatType& V,
-    const size_t r,
-    arma::mat& W,
-    arma::mat& H) const
-{
-  const size_t n = V.n_rows;
-  const size_t m = V.n_cols;
-
-  // Initialize W and H.
-  initializeRule.Initialize(V, r, W, H);
-
-  Log::Info << "Initialized W and H." << std::endl;
-
-  size_t iteration = 1;
-  const size_t nm = n * m;
-  double residue = minResidue;
-  double normOld = 0;
-  double norm = 0;
-  arma::mat WH;
-
-  while (residue >= minResidue && iteration != maxIterations)
-  {
-    // Update step.
-    // Update the value of W and H based on the Update Rules provided
-    wUpdate.Update(V, W, H);
-    hUpdate.Update(V, W, H);
-
-    // Calculate norm of WH after each iteration.
-    WH = W * H;
-    norm = sqrt(accu(WH % WH) / nm);
-
-    if (iteration != 0)
-    {
-      residue = fabs(normOld - norm);
-      residue /= normOld;
-    }
-
-    normOld = norm;
-
-    iteration++;
-  }
-
-  Log::Info << "NMF converged to residue of " << sqrt(residue) << " in "
-      << iteration << " iterations." << std::endl;
-}
-
-//Return a String of the object
-template<typename InitializationRule,
-         typename WUpdateRule,
-         typename HUpdateRule>
-std::string NMF<InitializationRule, WUpdateRule, HUpdateRule>::ToString() const
-{
-  std::ostringstream convert;
-  convert << "Non negative matrix factorization [" << this << "]" << std::endl;
-  convert << "  Max Iterations: " << maxIterations << std::endl;
-  convert << "  Minimum Residue: " << minResidue<< std::endl;
-  return convert.str();
-}
-
-}; // namespace nmf
-}; // namespace mlpack
diff --git a/src/mlpack/methods/nmf/nmf_main.cpp b/src/mlpack/methods/nmf/nmf_main.cpp
index feddb7a..10562e8 100644
--- a/src/mlpack/methods/nmf/nmf_main.cpp
+++ b/src/mlpack/methods/nmf/nmf_main.cpp
@@ -6,15 +6,15 @@
  */
 #include <mlpack/core.hpp>
 
-#include "nmf.hpp"
+#include <mlpack/methods/amf/amf.hpp>
 
-#include "random_init.hpp"
-#include "mult_dist_update_rules.hpp"
-#include "mult_div_update_rules.hpp"
-#include "als_update_rules.hpp"
+#include <mlpack/methods/amf/init_rules/random_init.hpp>
+#include <mlpack/methods/amf/update_rules/nmf_mult_dist.hpp>
+#include <mlpack/methods/amf/update_rules/nmf_mult_div.hpp>
+#include <mlpack/methods/amf/update_rules/nmf_als.hpp>
 
 using namespace mlpack;
-using namespace mlpack::nmf;
+using namespace mlpack::amf;
 using namespace std;
 
 // Document program.
@@ -104,26 +104,22 @@ int main(int argc, char** argv)
   {
     Log::Info << "Performing NMF with multiplicative distance-based update "
         << "rules." << std::endl;
-    NMF<> nmf(maxIterations, minResidue);
-    nmf.Apply(V, r, W, H);
+    AMF<> amf(maxIterations, minResidue);
+    amf.Apply(V, r, W, H);
   }
   else if (updateRules == "multdiv")
   {
     Log::Info << "Performing NMF with multiplicative divergence-based update "
         << "rules." << std::endl;
-    NMF<RandomInitialization,
-        WMultiplicativeDivergenceRule,
-        HMultiplicativeDivergenceRule> nmf(maxIterations, minResidue);
-    nmf.Apply(V, r, W, H);
+    AMF<RandomInitialization, NMFMultiplicativeDivergenceUpdate> amf(maxIterations, minResidue);
+    amf.Apply(V, r, W, H);
   }
   else if (updateRules == "als")
   {
     Log::Info << "Performing NMF with alternating least squared update rules."
         << std::endl;
-    NMF<RandomInitialization,
-        WAlternatingLeastSquaresRule,
-        HAlternatingLeastSquaresRule> nmf(maxIterations, minResidue);
-    nmf.Apply(V, r, W, H);
+    AMF<RandomInitialization, NMFALSUpdate> amf(maxIterations, minResidue);
+    amf.Apply(V, r, W, H);
   }
 
   // Save results.
diff --git a/src/mlpack/tests/nmf_test.cpp b/src/mlpack/tests/nmf_test.cpp
index 30f0720..4408dd3 100644
--- a/src/mlpack/tests/nmf_test.cpp
+++ b/src/mlpack/tests/nmf_test.cpp
@@ -5,10 +5,10 @@
  * Test file for NMF class.
  */
 #include <mlpack/core.hpp>
-#include <mlpack/methods/nmf/nmf.hpp>
-#include <mlpack/methods/nmf/random_acol_init.hpp>
-#include <mlpack/methods/nmf/mult_div_update_rules.hpp>
-#include <mlpack/methods/nmf/als_update_rules.hpp>
+#include <mlpack/methods/amf/amf.hpp>
+#include <mlpack/methods/amf/init_rules/random_acol_init.hpp>
+#include <mlpack/methods/amf/update_rules/nmf_mult_div.hpp>
+#include <mlpack/methods/amf/update_rules/nmf_als.hpp>
 
 #include <boost/test/unit_test.hpp>
 #include "old_boost_test_definitions.hpp"
@@ -18,7 +18,7 @@ BOOST_AUTO_TEST_SUITE(NMFTest);
 using namespace std;
 using namespace arma;
 using namespace mlpack;
-using namespace mlpack::nmf;
+using namespace mlpack::amf;
 
 /**
  * Check the if the product of the calculated factorization is close to the
@@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(NMFDefaultTest)
   mat v = w * h;
   size_t r = 16;
 
-  NMF<> nmf;
+  AMF<> nmf;
   nmf.Apply(v, r, w, h);
 
   mat wh = w * h;
@@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(NMFAcolDistTest)
   mat v = w * h;
   size_t r = 16;
 
-  NMF<RandomAcolInitialization<> > nmf;
+  AMF<RandomAcolInitialization<> > nmf;
   nmf.Apply(v, r, w, h);
 
   mat wh = w * h;
@@ -73,9 +73,7 @@ BOOST_AUTO_TEST_CASE(NMFRandomDivTest)
   mat v = w * h;
   size_t r = 16;
 
-  NMF<RandomInitialization,
-      WMultiplicativeDivergenceRule,
-      HMultiplicativeDivergenceRule> nmf;
+  AMF<RandomInitialization, NMFMultiplicativeDivergenceUpdate> nmf;
   nmf.Apply(v, r, w, h);
 
   mat wh = w * h;
@@ -97,9 +95,7 @@ BOOST_AUTO_TEST_CASE(NMFALSTest)
   mat v = w * h;
   size_t r = 16;
 
-  NMF<RandomInitialization,
-      WAlternatingLeastSquaresRule,
-      HAlternatingLeastSquaresRule> nmf(50000, 1e-15);
+  AMF<RandomInitialization, NMFALSUpdate> nmf(50000, 1e-15);
   nmf.Apply(v, r, w, h);
 
   const mat wh = w * h;
@@ -125,7 +121,7 @@ BOOST_AUTO_TEST_CASE(SparseNMFDefaultTest)
   size_t r = 18;
 
   // It seems to hit the iteration limit first.
-  NMF<> nmf(10000, 1e-20);
+  AMF<> nmf(10000, 1e-20);
   mlpack::math::RandomSeed(1000); // Set random seed so results are the same.
   nmf.Apply(v, r, w, h);
   mlpack::math::RandomSeed(1000);
@@ -163,7 +159,7 @@ BOOST_AUTO_TEST_CASE(SparseNMFAcolDistTest)
   mat dw, dh;
   size_t r = 16;
 
-  NMF<RandomAcolInitialization<> > nmf;
+  AMF<RandomAcolInitialization<> > nmf;
   mlpack::math::RandomSeed(1000); // Set random seed so results are the same.
   nmf.Apply(v, r, w, h);
   mlpack::math::RandomSeed(1000);
@@ -201,9 +197,7 @@ BOOST_AUTO_TEST_CASE(SparseNMFRandomDivTest)
   mat dw, dh;
   size_t r = 16;
 
-  NMF<RandomInitialization,
-      WMultiplicativeDivergenceRule,
-      HMultiplicativeDivergenceRule> nmf;
+  AMF<RandomInitialization, NMFMultiplicativeDivergenceUpdate> nmf;
   mlpack::math::RandomSeed(10); // Set random seed so the results are the same.
   nmf.Apply(v, r, w, h);
   mlpack::math::RandomSeed(10);
@@ -241,9 +235,7 @@ BOOST_AUTO_TEST_CASE(SparseNMFALSTest)
   mat dw, dh;
   size_t r = 8;
 
-  NMF<RandomInitialization,
-      WAlternatingLeastSquaresRule,
-      HAlternatingLeastSquaresRule> nmf;
+  AMF<RandomInitialization, NMFALSUpdate> nmf;
   mlpack::math::RandomSeed(40);
   nmf.Apply(v, r, w, h);
   mlpack::math::RandomSeed(40);
diff --git a/src/mlpack/tests/to_string_test.cpp b/src/mlpack/tests/to_string_test.cpp
index 1a61574..0b86d18 100644
--- a/src/mlpack/tests/to_string_test.cpp
+++ b/src/mlpack/tests/to_string_test.cpp
@@ -47,7 +47,7 @@
 #include <mlpack/methods/logistic_regression/logistic_regression.hpp>
 #include <mlpack/methods/lsh/lsh_search.hpp>
 #include <mlpack/methods/neighbor_search/neighbor_search.hpp>
-#include <mlpack/methods/nmf/nmf.hpp>
+#include <mlpack/methods/amf/amf.hpp>
 #include <mlpack/methods/nca/nca.hpp>
 #include <mlpack/methods/pca/pca.hpp>
 #include <mlpack/methods/radical/radical.hpp>
@@ -428,15 +428,17 @@ BOOST_AUTO_TEST_CASE(NeighborString)
   BOOST_REQUIRE_NE(s, "");
 }
 
+/*
 BOOST_AUTO_TEST_CASE(NMFString)
 {
   arma::mat c(40, 40);
   c.randn();
-  mlpack::nmf::NMF<> d;
+  mlpack::amf::AMF<> d;
   Log::Debug << d;
   std::string s = d.ToString();
   BOOST_REQUIRE_NE(s, "");
 }
+*/
 
 BOOST_AUTO_TEST_CASE(NCAString)
 {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list