MLPACK  1.0.7
cf.hpp
Go to the documentation of this file.
1 
25 #ifndef __MLPACK_METHODS_CF_CF_HPP
26 #define __MLPACK_METHODS_CF_CF_HPP
27 
28 #include <mlpack/core.hpp>
30 #include <set>
31 #include <map>
32 #include <iostream>
33 
34 namespace mlpack {
35 namespace cf {
36 
68 class CF
69 {
70  public:
79  CF(const size_t numRecs,const size_t numUsersForSimilarity,
80  arma::mat& data);
81 
89  CF(const size_t numRecs, arma::mat& data);
90 
97  CF(arma::mat& data);
98 
100  void NumRecs(size_t recs)
101  {
102  if (recs < 1)
103  {
104  Log::Warn << "CF::NumRecs(): invalid value (< 1) "
105  "ignored." << std::endl;
106  return;
107  }
108  this->numRecs = recs;
109  }
110 
112  size_t NumRecs()
113  {
114  return numRecs;
115  }
116 
118  void NumUsersForSimilarity(size_t num)
119  {
120  if (num < 1)
121  {
122  Log::Warn << "CF::NumUsersForSimilarity(): invalid value (< 1) "
123  "ignored." << std::endl;
124  return;
125  }
126  this->numUsersForSimilarity = num;
127  }
128 
131  {
132  return numUsersForSimilarity;
133  }
134 
136  const arma::mat& W() const { return w; }
138  const arma::mat& H() const { return h; }
140  const arma::mat& Rating() const { return rating; }
142  const arma::mat& Data() const { return data; }
144  const arma::sp_mat& CleanedData() const { return cleanedData; }
145 
151  void GetRecommendations(arma::Mat<size_t>& recommendations);
152 
159  void GetRecommendations(arma::Mat<size_t>& recommendations,
160  arma::Col<size_t>& users);
161 
169  void GetRecommendations(arma::Mat<size_t>& recommendations,
170  arma::Col<size_t>& users, size_t num);
171 
181  void GetRecommendations(arma::Mat<size_t>& recommendations,
182  arma::Col<size_t>& users, size_t num,
183  size_t neighbours);
184 
185  private:
187  size_t numRecs;
191  arma::mat w;
193  arma::mat h;
195  arma::mat rating;
197  arma::mat data;
199  arma::sp_mat cleanedData;
201  void CleanData();
202 
212  void InsertNeighbor(const size_t queryIndex,
213  const size_t pos,
214  const size_t neighbor,
215  const double value,
216  arma::Mat<size_t>& recommendations,
217  arma::mat& values) const;
218 
219 }; // class CF
220 
221 }; // namespace cf
222 }; // namespace mlpack
223 
224 #endif
const arma::sp_mat & CleanedData() const
Get the cleaned data matrix.
Definition: cf.hpp:144
arma::sp_mat cleanedData
Cleaned data matrix.
Definition: cf.hpp:199
const arma::mat & Data() const
Get the data matrix.
Definition: cf.hpp:142
const arma::mat & W() const
Get the User Matrix.
Definition: cf.hpp:136
void NumRecs(size_t recs)
Sets number of Recommendations.
Definition: cf.hpp:100
CF(const size_t numRecs, const size_t numUsersForSimilarity, arma::mat &data)
Create a CF object and (optionally) set the parameters with which collaborative filtering will be run...
void GetRecommendations(arma::Mat< size_t > &recommendations)
Generates default number of recommendations for all users.
arma::mat h
Item matrix.
Definition: cf.hpp:193
size_t numRecs
Number of recommendations.
Definition: cf.hpp:187
void NumUsersForSimilarity(size_t num)
Sets number of user for calculating similarity.
Definition: cf.hpp:118
size_t NumRecs()
Gets numRecs.
Definition: cf.hpp:112
const arma::mat & H() const
Get the Item Matrix.
Definition: cf.hpp:138
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.
void CleanData()
Converts the User, Item, Value Matrix to User-Item Table.
arma::mat w
User matrix.
Definition: cf.hpp:191
size_t numUsersForSimilarity
Number of users for similarity.
Definition: cf.hpp:189
const arma::mat & Rating() const
Get the Rating Matrix.
Definition: cf.hpp:140
static util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
Definition: log.hpp:92
arma::mat rating
Rating matrix.
Definition: cf.hpp:195
arma::mat data
Initial data matrix.
Definition: cf.hpp:197
This class implements Collaborative Filtering (CF).
Definition: cf.hpp:68
size_t NumUsersForSimilarity()
Gets number of users for calculating similarity/.
Definition: cf.hpp:130