mlpack 3.4.2
randomized_block_krylov_method.hpp
Go to the documentation of this file.
1
14#ifndef MLPACK_METHODS_PCA_DECOMPOSITION_POLICIES_RANDOMIZED_BLOCK_KRYLOV_HPP
15#define MLPACK_METHODS_PCA_DECOMPOSITION_POLICIES_RANDOMIZED_BLOCK_KRYLOV_HPP
16
17#include <mlpack/prereqs.hpp>
19
20namespace mlpack {
21namespace pca {
22
27{
28 public:
37 RandomizedBlockKrylovSVDPolicy(const size_t maxIterations = 2,
38 const size_t blockSize = 0) :
39 maxIterations(maxIterations),
40 blockSize(blockSize)
41 {
42 /* Nothing to do here */
43 }
44
56 void Apply(const arma::mat& data,
57 const arma::mat& centeredData,
58 arma::mat& transformedData,
59 arma::vec& eigVal,
60 arma::mat& eigvec,
61 const size_t rank)
62 {
63 // This matrix will store the right singular values; we do not need them.
64 arma::mat v;
65
66 // Do singular value decomposition using the randomized block krylov SVD
67 // algorithm.
68 svd::RandomizedBlockKrylovSVD rsvd(maxIterations, blockSize);
69 rsvd.Apply(centeredData, eigvec, eigVal, v, rank);
70
71 // Now we must square the singular values to get the eigenvalues.
72 // In addition we must divide by the number of points, because the
73 // covariance matrix is X * X' / (N - 1).
74 eigVal %= eigVal / (data.n_cols - 1);
75
76 // Project the samples to the principals.
77 transformedData = arma::trans(eigvec) * centeredData;
78 }
79
81 size_t MaxIterations() const { return maxIterations; }
83 size_t& MaxIterations() { return maxIterations; }
84
86 size_t BlockSize() const { return blockSize; }
88 size_t& BlockSize() { return blockSize; }
89
90 private:
92 size_t maxIterations;
93
95 size_t blockSize;
96};
97
98} // namespace pca
99} // namespace mlpack
100
101#endif
Implementation of the randomized block krylov SVD policy.
size_t MaxIterations() const
Get the number of iterations for the power method.
void Apply(const arma::mat &data, const arma::mat &centeredData, arma::mat &transformedData, arma::vec &eigVal, arma::mat &eigvec, const size_t rank)
Apply Principal Component Analysis to the provided data set using the randomized block krylov SVD met...
size_t & MaxIterations()
Modify the number of iterations for the power method.
RandomizedBlockKrylovSVDPolicy(const size_t maxIterations=2, const size_t blockSize=0)
Use randomized block krylov SVD method to perform the principal components analysis (PCA).
Randomized block krylov SVD is a matrix factorization that is based on randomized matrix approximatio...
void Apply(const arma::mat &data, arma::mat &u, arma::vec &s, arma::mat &v, const size_t rank)
Apply Principal Component Analysis to the provided data set using the randomized block krylov SVD.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.