[mlpack-svn] r15878 - mlpack/trunk/src/mlpack/methods/cf

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Sep 30 16:49:53 EDT 2013


Author: rcurtin
Date: Mon Sep 30 16:49:53 2013
New Revision: 15878

Log:
Inline CreateQuery() function since it is only used once, and use better
Armadillo functions to make the generation cleaner-looking (probably no
speedup).


Modified:
   mlpack/trunk/src/mlpack/methods/cf/cf.cpp
   mlpack/trunk/src/mlpack/methods/cf/cf.hpp

Modified: mlpack/trunk/src/mlpack/methods/cf/cf.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/cf/cf.cpp	(original)
+++ mlpack/trunk/src/mlpack/methods/cf/cf.cpp	Mon Sep 30 16:49:53 2013
@@ -165,10 +165,11 @@
                arma::Col<size_t>& users)
 {
   // Temporarily store feature vector of queried users.
-  arma::mat query(rating.n_rows, users.n_rows);
+  arma::mat query(rating.n_rows, users.n_elem);
 
-  // Calculate the feature vector of queried users.
-  CreateQuery(query, users);
+  // Select feature vectors of queried users.
+  for (size_t i = 0; i < users.n_elem; i++)
+    query.col(i) = rating.col(users(i) - 1);
 
   // Temporary storage for neighborhood of the queried users.
   arma::Mat<size_t> neighborhood;
@@ -187,16 +188,6 @@
   CalculateTopRecommendations(recommendations, averages, users);
 }
 
-void CF::CreateQuery(arma::mat& query,arma::Col<size_t>& users) const
-{
-  Log::Info<<"CreateQuery"<<endl;
-  //Selecting feature vectors of queried users
-  for(size_t i=0;i<users.n_rows;i++)
-    for(size_t j=0;j<rating.col(i).n_rows;j++)
-      query(j,i) = rating(j,users(i)-1);
-  //data::Save("query.csv",query);
-}
-
 void CF::GetNeighbourhood(arma::mat& query,
                          arma::Mat<size_t>& neighbourhood)
 {

Modified: mlpack/trunk/src/mlpack/methods/cf/cf.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/cf/cf.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/cf/cf.hpp	Mon Sep 30 16:49:53 2013
@@ -204,14 +204,6 @@
   void Query(arma::Mat<size_t>& recommendations,arma::Col<size_t>& users);
 
   /**
-   * Selects item preferences of the users
-   *
-   * @param query Matrix to store the item preference of the user.
-   * @param users Users for which recommendations are to be generated
-   */
-  void CreateQuery(arma::mat& query,arma::Col<size_t>& users) const;
-
-  /**
    * Generates the neighbourhood of users.
    *
    * @param query Matrix to store the item preference of the user.



More information about the mlpack-svn mailing list