18 #ifndef __MLPACK_METHODS_CF_CF_HPP
19 #define __MLPACK_METHODS_CF_CF_HPP
40 template<
typename FactorizerType>
90 const size_t rank = 0);
108 template<
typename FactorizerType = amf::NMFALSFactorizer>
109 CF(
const arma::mat& data,
110 FactorizerType factorizer = FactorizerType(),
112 const size_t rank = 0);
132 template<
typename FactorizerType = amf::NMFALSFactorizer>
133 CF(
const arma::sp_mat& data,
134 FactorizerType factorizer = FactorizerType(),
136 const size_t rank = 0,
137 const typename boost::disable_if_c<
148 template<
typename FactorizerType = amf::NMFALSFactorizer>
149 void Train(
const arma::mat& data,
150 FactorizerType factorizer = FactorizerType());
160 template<
typename FactorizerType = amf::NMFALSFactorizer>
161 void Train(
const arma::sp_mat& data,
162 FactorizerType factorizer = FactorizerType(),
163 const typename boost::disable_if_c<
172 Log::Warn <<
"CF::NumUsersForSimilarity(): invalid value (< 1) "
173 "ignored." << std::endl;
186 void Rank(
const size_t rankValue)
188 this->
rank = rankValue;
198 const arma::mat&
W()
const {
return w; }
200 const arma::mat&
H()
const {
return h; }
211 arma::Mat<size_t>& recommendations);
221 arma::Mat<size_t>& recommendations,
222 arma::Col<size_t>& users);
233 double Predict(
const size_t user,
const size_t item)
const;
247 void Predict(
const arma::Mat<size_t>& combinations,
248 arma::vec& predictions)
const;
253 template<
typename Archive>
254 void Serialize(Archive& ar,
const unsigned int );
279 const size_t neighbor,
281 arma::Mat<size_t>& recommendations,
282 arma::mat& values)
const;
290 #include "cf_impl.hpp"
const arma::sp_mat & CleanedData() const
Get the cleaned data matrix.
double Predict(const size_t user, const size_t item) const
Predict the rating of an item by a particular user.
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.
static void CleanData(const arma::mat &data, arma::sp_mat &cleanedData)
Converts the User, Item, Value Matrix to User-Item Table.
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.
void Train(const arma::mat &data, FactorizerType factorizer=FactorizerType())
Train the CF model (i.e.
const arma::mat & H() const
Get the Item Matrix.
void Serialize(Archive &ar, const unsigned int)
Serialize the CF model to the given archive.
CF(const size_t numUsersForSimilarity=5, const size_t rank=0)
Initialize the CF object without performing any factorization.
void InsertNeighbor(const size_t queryIndex, const size_t pos, const size_t neighbor, const double value, arma::Mat< size_t > &recommendations, arma::mat &values) const
Helper function to insert a point into the recommendation matrices.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
size_t numUsersForSimilarity
Number of users for similarity.
void GetRecommendations(const size_t numRecs, arma::Mat< size_t > &recommendations)
Generates the given number of recommendations for all users.
Template class for factorizer traits.
static util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
void Rank(const size_t rankValue)
Sets rank parameter for matrix factorization.
This class implements Collaborative Filtering (CF).