14#ifndef MLPACK_METHODS_CF_DECOMPOSITION_POLICIES_RANDOMIZED_SVD_METHOD_HPP
15#define MLPACK_METHODS_CF_DECOMPOSITION_POLICIES_RANDOMIZED_SVD_METHOD_HPP
53 const size_t maxIterations = 2) :
54 iteratedPower(iteratedPower),
55 maxIterations(maxIterations)
72 template<
typename MatType>
74 const arma::sp_mat& cleanedData,
76 const size_t maxIterations,
84 rsvd.
Apply(cleanedData, w, sigma, h, rank);
87 w = w * arma::diagmat(sigma);
99 double GetRating(
const size_t user,
const size_t item)
const
101 double rating = arma::as_scalar(w.row(item) * h.col(user));
113 rating = w * h.col(user);
128 template<
typename NeighborSearchPolicy>
130 const size_t numUsersForSimilarity,
131 arma::Mat<size_t>& neighborhood,
132 arma::mat& similarities)
const
141 arma::mat l = arma::chol(w.t() * w);
142 arma::mat stretchedH = l * h;
145 arma::mat query(stretchedH.n_rows, users.n_elem);
147 for (
size_t i = 0; i < users.n_elem; ++i)
148 query.col(i) = stretchedH.col(users(i));
150 NeighborSearchPolicy neighborSearch(stretchedH);
151 neighborSearch.Search(
152 query, numUsersForSimilarity, neighborhood, similarities);
156 const arma::mat&
W()
const {
return w; }
158 const arma::mat&
H()
const {
return h; }
173 template<
typename Archive>
176 ar & BOOST_SERIALIZATION_NVP(w);
177 ar & BOOST_SERIALIZATION_NVP(h);
182 size_t iteratedPower;
184 size_t maxIterations;
Implementation of the Randomized SVD policy to act as a wrapper when accessing Randomized SVD from wi...
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.
size_t MaxIterations() const
Get the number of iterations.
size_t & MaxIterations()
Modify the number of iterations.
RandomizedSVDPolicy(const size_t iteratedPower=0, const size_t maxIterations=2)
Use randomized SVD method to perform collaborative filtering.
size_t IteratedPower() const
Get the size of the normalized power iterations.
const arma::mat & W() const
Get the Item Matrix.
void Apply(const MatType &, const arma::sp_mat &cleanedData, const size_t rank, const size_t maxIterations, const double, const bool)
Apply Collaborative Filtering to the provided data set using the randomized SVD.
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.
size_t & IteratedPower()
Modify the size of the normalized power iterations.
Randomized SVD is a matrix factorization that is based on randomized matrix approximation techniques,...
void Apply(const arma::sp_mat &data, arma::mat &u, arma::vec &s, arma::mat &v, const size_t rank)
Center the data to apply Principal Component Analysis on given sparse matrix dataset using randomized...
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.