mlpack  master
randomized_svd_method.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_METHODS_PCA_DECOMPOSITION_POLICIES_RANDOMIZED_SVD_METHOD_HPP
15 #define MLPACK_METHODS_PCA_DECOMPOSITION_POLICIES_RANDOMIZED_SVD_METHOD_HPP
16 
17 #include <mlpack/prereqs.hpp>
20 
21 namespace mlpack {
22 namespace pca {
23 
28 {
29  public:
40  const size_t maxIterations = 2) :
43  {
44  /* Nothing to do here */
45  }
46 
58  void Apply(const arma::mat& data,
59  const arma::mat& centeredData,
60  arma::mat& transformedData,
61  arma::vec& eigVal,
62  arma::mat& eigvec,
63  const size_t rank)
64  {
65  // This matrix will store the right singular values; we do not need them.
66  arma::mat v;
67 
68  // Do singular value decomposition using the randomized SVD algorithm.
70  rsvd.Apply(data, eigvec, eigVal, v, rank);
71 
72  // Now we must square the singular values to get the eigenvalues.
73  // In addition we must divide by the number of points, because the
74  // covariance matrix is X * X' / (N - 1).
75  eigVal %= eigVal / (data.n_cols - 1);
76 
77  // Project the samples to the principals.
78  transformedData = arma::trans(eigvec) * centeredData;
79  }
80 
82  size_t IteratedPower() const { return iteratedPower; }
84  size_t& IteratedPower() { return iteratedPower; }
85 
87  size_t MaxIterations() const { return maxIterations; }
89  size_t& MaxIterations() { return maxIterations; }
90 
91  private:
93  size_t iteratedPower;
94 
96  size_t maxIterations;
97 };
98 
99 } // namespace pca
100 } // namespace mlpack
101 
102 #endif
size_t & IteratedPower()
Modify the size of the normalized power iterations.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
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 SVD.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t MaxIterations() const
Get the number of iterations for the power method.
RandomizedSVDPolicy(const size_t iteratedPower=0, const size_t maxIterations=2)
Use randomized SVD method to perform the principal components analysis (PCA).
size_t & MaxIterations()
Modify the number of iterations for the power method.
size_t iteratedPower
Locally stored size of the normalized power iterations.
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 SVD.
Randomized SVD is a matrix factorization that is based on randomized matrix approximation techniques...
Implementation of the randomized SVD policy.
size_t maxIterations
Locally stored number of iterations for the power method.
size_t IteratedPower() const
Get the size of the normalized power iterations.