16 #ifndef MLPACK_METHODS_CF_CF_HPP
17 #define MLPACK_METHODS_CF_CF_HPP
38 template<
typename FactorizerType>
87 CF(
const size_t numUsersForSimilarity = 5,
88 const size_t rank = 0);
106 template<
typename FactorizerType = amf::NMFALSFactorizer>
107 CF(
const arma::mat& data,
108 FactorizerType factorizer = FactorizerType(),
109 const size_t numUsersForSimilarity = 5,
110 const size_t rank = 0);
130 template<
typename FactorizerType = amf::NMFALSFactorizer>
131 CF(
const arma::sp_mat& data,
132 FactorizerType factorizer = FactorizerType(),
133 const size_t numUsersForSimilarity = 5,
134 const size_t rank = 0,
135 const typename boost::disable_if_c<
146 template<
typename FactorizerType = amf::NMFALSFactorizer>
147 void Train(
const arma::mat& data,
148 FactorizerType factorizer = FactorizerType());
158 template<
typename FactorizerType = amf::NMFALSFactorizer>
159 void Train(
const arma::sp_mat& data,
160 FactorizerType factorizer = FactorizerType(),
161 const typename boost::disable_if_c<
170 Log::Warn <<
"CF::NumUsersForSimilarity(): invalid value (< 1) "
171 "ignored." << std::endl;
174 this->numUsersForSimilarity = num;
180 return numUsersForSimilarity;
184 void Rank(
const size_t rankValue)
186 this->rank = rankValue;
196 const arma::mat&
W()
const {
return w; }
198 const arma::mat&
H()
const {
return h; }
209 arma::Mat<size_t>& recommendations);
219 arma::Mat<size_t>& recommendations,
220 arma::Col<size_t>& users);
223 static void CleanData(
const arma::mat& data, arma::sp_mat& cleanedData);
231 double Predict(
const size_t user,
const size_t item)
const;
245 void Predict(
const arma::Mat<size_t>& combinations,
246 arma::vec& predictions)
const;
251 template<
typename Archive>
252 void Serialize(Archive& ar,
const unsigned int );
256 size_t numUsersForSimilarity;
264 arma::sp_mat cleanedData;
267 typedef std::pair<double, size_t> Candidate;
270 struct CandidateCmp {
271 bool operator()(
const Candidate& c1,
const Candidate& c2)
273 return c1.first > c2.first;
282 #include "cf_impl.hpp"
double Predict(const size_t user, const size_t item) const
Predict the rating of an item by a particular user.
CF(const size_t numUsersForSimilarity=5, const size_t rank=0)
Initialize the CF object without performing any factorization.
const arma::mat & W() const
Get the User Matrix.
const arma::sp_mat & CleanedData() const
Get the cleaned data matrix.
static const bool UsesCoordinateList
If true, then the passed data matrix is used for factorizer.Apply().
The core includes that mlpack expects; standard C++ includes and Armadillo.
const arma::mat & H() const
Get the Item Matrix.
size_t NumUsersForSimilarity() const
Gets number of users for calculating similarity.
void Train(const arma::mat &data, FactorizerType factorizer=FactorizerType())
Train the CF model (i.e.
void Rank(const size_t rankValue)
Sets rank parameter for matrix factorization.
size_t Rank() const
Gets rank parameter for matrix factorization.
static void CleanData(const arma::mat &data, arma::sp_mat &cleanedData)
Converts the User, Item, Value Matrix to User-Item Table.
Template class for factorizer traits.
static MLPACK_EXPORT util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
This class implements Collaborative Filtering (CF).
void NumUsersForSimilarity(const size_t num)
Sets number of users for calculating similarity.
void GetRecommendations(const size_t numRecs, arma::Mat< size_t > &recommendations)
Generates the given number of recommendations for all users.
void Serialize(Archive &ar, const unsigned int)
Serialize the CF model to the given archive.