16 #ifndef MLPACK_METHODS_CF_CF_HPP 17 #define MLPACK_METHODS_CF_CF_HPP 68 template<
typename DecompositionPolicy =
NMFPolicy,
77 CFType(
const size_t numUsersForSimilarity = 5,
const size_t rank = 0);
103 template<
typename MatType>
104 CFType(
const MatType& data,
105 const DecompositionPolicy& decomposition = DecompositionPolicy(),
106 const size_t numUsersForSimilarity = 5,
107 const size_t rank = 0,
108 const size_t maxIterations = 1000,
109 const double minResidue = 1e-5,
110 const bool mit =
false);
123 void Train(
const arma::mat& data,
124 const DecompositionPolicy& decomposition,
125 const size_t maxIterations = 1000,
126 const double minResidue = 1e-5,
127 const bool mit =
false);
140 void Train(
const arma::sp_mat& data,
141 const DecompositionPolicy& decomposition,
142 const size_t maxIterations = 1000,
143 const double minResidue = 1e-5,
144 const bool mit =
false);
151 Log::Warn <<
"CFType::NumUsersForSimilarity(): invalid value (< 1) " 152 "ignored." << std::endl;
155 this->numUsersForSimilarity = num;
161 return numUsersForSimilarity;
165 void Rank(
const size_t rankValue)
167 this->rank = rankValue;
199 arma::Mat<size_t>& recommendations);
216 arma::Mat<size_t>& recommendations,
217 const arma::Col<size_t>& users);
220 static void CleanData(
const arma::mat& data, arma::sp_mat& cleanedData);
235 double Predict(
const size_t user,
const size_t item)
const;
256 void Predict(
const arma::Mat<size_t>& combinations,
257 arma::vec& predictions)
const;
262 template<
typename Archive>
263 void serialize(Archive& ar,
const uint32_t );
267 size_t numUsersForSimilarity;
271 DecompositionPolicy decomposition;
273 arma::sp_mat cleanedData;
275 NormalizationType normalization;
278 typedef std::pair<double, size_t> Candidate;
281 struct CandidateCmp {
282 bool operator()(
const Candidate& c1,
const Candidate& c2)
284 return c1.first > c2.first;
293 #include "cf_impl.hpp" LMetricSearch< 2 > EuclideanSearch
const arma::sp_mat & CleanedData() const
Get the cleaned data matrix.
void NumUsersForSimilarity(const size_t num)
Sets number of users for calculating similarity.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
Implementation of the NMF policy to act as a wrapper when accessing NMF from within CFType...
double Predict(const size_t user, const size_t item) const
Predict the rating of an item by a particular user.
This class performs average interpolation to generate interpolation weights for neighborhood-based co...
static void CleanData(const arma::mat &data, arma::sp_mat &cleanedData)
Converts the User, Item, Value Matrix to User-Item Table.
size_t Rank() const
Gets rank parameter for matrix factorization.
void Train(const arma::mat &data, const DecompositionPolicy &decomposition, const size_t maxIterations=1000, const double minResidue=1e-5, const bool mit=false)
Train the CFType model (i.e.
This normalization class doesn't perform any normalization.
const NormalizationType & Normalization() const
Get the normalization object.
const DecompositionPolicy & Decomposition() const
Gets decomposition object.
void GetRecommendations(const size_t numRecs, arma::Mat< size_t > &recommendations)
Generates the given number of recommendations for all users.
static MLPACK_EXPORT util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
This class implements Collaborative Filtering (CF).
size_t NumUsersForSimilarity() const
Gets number of users for calculating similarity.
CFType(const size_t numUsersForSimilarity=5, const size_t rank=0)
Initialize the CFType object without performing any factorization.
void Rank(const size_t rankValue)
Sets rank parameter for matrix factorization.
void serialize(Archive &ar, const uint32_t)
Serialize the CFType model to the given archive.