randomized_svd_method.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_METHODS_CF_DECOMPOSITION_POLICIES_RANDOMIZED_SVD_METHOD_HPP
15 #define MLPACK_METHODS_CF_DECOMPOSITION_POLICIES_RANDOMIZED_SVD_METHOD_HPP
16 
17 #include <mlpack/prereqs.hpp>
19 
20 namespace mlpack {
21 namespace cf {
22 
28 {
29  public:
38  RandomizedSVDPolicy(const size_t iteratedPower = 0,
39  const size_t maxIterations = 2) :
40  iteratedPower(iteratedPower),
41  maxIterations(maxIterations)
42  {
43  /* Nothing to do here */
44  }
45 
60  template<typename MatType>
61  void Apply(const MatType& /* data */,
62  const arma::sp_mat& cleanedData,
63  const size_t rank,
64  arma::mat& w,
65  arma::mat& h,
66  const size_t maxIterations,
67  const double /* minResidue */,
68  const bool /* mit */)
69  {
70  arma::vec sigma;
71 
72  // Do singular value decomposition using the randomized SVD algorithm.
73  svd::RandomizedSVD rsvd(iteratedPower, maxIterations);
74  rsvd.Apply(cleanedData, w, sigma, h, rank);
75 
76  // Sigma matrix is multiplied to w.
77  w = w * arma::diagmat(sigma);
78 
79  // Take transpose of the matrix h as required by CF class.
80  h = arma::trans(h);
81  }
82 
84  size_t IteratedPower() const { return iteratedPower; }
86  size_t& IteratedPower() { return iteratedPower; }
87 
89  size_t MaxIterations() const { return maxIterations; }
91  size_t& MaxIterations() { return maxIterations; }
92 
93  private:
95  size_t iteratedPower;
96 
98  size_t maxIterations;
99 };
100 
101 } // namespace cf
102 } // namespace mlpack
103 
104 #endif
.hpp
Definition: add_to_po.hpp:21
size_t IteratedPower() const
Get the size of the normalized power iterations.
The core includes that mlpack expects; standard C++ includes and Armadillo.
Randomized SVD is a matrix factorization that is based on randomized matrix approximation techniques...
void Apply(const MatType &, const arma::sp_mat &cleanedData, const size_t rank, arma::mat &w, arma::mat &h, const size_t maxIterations, const double, const bool)
Apply Collaborative Filtering to the provided data set using the randomized SVD.
size_t MaxIterations() const
Get the number of iterations.
RandomizedSVDPolicy(const size_t iteratedPower=0, const size_t maxIterations=2)
Use randomized SVD method to perform collaborative filtering.
size_t & IteratedPower()
Modify the size of the normalized power iterations.
Implementation of the Randomized SVD policy to act as a wrapper when accessing Randomized SVD from wi...
size_t & MaxIterations()
Modify the number of iterations.
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...