From bb35bc4e9a23edd8806d8c4216ea55bdc357df2f Mon Sep 17 00:00:00 2001 From: Khizir Siddiqui Date: Thu, 2 Jan 2020 16:01:57 +0530 Subject: [PATCH 01/10] add norm to cfmodel and cli --- src/mlpack/methods/cf/cf_main.cpp | 19 ++++- src/mlpack/methods/cf/cf_model.hpp | 92 +++++++++++++++++++------ src/mlpack/methods/cf/cf_model_impl.hpp | 54 +++++++++++---- 3 files changed, 128 insertions(+), 37 deletions(-) diff --git a/src/mlpack/methods/cf/cf_main.cpp b/src/mlpack/methods/cf/cf_main.cpp index 726535fb96..c73ff57f92 100644 --- a/src/mlpack/methods/cf/cf_main.cpp +++ b/src/mlpack/methods/cf/cf_main.cpp @@ -100,6 +100,15 @@ PROGRAM_INFO("Collaborative Filtering", " - 'average' -- Average Interpolation Algorithm\n" " - 'regression' -- Regression Interpolation Algorithm\n" " - 'similarity' -- Similarity Interpolation Algorithm\n" + "\n\n" + "The following ranking normalization algorithms can be specified via" + + " the " + PRINT_PARAM_STRING("normalization") + " parameter:" + "\n" + " - 'none' -- No Normalization\n" + " - 'itemMean' -- Item Mean Normalization\n" + " - 'overallMean' -- Overall Mean Normalization\n" + " - 'userMean' -- User Mean Normalization\n" + " - 'zScore' -- Z-Score Normalization\n" "\n" "A trained model may be saved to with the " + PRINT_PARAM_STRING("output_model") + " output parameter." @@ -136,6 +145,8 @@ PROGRAM_INFO("Collaborative Filtering", PARAM_MATRIX_IN("training", "Input dataset to perform CF on.", "t"); PARAM_STRING_IN("algorithm", "Algorithm used for matrix factorization.", "a", "NMF"); +PARAM_STRING_IN("normalization", "Normalization performed on the ratings.", "z", + "none"); PARAM_INT_IN("neighborhood", "Size of the neighborhood of similar users to " "consider for each query user.", "n", 5); PARAM_INT_IN("rank", "Rank of decomposed matrices (if 0, a heuristic is used to" @@ -364,7 +375,7 @@ void PerformAction(CFModel* c) CLI::GetParam("output_model") = c; } -template +template void PerformAction(arma::mat& dataset, const size_t rank, const size_t maxIterations, @@ -372,8 +383,12 @@ void PerformAction(arma::mat& dataset, { const size_t neighborhood = (size_t) CLI::GetParam("neighborhood"); CFModel* c = new CFModel(); + + const string normalizationType = CLI::GetParam("normalization"); + c->template Train(dataset, neighborhood, rank, - maxIterations, minResidue, CLI::HasParam("iteration_only_termination")); + maxIterations, minResidue, CLI::HasParam("iteration_only_termination"), + normalizationType); PerformAction(c); } diff --git a/src/mlpack/methods/cf/cf_model.hpp b/src/mlpack/methods/cf/cf_model.hpp index ef1ebac214..94858957d8 100644 --- a/src/mlpack/methods/cf/cf_model.hpp +++ b/src/mlpack/methods/cf/cf_model.hpp @@ -24,6 +24,13 @@ #include #include +#include +#include +#include +#include +#include +#include + namespace mlpack { namespace cf { @@ -35,8 +42,9 @@ class DeleteVisitor : public boost::static_visitor { public: //! Delete CFType object. - template - void operator()(CFType* c) const; + template + void operator()(CFType* c) const; }; /** @@ -46,8 +54,9 @@ class GetValueVisitor : public boost::static_visitor { public: //! Return stored pointer as void* type. - template - void* operator()(CFType* c) const; + template + void* operator()(CFType* c) const; }; /** @@ -66,8 +75,9 @@ class PredictVisitor : public boost::static_visitor public: //! Predict ratings for each user-item combination. - template - void operator()(CFType* c) const; + template + void operator()(CFType* c) const; //! Visitor constructor. PredictVisitor(const arma::Mat& combinations, @@ -100,8 +110,9 @@ class RecommendationVisitor : public boost::static_visitor const bool usersGiven); //! Generates the given number of recommendations. - template - void operator()(CFType* c) const; + template + void operator()(CFType* c) const; }; /** @@ -112,17 +123,54 @@ class CFModel private: /** * cf holds an instance of the CFType class for the current - * decompositionPolicy. It is initialized every time Train() is executed. - * We access to the contained value through the visitor classes defined above. + * decompositionPolicy and normalizationType. It is initialized every time + * Train() is executed. We access to the contained value through the visitor + * classes defined above. */ - boost::variant*, - CFType*, - CFType*, - CFType*, - CFType*, - CFType*, - CFType*, - CFType*> cf; + boost::variant*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*, + CFType*> cf; public: //! Create an empty CF model. @@ -132,8 +180,9 @@ class CFModel ~CFModel(); //! Get the pointer to CFType<> object. - template - const CFType* CFPtr() const; + template + const CFType* CFPtr() const; //! Train the model. template +#include +#include +#include +#include +#include +#include + using namespace mlpack::cf; -template -void DeleteVisitor::operator()(CFType* c) const +template +void DeleteVisitor::operator()(CFType* c) const { if (c) delete c; } -template -void* GetValueVisitor::operator()(CFType* c) const +template +void* GetValueVisitor::operator()(CFType* c) const { if (!c) throw std::runtime_error("no cf model initialized"); @@ -45,9 +54,10 @@ PredictVisitor::PredictVisitor( template -template +template void PredictVisitor - ::operator()(CFType* c) const + ::operator()(CFType* c) const { if (!c) { @@ -75,9 +85,10 @@ RecommendationVisitor template -template +template void RecommendationVisitor - ::operator()(CFType* c) const + ::operator()(CFType* c) const { if (!c) { @@ -105,15 +116,29 @@ void CFModel::Train(const MatType& data, const size_t rank, const size_t maxIterations, const double minResidue, - const bool mit) + const bool mit, + const string normalization = "none") { // Delete the current CFType object, if there is one. boost::apply_visitor(DeleteVisitor(), cf); // Instantiate a new CFType object. DecompositionPolicy decomposition; - cf = new CFType(data, decomposition, - numUsersForSimilarity, rank, maxIterations, minResidue, mit); + if (normalization == "overallMean") + cf = new CFType(data, decomposition, + numUsersForSimilarity, rank, maxIterations, minResidue, mit); + else if (normalization == "itemMean") + cf = new CFType(data, decomposition, + numUsersForSimilarity, rank, maxIterations, minResidue, mit); + else if (normalization == "userMean") + cf = new CFType(data, decomposition, + numUsersForSimilarity, rank, maxIterations, minResidue, mit); + else if (normalization == "zScore") + cf = new CFType(data, decomposition, + numUsersForSimilarity, rank, maxIterations, minResidue, mit); + else + cf = new CFType(data, decomposition, + numUsersForSimilarity, rank, maxIterations, minResidue, mit); } //! Make predictions. @@ -151,11 +176,12 @@ void CFModel::GetRecommendations(const size_t numRecs, boost::apply_visitor(recommendation, cf); } -template -const CFType* CFModel::CFPtr() const +template +const CFType* CFModel::CFPtr() const { void* pointer = boost::apply_visitor(GetValueVisitor(), cf); - return (CFType*) pointer; + return (CFType*) pointer; } template From 77b6c4e9b6eb1ae0902d6b8027179aada73044a3 Mon Sep 17 00:00:00 2001 From: Khizir Siddiqui Date: Thu, 2 Jan 2020 16:38:13 +0530 Subject: [PATCH 02/10] style fix and make str as address --- src/mlpack/methods/cf/cf_model.hpp | 4 +-- src/mlpack/methods/cf/cf_model_impl.hpp | 33 +++++++++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/mlpack/methods/cf/cf_model.hpp b/src/mlpack/methods/cf/cf_model.hpp index 94858957d8..7d4b18ef53 100644 --- a/src/mlpack/methods/cf/cf_model.hpp +++ b/src/mlpack/methods/cf/cf_model.hpp @@ -144,7 +144,7 @@ class CFModel CFType*, CFType*, CFType*, - + CFType*, CFType*, CFType*, @@ -193,7 +193,7 @@ class CFModel const size_t maxIterations, const double minResidue, const bool mit, - const string normalizationType = "none"); + const std::string& normalizationType = "none"); //! Make predictions. template -void DeleteVisitor::operator()(CFType* c) const +void DeleteVisitor:: +operator()(CFType* c) const { if (c) delete c; @@ -35,7 +36,8 @@ void DeleteVisitor::operator()(CFType* c template -void* GetValueVisitor::operator()(CFType* c) const +void* GetValueVisitor:: +operator()(CFType* c) const { if (!c) throw std::runtime_error("no cf model initialized"); @@ -117,7 +119,7 @@ void CFModel::Train(const MatType& data, const size_t maxIterations, const double minResidue, const bool mit, - const string normalization = "none") + const std::string& normalization = "none") { // Delete the current CFType object, if there is one. boost::apply_visitor(DeleteVisitor(), cf); @@ -125,20 +127,25 @@ void CFModel::Train(const MatType& data, // Instantiate a new CFType object. DecompositionPolicy decomposition; if (normalization == "overallMean") - cf = new CFType(data, decomposition, - numUsersForSimilarity, rank, maxIterations, minResidue, mit); + cf = new CFType(data, + decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, + mit); else if (normalization == "itemMean") - cf = new CFType(data, decomposition, - numUsersForSimilarity, rank, maxIterations, minResidue, mit); + cf = new CFType(data, + decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, + mit); else if (normalization == "userMean") - cf = new CFType(data, decomposition, - numUsersForSimilarity, rank, maxIterations, minResidue, mit); + cf = new CFType(data, + decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, + mit); else if (normalization == "zScore") - cf = new CFType(data, decomposition, - numUsersForSimilarity, rank, maxIterations, minResidue, mit); + cf = new CFType(data, + decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, + mit); else - cf = new CFType(data, decomposition, - numUsersForSimilarity, rank, maxIterations, minResidue, mit); + cf = new CFType(data, + decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, + mit); } //! Make predictions. From e1e6521d92657e889b21aaad86ae4b7cb2cfce6e Mon Sep 17 00:00:00 2001 From: Khizir Siddiqui Date: Thu, 2 Jan 2020 16:43:53 +0530 Subject: [PATCH 03/10] fix redeclaration error --- src/mlpack/methods/cf/cf_model_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/cf/cf_model_impl.hpp b/src/mlpack/methods/cf/cf_model_impl.hpp index 5f9f090b93..8ec13cb396 100644 --- a/src/mlpack/methods/cf/cf_model_impl.hpp +++ b/src/mlpack/methods/cf/cf_model_impl.hpp @@ -119,7 +119,7 @@ void CFModel::Train(const MatType& data, const size_t maxIterations, const double minResidue, const bool mit, - const std::string& normalization = "none") + const std::string& normalization) { // Delete the current CFType object, if there is one. boost::apply_visitor(DeleteVisitor(), cf); From 3d6a802a252df1f34465209b47d5ed2c18e9dfc0 Mon Sep 17 00:00:00 2001 From: Khizir Siddiqui Date: Thu, 2 Jan 2020 23:47:56 +0530 Subject: [PATCH 04/10] add default normalization as nonorm --- src/mlpack/methods/cf/cf_model.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mlpack/methods/cf/cf_model.hpp b/src/mlpack/methods/cf/cf_model.hpp index 7d4b18ef53..26a7c4b885 100644 --- a/src/mlpack/methods/cf/cf_model.hpp +++ b/src/mlpack/methods/cf/cf_model.hpp @@ -43,7 +43,7 @@ class DeleteVisitor : public boost::static_visitor public: //! Delete CFType object. template + typename NormalizationType = NoNormalization> void operator()(CFType* c) const; }; @@ -55,7 +55,7 @@ class GetValueVisitor : public boost::static_visitor public: //! Return stored pointer as void* type. template + typename NormalizationType = NoNormalization> void* operator()(CFType* c) const; }; @@ -76,7 +76,7 @@ class PredictVisitor : public boost::static_visitor public: //! Predict ratings for each user-item combination. template + typename NormalizationType = NoNormalization> void operator()(CFType* c) const; //! Visitor constructor. @@ -111,7 +111,7 @@ class RecommendationVisitor : public boost::static_visitor //! Generates the given number of recommendations. template + typename NormalizationType = NoNormalization> void operator()(CFType* c) const; }; @@ -181,7 +181,7 @@ class CFModel //! Get the pointer to CFType<> object. template + typename NormalizationType = NoNormalization> const CFType* CFPtr() const; //! Train the model. From d5990eab30343bc3090f5b596020129ca77f0647 Mon Sep 17 00:00:00 2001 From: Khizir Siddiqui Date: Sun, 5 Jan 2020 13:40:58 +0530 Subject: [PATCH 05/10] undo space between typename and template name --- src/mlpack/methods/cf/cf_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/methods/cf/cf_main.cpp b/src/mlpack/methods/cf/cf_main.cpp index c73ff57f92..1653643fc1 100644 --- a/src/mlpack/methods/cf/cf_main.cpp +++ b/src/mlpack/methods/cf/cf_main.cpp @@ -375,7 +375,7 @@ void PerformAction(CFModel* c) CLI::GetParam("output_model") = c; } -template +template void PerformAction(arma::mat& dataset, const size_t rank, const size_t maxIterations, From 699a437e8cda2a7bcd40197b3ad3f9c7fab96ee1 Mon Sep 17 00:00:00 2001 From: Khizir Siddiqui Date: Sun, 5 Jan 2020 13:41:32 +0530 Subject: [PATCH 06/10] add braces for better readibility and name --- src/mlpack/methods/cf/cf_model.hpp | 1 + src/mlpack/methods/cf/cf_model_impl.hpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/mlpack/methods/cf/cf_model.hpp b/src/mlpack/methods/cf/cf_model.hpp index 26a7c4b885..35bd0ae944 100644 --- a/src/mlpack/methods/cf/cf_model.hpp +++ b/src/mlpack/methods/cf/cf_model.hpp @@ -1,6 +1,7 @@ /** * @file cf_model.hpp * @author Wenhao Huang + * @author Khizir Siddiqui * * A serializable CF model, used by the main program. * diff --git a/src/mlpack/methods/cf/cf_model_impl.hpp b/src/mlpack/methods/cf/cf_model_impl.hpp index 8ec13cb396..bb08647422 100644 --- a/src/mlpack/methods/cf/cf_model_impl.hpp +++ b/src/mlpack/methods/cf/cf_model_impl.hpp @@ -127,25 +127,35 @@ void CFModel::Train(const MatType& data, // Instantiate a new CFType object. DecompositionPolicy decomposition; if (normalization == "overallMean") + { cf = new CFType(data, decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, mit); + } else if (normalization == "itemMean") + { cf = new CFType(data, decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, mit); + } else if (normalization == "userMean") + { cf = new CFType(data, decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, mit); + } else if (normalization == "zScore") + { cf = new CFType(data, decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, mit); + } else + { cf = new CFType(data, decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, mit); + } } //! Make predictions. From a767ed44f46a6635d6aa7410273c125c9f03ef2c Mon Sep 17 00:00:00 2001 From: Khizir Siddiqui Date: Sun, 12 Jan 2020 01:13:05 +0530 Subject: [PATCH 07/10] add test --- src/mlpack/methods/cf/cf_model_impl.hpp | 7 +- src/mlpack/tests/main_tests/cf_test.cpp | 98 +++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/src/mlpack/methods/cf/cf_model_impl.hpp b/src/mlpack/methods/cf/cf_model_impl.hpp index bb08647422..ebec1c80bd 100644 --- a/src/mlpack/methods/cf/cf_model_impl.hpp +++ b/src/mlpack/methods/cf/cf_model_impl.hpp @@ -150,12 +150,17 @@ void CFModel::Train(const MatType& data, decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, mit); } - else + else if (normalization == "none") { cf = new CFType(data, decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, mit); } + else + { + throw std::runtime_error("Unsupported Normalization Algorithm." + "Please refer to help (-h) section for details"); + } } //! Make predictions. diff --git a/src/mlpack/tests/main_tests/cf_test.cpp b/src/mlpack/tests/main_tests/cf_test.cpp index 8a9837800d..a8031aabd5 100644 --- a/src/mlpack/tests/main_tests/cf_test.cpp +++ b/src/mlpack/tests/main_tests/cf_test.cpp @@ -616,4 +616,102 @@ BOOST_AUTO_TEST_CASE(CFNeighborSearchTest) BOOST_REQUIRE(arma::any(arma::vectorise(output1 != output3))); } +/** + * Ensure normalization algorithm is one of { "none", "zScore", + * "itemMean", "userMean" }. + */ +BOOST_AUTO_TEST_CASE(CFNormalizationBoundTest) +{ + mat dataset; + data::Load("GroupLensSmall.csv", dataset); + + const int querySize = 7; + Mat query = arma::linspace>(0, querySize - 1, querySize); + + SetInputParam("neighbor_search", std::string("cosine")); + SetInputParam("algorithm", std::string("NMF")); + + // normalization algorithm should be valid. + SetInputParam("normalization", std::string("invalid_normalization")); + SetInputParam("training", std::move(dataset)); + SetInputParam("query", query); + + Log::Fatal.ignoreInput = true; + BOOST_REQUIRE_THROW(mlpackMain(), std::runtime_error); + Log::Fatal.ignoreInput = false; +} + +/** + * Ensure that using normalization techniques make difference. + */ +BOOST_AUTO_TEST_CASE(CFNormalizationTest) +{ + mat dataset; + data::Load("GroupLensSmall.csv", dataset); + + const int querySize = 7; + Mat query = arma::linspace>(0, querySize - 1, querySize); + + // Query with different normalization techniques. + ResetSettings(); + + SetInputParam("training", dataset); + SetInputParam("max_iterations", int(10)); + SetInputParam("query", query); + SetInputParam("algorithm", std::string("NMF")); + + // Using without Normalization. + SetInputParam("normalization", std::string("none")); + SetInputParam("recommendations", 5); + + mlpackMain(); + + const arma::Mat output1 = CLI::GetParam>("output"); + + BOOST_REQUIRE_EQUAL(output1.n_rows, 5); + BOOST_REQUIRE_EQUAL(output1.n_cols, 7); + + // Query with different normalization techniques. + ResetSettings(); + + SetInputParam("training", dataset); + SetInputParam("max_iterations", int(10)); + SetInputParam("query", query); + SetInputParam("algorithm", std::string("NMF")); + + // Using without Normalization. + SetInputParam("normalization", std::string("itemMean")); + SetInputParam("recommendations", 5); + + mlpackMain(); + + const arma::Mat output2 = CLI::GetParam>("output"); + + BOOST_REQUIRE_EQUAL(output2.n_rows, 5); + BOOST_REQUIRE_EQUAL(output2.n_cols, 7); + + // Query with different normalization techniques. + ResetSettings(); + + SetInputParam("training", dataset); + SetInputParam("max_iterations", int(10)); + SetInputParam("query", query); + SetInputParam("algorithm", std::string("NMF")); + + // Using without Normalization. + SetInputParam("normalization", std::string("zScore")); + SetInputParam("recommendations", 5); + + mlpackMain(); + + const arma::Mat output3 = CLI::GetParam>("output"); + + BOOST_REQUIRE_EQUAL(output3.n_rows, 5); + BOOST_REQUIRE_EQUAL(output3.n_cols, 7); + + // The resulting matrices should be different. + BOOST_REQUIRE(arma::any(arma::vectorise(output1 != output2))); + BOOST_REQUIRE(arma::any(arma::vectorise(output1 != output3))); +} + BOOST_AUTO_TEST_SUITE_END(); From bb7edfadd14f0069cfcd111c3eda081e51d0baf0 Mon Sep 17 00:00:00 2001 From: Khizir Siddiqui Date: Wed, 15 Jan 2020 12:22:42 +0530 Subject: [PATCH 08/10] change error msg and algo cli names --- src/mlpack/methods/cf/cf_main.cpp | 8 ++++---- src/mlpack/methods/cf/cf_model_impl.hpp | 13 +++++++------ src/mlpack/tests/main_tests/cf_test.cpp | 14 +++++++------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/mlpack/methods/cf/cf_main.cpp b/src/mlpack/methods/cf/cf_main.cpp index 1653643fc1..49faf450fc 100644 --- a/src/mlpack/methods/cf/cf_main.cpp +++ b/src/mlpack/methods/cf/cf_main.cpp @@ -105,10 +105,10 @@ PROGRAM_INFO("Collaborative Filtering", " the " + PRINT_PARAM_STRING("normalization") + " parameter:" "\n" " - 'none' -- No Normalization\n" - " - 'itemMean' -- Item Mean Normalization\n" - " - 'overallMean' -- Overall Mean Normalization\n" - " - 'userMean' -- User Mean Normalization\n" - " - 'zScore' -- Z-Score Normalization\n" + " - 'item_mean' -- Item Mean Normalization\n" + " - 'overall_mean' -- Overall Mean Normalization\n" + " - 'user_mean' -- User Mean Normalization\n" + " - 'z_score' -- Z-Score Normalization\n" "\n" "A trained model may be saved to with the " + PRINT_PARAM_STRING("output_model") + " output parameter." diff --git a/src/mlpack/methods/cf/cf_model_impl.hpp b/src/mlpack/methods/cf/cf_model_impl.hpp index ebec1c80bd..47908d904d 100644 --- a/src/mlpack/methods/cf/cf_model_impl.hpp +++ b/src/mlpack/methods/cf/cf_model_impl.hpp @@ -126,25 +126,25 @@ void CFModel::Train(const MatType& data, // Instantiate a new CFType object. DecompositionPolicy decomposition; - if (normalization == "overallMean") + if (normalization == "overall_mean") { cf = new CFType(data, decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, mit); } - else if (normalization == "itemMean") + else if (normalization == "item_mean") { cf = new CFType(data, decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, mit); } - else if (normalization == "userMean") + else if (normalization == "user_mean") { cf = new CFType(data, decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, mit); } - else if (normalization == "zScore") + else if (normalization == "z_score") { cf = new CFType(data, decomposition, numUsersForSimilarity, rank, maxIterations, minResidue, @@ -158,8 +158,9 @@ void CFModel::Train(const MatType& data, } else { - throw std::runtime_error("Unsupported Normalization Algorithm." - "Please refer to help (-h) section for details"); + throw std::runtime_error("Unsupported normalization algorithm." + "It should be one of none, overall_mean, " + "item_mean, user_mean or z_score"); } } diff --git a/src/mlpack/tests/main_tests/cf_test.cpp b/src/mlpack/tests/main_tests/cf_test.cpp index a8031aabd5..936f39cbef 100644 --- a/src/mlpack/tests/main_tests/cf_test.cpp +++ b/src/mlpack/tests/main_tests/cf_test.cpp @@ -617,8 +617,8 @@ BOOST_AUTO_TEST_CASE(CFNeighborSearchTest) } /** - * Ensure normalization algorithm is one of { "none", "zScore", - * "itemMean", "userMean" }. + * Ensure normalization algorithm is one of { "none", "z_score", + * "item_mean", "user_mean" }. */ BOOST_AUTO_TEST_CASE(CFNormalizationBoundTest) { @@ -631,7 +631,7 @@ BOOST_AUTO_TEST_CASE(CFNormalizationBoundTest) SetInputParam("neighbor_search", std::string("cosine")); SetInputParam("algorithm", std::string("NMF")); - // normalization algorithm should be valid. + // Normalization algorithm should be valid. SetInputParam("normalization", std::string("invalid_normalization")); SetInputParam("training", std::move(dataset)); SetInputParam("query", query); @@ -679,8 +679,8 @@ BOOST_AUTO_TEST_CASE(CFNormalizationTest) SetInputParam("query", query); SetInputParam("algorithm", std::string("NMF")); - // Using without Normalization. - SetInputParam("normalization", std::string("itemMean")); + // Using Item Mean normalization. + SetInputParam("normalization", std::string("item_mean")); SetInputParam("recommendations", 5); mlpackMain(); @@ -698,8 +698,8 @@ BOOST_AUTO_TEST_CASE(CFNormalizationTest) SetInputParam("query", query); SetInputParam("algorithm", std::string("NMF")); - // Using without Normalization. - SetInputParam("normalization", std::string("zScore")); + // Using Z-Score normalization. + SetInputParam("normalization", std::string("z_score")); SetInputParam("recommendations", 5); mlpackMain(); From c33e243bbd7a4627214900541eac2d9e83f8d2c7 Mon Sep 17 00:00:00 2001 From: Khizir Siddiqui Date: Wed, 15 Jan 2020 12:48:02 +0530 Subject: [PATCH 09/10] style space check --- src/mlpack/methods/cf/cf_model_impl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mlpack/methods/cf/cf_model_impl.hpp b/src/mlpack/methods/cf/cf_model_impl.hpp index 47908d904d..096b5136be 100644 --- a/src/mlpack/methods/cf/cf_model_impl.hpp +++ b/src/mlpack/methods/cf/cf_model_impl.hpp @@ -158,8 +158,8 @@ void CFModel::Train(const MatType& data, } else { - throw std::runtime_error("Unsupported normalization algorithm." - "It should be one of none, overall_mean, " + throw std::runtime_error("Unsupported normalization algorithm." + " It should be one of none, overall_mean, " "item_mean, user_mean or z_score"); } } From b85377a3c4d3c058e6ddddc67fd0c960c89bec9d Mon Sep 17 00:00:00 2001 From: Khizir Siddiqui Date: Fri, 17 Jan 2020 23:50:37 +0530 Subject: [PATCH 10/10] remove unnecessary imports --- src/mlpack/methods/cf/cf_model.hpp | 1 - src/mlpack/methods/cf/cf_model_impl.hpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/mlpack/methods/cf/cf_model.hpp b/src/mlpack/methods/cf/cf_model.hpp index 35bd0ae944..112e093345 100644 --- a/src/mlpack/methods/cf/cf_model.hpp +++ b/src/mlpack/methods/cf/cf_model.hpp @@ -30,7 +30,6 @@ #include #include #include -#include namespace mlpack { namespace cf { diff --git a/src/mlpack/methods/cf/cf_model_impl.hpp b/src/mlpack/methods/cf/cf_model_impl.hpp index 096b5136be..45b87c26c5 100644 --- a/src/mlpack/methods/cf/cf_model_impl.hpp +++ b/src/mlpack/methods/cf/cf_model_impl.hpp @@ -21,7 +21,6 @@ #include #include #include -#include using namespace mlpack::cf;