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)
44 template<
typename MatType>
49 arma::mat deltaW(
n, W.n_cols);
51 for(
size_t i = 0;i <
n;i++)
57 if(
kw != 0) deltaW.row(i) -=
kw * W.row(i);
72 template<
typename MatType>
77 arma::mat deltaH(H.n_rows, 1);
80 for(
size_t i = 0;i <
n;i++)
85 arma::trans(W.row(i));
105 inline void SVDIncompleteIncrementalLearning::
106 WUpdate<arma::sp_mat>(
const arma::sp_mat& V,
110 arma::mat deltaW(n, W.n_cols);
112 for(arma::sp_mat::const_iterator it = V.begin_col(currentUserIndex);
113 it != V.end_col(currentUserIndex);it++)
117 deltaW.row(i) += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
118 arma::trans(H.col(currentUserIndex));
119 if(kw != 0) deltaW.row(i) -= kw * W.row(i);
126 inline void SVDIncompleteIncrementalLearning::
127 HUpdate<arma::sp_mat>(
const arma::sp_mat& V,
131 arma::mat deltaH(H.n_rows, 1);
134 for(arma::sp_mat::const_iterator it = V.begin_col(currentUserIndex);
135 it != V.end_col(currentUserIndex);it++)
139 if((val = V(i, currentUserIndex)) != 0)
140 deltaH += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
141 arma::trans(W.row(i));
143 if(kh != 0) deltaH -= kh * H.col(currentUserIndex);
145 H.col(currentUserIndex++) += u * deltaH;
146 currentUserIndex = currentUserIndex % m;
153 #endif // SVD_INCREMENTAL_LEARNING_HPP_INCLUDED
Linear algebra utility functions, generally performed on matrices or vectors.
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)