12 #ifndef MLPACK_METHODS_AMF_SVD_INCOMPLETE_INCREMENTAL_LEARNING_HPP 13 #define MLPACK_METHODS_AMF_SVD_INCOMPLETE_INCREMENTAL_LEARNING_HPP 56 : u(u), kw(kw), kh(kh), currentUserIndex(0)
69 template<
typename MatType>
85 template<
typename MatType>
91 deltaW.zeros(V.n_rows, W.n_cols);
95 for (
size_t i = 0; i < V.n_rows; ++i)
97 const double val = V(i, currentUserIndex);
101 deltaW.row(i) += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
102 H.col(currentUserIndex).t();
106 deltaW.row(i) -= kw * W.row(i);
120 template<
typename MatType>
126 deltaH.zeros(H.n_rows);
130 for (
size_t i = 0; i < V.n_rows; ++i)
132 const double val = V(i, currentUserIndex);
136 deltaH += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
142 deltaH -= kh * H.col(currentUserIndex);
145 H.col(currentUserIndex++) += u * deltaH;
146 currentUserIndex = currentUserIndex % V.n_cols;
158 size_t currentUserIndex;
166 inline void SVDIncompleteIncrementalLearning::WUpdate<arma::sp_mat>(
167 const arma::sp_mat& V, arma::mat& W,
const arma::mat& H)
169 arma::mat deltaW(V.n_rows, W.n_cols);
171 for (arma::sp_mat::const_iterator it = V.begin_col(currentUserIndex);
172 it != V.end_col(currentUserIndex); ++it)
176 deltaW.row(i) += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
177 arma::trans(H.col(currentUserIndex));
178 if (kw != 0) deltaW.row(i) -= kw * W.row(i);
185 inline void SVDIncompleteIncrementalLearning::HUpdate<arma::sp_mat>(
186 const arma::sp_mat& V,
const arma::mat& W, arma::mat& H)
188 arma::mat deltaH(H.n_rows, 1);
191 for (arma::sp_mat::const_iterator it = V.begin_col(currentUserIndex);
192 it != V.end_col(currentUserIndex); ++it)
196 if ((val = V(i, currentUserIndex)) != 0)
198 deltaH += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
199 arma::trans(W.row(i));
202 if (kh != 0) deltaH -= kh * H.col(currentUserIndex);
204 H.col(currentUserIndex++) += u * deltaH;
205 currentUserIndex = currentUserIndex % V.n_cols;
This class computes SVD using incomplete incremental batch learning, as described in the following pa...
Linear algebra utility functions, generally performed on matrices or vectors.
SVDIncompleteIncrementalLearning(double u=0.001, double kw=0, double kh=0)
Initialize the parameters of SVDIncompleteIncrementalLearning.
void HUpdate(const MatType &V, const arma::mat &W, arma::mat &H)
The update rule for the encoding matrix H.
void WUpdate(const MatType &V, arma::mat &W, const arma::mat &H)
The update rule for the basis matrix W.
void Initialize(const MatType &, const size_t)
Initialize parameters before factorization.