14 #ifndef MLPACK_METHODS_CF_DECOMPOSITION_POLICIES_BIAS_SVD_METHOD_HPP 15 #define MLPACK_METHODS_CF_DECOMPOSITION_POLICIES_BIAS_SVD_METHOD_HPP 52 const double alpha = 0.02,
53 const double lambda = 0.05) :
54 maxIterations(maxIterations),
73 void Apply(
const arma::mat& data,
76 const size_t maxIterations,
82 biassvd.
Apply(data, rank, w, h, p, q);
91 double GetRating(
const size_t user,
const size_t item)
const 94 arma::as_scalar(w.row(item) * h.col(user)) + p(item) + q(user);
106 rating = w * h.col(user) + p + q(user);
121 template<
typename NeighborSearchPolicy>
123 const size_t numUsersForSimilarity,
124 arma::Mat<size_t>& neighborhood,
125 arma::mat& similarities)
const 129 arma::mat query(h.n_rows, users.n_elem);
131 for (
size_t i = 0; i < users.n_elem; ++i)
132 query.col(i) = h.col(users(i));
134 NeighborSearchPolicy neighborSearch(h);
135 neighborSearch.Search(
136 query, numUsersForSimilarity, neighborhood, similarities);
140 const arma::mat&
W()
const {
return w; }
142 const arma::mat&
H()
const {
return h; }
144 const arma::vec&
Q()
const {
return q; }
146 const arma::vec&
P()
const {
return p; }
154 double Alpha()
const {
return alpha; }
166 template<
typename Archive>
169 ar(CEREAL_NVP(maxIterations));
170 ar(CEREAL_NVP(alpha));
171 ar(CEREAL_NVP(lambda));
180 size_t maxIterations;
double GetRating(const size_t user, const size_t item) const
Return predicted rating given user ID and item ID.
double & Lambda()
Modify regularization parameter.
double Lambda() const
Get regularization parameter.
void Apply(const arma::mat &data, const arma::sp_mat &, const size_t rank, const size_t maxIterations, const double, const bool)
Apply Collaborative Filtering to the provided data set using the bias SVD.
Bias SVD is an improvement on Regularized SVD which is a matrix factorization techniques.
void Apply(const arma::mat &data, const size_t rank, arma::mat &u, arma::mat &v, arma::vec &p, arma::vec &q)
Trains the model and obtains user/item matrices and user/item bias.
void GetNeighborhood(const arma::Col< size_t > &users, const size_t numUsersForSimilarity, arma::Mat< size_t > &neighborhood, arma::mat &similarities) const
Get the neighborhood and corresponding similarities for a set of users.
Linear algebra utility functions, generally performed on matrices or vectors.
const arma::vec & P() const
Get the Item Bias Vector.
The core includes that mlpack expects; standard C++ includes and Armadillo.
const arma::vec & Q() const
Get the User Bias Vector.
const arma::mat & W() const
Get the Item Matrix.
size_t MaxIterations() const
Get the number of iterations.
size_t & MaxIterations()
Modify the number of iterations.
void serialize(Archive &ar, const uint32_t)
Serialization.
BiasSVDPolicy(const size_t maxIterations=10, const double alpha=0.02, const double lambda=0.05)
Use Bias SVD method to perform collaborative filtering.
void GetRatingOfUser(const size_t user, arma::vec &rating) const
Get predicted ratings for a user.
const arma::mat & H() const
Get the User Matrix.
Implementation of the Bias SVD policy to act as a wrapper when accessing Bias SVD from within CFType...
double Alpha() const
Get learning rate.
double & Alpha()
Modify learning rate.