1 #ifndef SVD_INCREMENTAL_LEARNING_HPP_INCLUDED
2 #define SVD_INCREMENTAL_LEARNING_HPP_INCLUDED
17 template<
typename MatType>
18 void Initialize(
const MatType& dataset,
const size_t rank)
52 template<
typename MatType>
57 arma::mat deltaW(
n, W.n_cols);
59 for(
size_t i = 0;i <
n;i++)
65 if(
kw != 0) deltaW.row(i) -=
kw * W.row(i);
80 template<
typename MatType>
85 arma::mat deltaH(H.n_rows, 1);
88 for(
size_t i = 0;i <
n;i++)
93 arma::trans(W.row(i));
113 inline void SVDIncompleteIncrementalLearning::
114 WUpdate<arma::sp_mat>(
const arma::sp_mat& V,
118 arma::mat deltaW(n, W.n_cols);
120 for(arma::sp_mat::const_iterator it = V.begin_col(currentUserIndex);
121 it != V.end_col(currentUserIndex);it++)
125 deltaW.row(i) += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
126 arma::trans(H.col(currentUserIndex));
127 if(kw != 0) deltaW.row(i) -= kw * W.row(i);
134 inline void SVDIncompleteIncrementalLearning::
135 HUpdate<arma::sp_mat>(
const arma::sp_mat& V,
139 arma::mat deltaH(H.n_rows, 1);
142 for(arma::sp_mat::const_iterator it = V.begin_col(currentUserIndex);
143 it != V.end_col(currentUserIndex);it++)
147 if((val = V(i, currentUserIndex)) != 0)
148 deltaH += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
149 arma::trans(W.row(i));
151 if(kh != 0) deltaH -= kh * H.col(currentUserIndex);
153 H.col(currentUserIndex++) += u * deltaH;
154 currentUserIndex = currentUserIndex % m;
161 #endif // SVD_INCREMENTAL_LEARNING_HPP_INCLUDED
void Initialize(const MatType &dataset, const size_t rank)
void WUpdate(const MatType &V, arma::mat &W, const arma::mat &H)
The update rule for the basis matrix W.
void HUpdate(const MatType &V, const arma::mat &W, arma::mat &H)
The update rule for the encoding matrix H.
SVDIncompleteIncrementalLearning(double u=0.001, double kw=0, double kh=0)