[mlpack-git] master: * Refactoring CF module * CleanData function made static * Added overload of CF constructor which accepts user cleaned matrix if supported by the factorizer (436c65b)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu May 21 21:05:10 EDT 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/7e9cd46afb53817ae93ccbd02637d7726137ce4d...d2f2976c7a43f8ab9139064ae33304bcf9f4f884

>---------------------------------------------------------------

commit 436c65b6f83457ef594662734c8af23c545ce503
Author: sumedhghaisas <sumedhghaisas at gmail.com>
Date:   Tue Apr 28 07:49:46 2015 +0530

    * Refactoring CF module
     * CleanData function made static
     * Added overload of CF constructor which accepts user cleaned matrix if supported by the factorizer


>---------------------------------------------------------------

436c65b6f83457ef594662734c8af23c545ce503
 src/mlpack/methods/cf/cf.hpp      | 10 ++++++++--
 src/mlpack/methods/cf/cf_impl.hpp | 18 ++++++++----------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/mlpack/methods/cf/cf.hpp b/src/mlpack/methods/cf/cf.hpp
index 61b9135..835c62a 100644
--- a/src/mlpack/methods/cf/cf.hpp
+++ b/src/mlpack/methods/cf/cf.hpp
@@ -101,7 +101,9 @@ class CF
    * be set; default values are provided for each of them. If the rank is left
    * unset (or is set to 0), a simple density-based heuristic will be used to
    * choose a rank. Data will be considered in the format of items vs. users and 
-   * will be passed directly to the factorizer without cleaning.
+   * will be passed directly to the factorizer without cleaning. This overload 
+   * of constructor will only be available if the factorizer does not require
+   * coordinate list.
    *
    * @param data Initial (user, item, rating) matrix.
    * @param factorizer Instantiated factorizer object.
@@ -109,7 +111,11 @@ class CF
    * @param rank Rank parameter for matrix factorization.
    * @param isCleaned If the data passed is cleaned for CF
    */
-  CF(arma::sp_mat& data,
+  template<typename U = FactorizerType, 
+           class = typename boost::enable_if_c<
+                   !FactorizerTraits<U>::UsesCoordinateList,
+                   int*>::type>
+  CF(const arma::sp_mat& data,
      FactorizerType factorizer = FactorizerType(),
      const size_t numUsersForSimilarity = 5,
      const size_t rank = 0);
diff --git a/src/mlpack/methods/cf/cf_impl.hpp b/src/mlpack/methods/cf/cf_impl.hpp
index 0b0eee4..63dbbbd 100644
--- a/src/mlpack/methods/cf/cf_impl.hpp
+++ b/src/mlpack/methods/cf/cf_impl.hpp
@@ -63,8 +63,7 @@ template<typename FactorizerType>
 CF<FactorizerType>::CF(arma::mat& data,
                        FactorizerType factorizer,
                        const size_t numUsersForSimilarity,
-                       const size_t rank,
-                       bool isCleaned) :
+                       const size_t rank) :
     numUsersForSimilarity(numUsersForSimilarity),
     rank(rank),
     factorizer(factorizer)
@@ -104,10 +103,11 @@ CF<FactorizerType>::CF(arma::mat& data,
  * Construct the CF object using an instantiated factorizer.
  */
 template<typename FactorizerType>
-CF<FactorizerType>::CF(arma::mat& data,
-                       FactorizerType factorizer,
-                       const size_t numUsersForSimilarity,
-                       const size_t rank) :
+template<typename U, class>
+CF<FactorizerType>::CF(const arma::sp_mat& data,
+            FactorizerType factorizer,
+            const size_t numUsersForSimilarity,
+            const size_t rank) :
     numUsersForSimilarity(numUsersForSimilarity),
     rank(rank),
     factorizer(factorizer)
@@ -121,7 +121,7 @@ CF<FactorizerType>::CF(arma::mat& data,
     this->numUsersForSimilarity = 5;
   }
 
-  CleanData(data, cleanedData);
+  cleanedData = data;
 
   // Check if the user wanted us to choose a rank for them.
   if (rank == 0)
@@ -138,9 +138,7 @@ CF<FactorizerType>::CF(arma::mat& data,
     this->rank = rankEstimate;
   }
 
-  // Operations independent of the query:
-  // Decompose the sparse data matrix to user and data matrices.
-  ApplyFactorizer<FactorizerType>(data, cleanedData, factorizer, this->rank, w, h);
+  factorizer.Apply(cleanedData, rank, w, h);
 }
 
 template<typename FactorizerType>



More information about the mlpack-git mailing list