13 #ifndef MLPACK_METHODS_RANDOMIZED_SVD_RANDOMIZED_SVD_HPP 14 #define MLPACK_METHODS_RANDOMIZED_SVD_RANDOMIZED_SVD_HPP 88 const size_t iteratedPower = 0,
89 const size_t maxIterations = 2,
90 const size_t rank = 0,
91 const double eps = 1e-7);
104 const size_t maxIterations = 2,
105 const double eps = 1e-7);
117 void Apply(
const arma::sp_mat& data,
133 void Apply(
const arma::mat& data,
150 template<
typename MatType>
158 if (iteratedPower == 0)
159 iteratedPower = rank + 2;
161 arma::mat R, Q, Qdata;
164 if (data.n_cols >= data.n_rows)
166 R = arma::randn<arma::mat>(data.n_rows, iteratedPower);
167 Q = (data.t() * R) - arma::repmat(arma::trans(R.t() * rowMean),
172 R = arma::randn<arma::mat>(data.n_cols, iteratedPower);
173 Q = (data * R) - (rowMean * (arma::ones(1, data.n_cols) * R));
178 if (maxIterations == 0)
180 arma::qr_econ(Q, v, Q);
188 for (
size_t i = 0; i < maxIterations; ++i)
190 if (data.n_cols >= data.n_rows)
192 Q = (data * Q) - rowMean * (arma::ones(1, data.n_cols) * Q);
194 Q = (data.t() * Q) - arma::repmat(rowMean.t() * Q, data.n_cols, 1);
198 Q = (data.t() * Q) - arma::repmat(rowMean.t() * Q, data.n_cols, 1);
200 Q = (data * Q) - (rowMean * (arma::ones(1, data.n_cols) * Q));
207 if (i < (maxIterations - 1))
213 arma::qr_econ(Q, v, Q);
220 if (data.n_cols >= data.n_rows)
222 Qdata = (data * Q) - rowMean * (arma::ones(1, data.n_cols) * Q);
223 arma::svd_econ(u, s, v, Qdata);
228 Qdata = (Q.t() * data) - arma::repmat(Q.t() * rowMean, 1, data.n_cols);
229 arma::svd_econ(u, s, v, Qdata);
251 size_t iteratedPower;
254 size_t maxIterations;
Linear algebra utility functions, generally performed on matrices or vectors.
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...