13 #ifndef MLPACK_METHODS_RANDOMIZED_SVD_RANDOMIZED_SVD_HPP 14 #define MLPACK_METHODS_RANDOMIZED_SVD_RANDOMIZED_SVD_HPP 89 const size_t iteratedPower = 0,
90 const size_t maxIterations = 2,
91 const size_t rank = 0,
92 const double eps = 1e-7);
105 const size_t maxIterations = 2,
106 const double eps = 1e-7);
118 void Apply(
const arma::sp_mat& data,
134 void Apply(
const arma::mat& data,
151 template<
typename MatType>
159 if (iteratedPower == 0)
160 iteratedPower = rank + 2;
162 arma::mat R, Q, Qdata;
165 if (data.n_cols >= data.n_rows)
167 R = arma::randn<arma::mat>(data.n_rows, iteratedPower);
168 Q = (data.t() * R) - arma::repmat(arma::trans(R.t() * rowMean),
173 R = arma::randn<arma::mat>(data.n_cols, iteratedPower);
174 Q = (data * R) - (rowMean * (arma::ones(1, data.n_cols) * R));
179 if (maxIterations == 0)
181 arma::qr_econ(Q, v, Q);
189 for (
size_t i = 0; i < maxIterations; ++i)
191 if (data.n_cols >= data.n_rows)
193 Q = (data * Q) - rowMean * (arma::ones(1, data.n_cols) * Q);
195 Q = (data.t() * Q) - arma::repmat(rowMean.t() * Q, data.n_cols, 1);
199 Q = (data.t() * Q) - arma::repmat(rowMean.t() * Q, data.n_cols, 1);
201 Q = (data * Q) - (rowMean * (arma::ones(1, data.n_cols) * Q));
208 if (i < (maxIterations - 1))
214 arma::qr_econ(Q, v, Q);
221 if (data.n_cols >= data.n_rows)
223 Qdata = (data * Q) - rowMean * (arma::ones(1, data.n_cols) * Q);
224 arma::svd_econ(u, s, v, Qdata);
229 Qdata = (Q.t() * data) - arma::repmat(Q.t() * rowMean, 1, data.n_cols);
230 arma::svd_econ(u, s, v, Qdata);
252 size_t iteratedPower;
255 size_t maxIterations;
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Apply(const MatType &data, arma::mat &u, arma::vec &s, arma::mat &v, const size_t rank, MatType rowMean)
Apply Principal Component Analysis to the provided matrix data set using the randomized SVD...
size_t & IteratedPower()
Modify the size of the normalized power iterations.
RandomizedSVD(const arma::mat &data, arma::mat &u, arma::vec &s, arma::mat &v, const size_t iteratedPower=0, const size_t maxIterations=2, const size_t rank=0, const double eps=1e-7)
Create object for the randomized SVD method.
size_t MaxIterations() const
Get the number of iterations for the power method.
double Epsilon() const
Get the value used for decomposition stability.
Randomized SVD is a matrix factorization that is based on randomized matrix approximation techniques...
size_t IteratedPower() const
Get the size of the normalized power iterations.
size_t & MaxIterations()
Modify the number of iterations for the power method.
double & Epsilon()
Modify the value used for decomposition stability.
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...