From 017c206cbfa62011d463fd5dfa016894e952e1ba Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Mon, 30 Sep 2013 17:26:01 +0000 Subject: [PATCH] Clean up CleanData() function. Don't use temporary matrices; there's no point to doing that. --- src/mlpack/methods/cf/cf.cpp | 52 +++++++++++++++--------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/src/mlpack/methods/cf/cf.cpp b/src/mlpack/methods/cf/cf.cpp index 37bbeb2828..869b17690d 100644 --- a/src/mlpack/methods/cf/cf.cpp +++ b/src/mlpack/methods/cf/cf.cpp @@ -132,38 +132,30 @@ void CF::GetRecommendations(arma::Mat& recommendations, void CF::CleanData() { - Log::Info<<"CleanData"; - //Temporarily stores max user id - double maxUserID; - //Temporarily stores max item id - double maxItemID; - //Calculating max users and items - maxUserID = data(0,0); - maxItemID = data(1,0); - for (size_t i=1;imaxUserID) - maxUserID = data(0,i); - if(data(1,i)>maxItemID) - maxItemID = data(1,i); + if (data(0, i) > maxUserID) + maxUserID = data(0, i); + if (data(1, i) > maxItemID) + maxItemID = data(1, i); } - //Temporarily stores sparcely populated rating matrix - arma::sp_mat tmp((size_t)maxItemID,(size_t)maxUserID); - //Temporarily stores mask matrix - arma::mat lMask = arma::ones((size_t)maxItemID, - (size_t)maxUserID); - //Calculates the initial User-Item table - for (size_t i=0;i((size_t) maxItemID, + (size_t) maxUserID); + // Calculates the initial User-Item table + for (size_t i = 0; i < data.n_cols; i++) + cleanedData(data(1, i) - 1, data(0, i) - 1) = data(2, i); + // Populate mask. + for (size_t i = 0; i < data.n_cols; i++) + mask(data(1, i) - 1, data(0, i) - 1) = -1.0; } void CF::Decompose()