mlpack  master
quic_svd_method.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_METHODS_PCA_DECOMPOSITION_POLICIES_QUIC_SVD_METHOD_HPP
15 #define MLPACK_METHODS_PCA_DECOMPOSITION_POLICIES_QUIC_SVD_METHOD_HPP
16 
17 #include <mlpack/prereqs.hpp>
19 
20 namespace mlpack {
21 namespace pca {
22 
27 {
28  public:
29 
36  QUICSVDPolicy(const double epsilon = 0.03, const double delta = 0.1) :
38  delta(delta)
39  {
40  /* Nothing to do here */
41  }
42 
54  void Apply(const arma::mat& data,
55  const arma::mat& centeredData,
56  arma::mat& transformedData,
57  arma::vec& eigVal,
58  arma::mat& eigvec,
59  const size_t /* rank */)
60  {
61  // This matrix will store the right singular values; we do not need them.
62  arma::mat v, sigma;
63 
64  // Do singular value decomposition using the QUIC-SVD algorithm.
65  svd::QUIC_SVD quicsvd(centeredData, eigvec, v, sigma, epsilon, delta);
66 
67  // Now we must square the singular values to get the eigenvalues.
68  // In addition we must divide by the number of points, because the
69  // covariance matrix is X * X' / (N - 1).
70  eigVal = arma::pow(arma::diagvec(sigma), 2) / (data.n_cols - 1);
71 
72  // Project the samples to the principals.
73  transformedData = arma::trans(eigvec) * centeredData;
74  }
75 
77  double Epsilon() const { return epsilon; }
79  double& Epsilon() { return epsilon; }
80 
82  double Delta() const { return delta; }
84  double& Delta() { return delta; }
85 
86  private:
88  double epsilon;
89 
91  double delta;
92 };
93 
94 } // namespace pca
95 } // namespace mlpack
96 
97 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
The core includes that mlpack expects; standard C++ includes and Armadillo.
double & Epsilon()
Modify the error tolerance fraction for calculated subspace.
double epsilon
Error tolerance fraction for calculated subspace.
QUICSVDPolicy(const double epsilon=0.03, const double delta=0.1)
Use QUIC-SVD method to perform the principal components analysis (PCA).
double & Delta()
Modify the cumulative probability for Monte Carlo error lower bound.
void Apply(const arma::mat &data, const arma::mat &centeredData, arma::mat &transformedData, arma::vec &eigVal, arma::mat &eigvec, const size_t)
Apply Principal Component Analysis to the provided data set using the QUIC-SVD method.
double Epsilon() const
Get the error tolerance fraction for calculated subspace.
double delta
Cumulative probability for Monte Carlo error lower bound.
double Delta() const
Get the cumulative probability for Monte Carlo error lower bound.
QUIC-SVD is a matrix factorization technique, which operates in a subspace such that A&#39;s approximatio...
Definition: quic_svd.hpp:53
Implementation of the QUIC-SVD policy.