13 #ifndef MLPACK_METHODS_CF_DECOMPOSITION_POLICIES_NMF_METHOD_HPP
14 #define MLPACK_METHODS_CF_DECOMPOSITION_POLICIES_NMF_METHOD_HPP
57 template<
typename MatType>
59 const arma::sp_mat& cleanedData,
61 const size_t maxIterations,
62 const double minResidue,
72 nmf.Apply(cleanedData, rank, w, h);
80 nmf.
Apply(cleanedData, rank, w, h);
90 double GetRating(
const size_t user,
const size_t item)
const
92 double rating = arma::as_scalar(w.row(item) * h.col(user));
104 rating = w * h.col(user);
119 template<
typename NeighborSearchPolicy>
121 const size_t numUsersForSimilarity,
122 arma::Mat<size_t>& neighborhood,
123 arma::mat& similarities)
const
132 arma::mat l = arma::chol(w.t() * w);
133 arma::mat stretchedH = l * h;
136 arma::mat query(stretchedH.n_rows, users.n_elem);
138 for (
size_t i = 0; i < users.n_elem; i++)
139 query.col(i) = stretchedH.col(users(i));
141 NeighborSearchPolicy neighborSearch(stretchedH);
142 neighborSearch.Search(
143 query, numUsersForSimilarity, neighborhood, similarities);
147 const arma::mat&
W()
const {
return w; }
149 const arma::mat&
H()
const {
return h; }
154 template<
typename Archive>
157 ar & BOOST_SERIALIZATION_NVP(w);
158 ar & BOOST_SERIALIZATION_NVP(h);