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,
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(),
169 Log::Warn <<
"CF::NumUsersForSimilarity(): invalid value (< 1) " 170 "ignored." << std::endl;
173 this->numUsersForSimilarity = num;
179 return numUsersForSimilarity;
183 void Rank(
const size_t rankValue)
185 this->rank = rankValue;
195 const arma::mat&
W()
const {
return w; }
197 const arma::mat&
H()
const {
return h; }
207 void GetRecommendations(
const size_t numRecs,
208 arma::Mat<size_t>& recommendations);
217 void GetRecommendations(
const size_t numRecs,
218 arma::Mat<size_t>& recommendations,
219 const arma::Col<size_t>& users);
222 static void CleanData(
const arma::mat& data, arma::sp_mat& cleanedData);
230 double Predict(
const size_t user,
const size_t item)
const;
244 void Predict(
const arma::Mat<size_t>& combinations,
245 arma::vec& predictions)
const;
250 template<
typename Archive>
251 void Serialize(Archive& ar,
const unsigned int );
272 return c1.first > c2.first;
281 #include "cf_impl.hpp" const arma::sp_mat & CleanedData() const
Get the cleaned data matrix.
arma::sp_mat cleanedData
Cleaned data matrix.
size_t NumUsersForSimilarity() const
Gets number of users for calculating similarity.
size_t rank
Rank used for matrix factorization.
size_t Rank() const
Gets rank parameter for matrix factorization.
const arma::mat & W() const
Get the User Matrix.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
Compare two candidates based on the value.
bool operator()(const Candidate &c1, const Candidate &c2)
static MLPACK_EXPORT util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
static const bool UsesCoordinateList
If true, then the passed data matrix is used for factorizer.Apply().
void NumUsersForSimilarity(const size_t num)
Sets number of users for calculating similarity.
const arma::mat & H() const
Get the Item Matrix.
size_t numUsersForSimilarity
Number of users for similarity.
std::pair< double, size_t > Candidate
Candidate represents a possible recommendation (value, item).
Template class for factorizer traits.
void Rank(const size_t rankValue)
Sets rank parameter for matrix factorization.
This class implements Collaborative Filtering (CF).
typename enable_if< B, T >::type enable_if_t