13#ifndef MLPACK_METHODS_CF_DECOMPOSITION_POLICIES_BATCH_SVD_METHOD_HPP
14#define MLPACK_METHODS_CF_DECOMPOSITION_POLICIES_BATCH_SVD_METHOD_HPP
58 template<
typename MatType>
60 const arma::sp_mat& cleanedData,
62 const size_t maxIterations,
63 const double minResidue,
74 svdbatch.Apply(cleanedData, rank, w, h);
83 svdbatch.
Apply(cleanedData, rank, w, h);
93 double GetRating(
const size_t user,
const size_t item)
const
95 double rating = arma::as_scalar(w.row(item) * h.col(user));
107 rating = w * h.col(user);
122 template<
typename NeighborSearchPolicy>
124 const size_t numUsersForSimilarity,
125 arma::Mat<size_t>& neighborhood,
126 arma::mat& similarities)
const
135 arma::mat l = arma::chol(w.t() * w);
136 arma::mat stretchedH = l * h;
139 arma::mat query(stretchedH.n_rows, users.n_elem);
141 for (
size_t i = 0; i < users.n_elem; ++i)
142 query.col(i) = stretchedH.col(users(i));
144 NeighborSearchPolicy neighborSearch(stretchedH);
145 neighborSearch.Search(
146 query, numUsersForSimilarity, neighborhood, similarities);
150 const arma::mat&
W()
const {
return w; }
152 const arma::mat&
H()
const {
return h; }
157 template<
typename Archive>
160 ar & BOOST_SERIALIZATION_NVP(w);
161 ar & BOOST_SERIALIZATION_NVP(h);
This class implements AMF (alternating matrix factorization) on the given matrix V.
double Apply(const MatType &V, const size_t r, arma::mat &W, arma::mat &H)
Apply Alternating Matrix Factorization to the provided matrix.
This termination policy only terminates when the maximum number of iterations has been reached.
This initialization rule for AMF simply fills the W and H matrices with uniform random noise in [0,...
This class implements SVD batch learning with momentum.
This class implements a simple residue-based termination policy.
Implementation of the Batch SVD policy to act as a wrapper when accessing Batch SVD from within CFTyp...
double GetRating(const size_t user, const size_t item) const
Return predicted rating given user ID and item ID.
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.
void Apply(const MatType &, const arma::sp_mat &cleanedData, const size_t rank, const size_t maxIterations, const double minResidue, const bool mit)
Apply Collaborative Filtering to the provided data set using the batch SVD method.
const arma::mat & W() const
Get the Item Matrix.
const arma::mat & H() const
Get the User Matrix.
void GetRatingOfUser(const size_t user, arma::vec &rating) const
Get predicted ratings for a user.
void serialize(Archive &ar, const unsigned int)
Serialization.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.