regularized_svd_function.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_REGULARIZED_SVD_REGULARIZED_FUNCTION_SVD_HPP
14 #define MLPACK_METHODS_REGULARIZED_SVD_REGULARIZED_FUNCTION_SVD_HPP
15 
16 #include <mlpack/prereqs.hpp>
20 
21 namespace mlpack {
22 namespace svd {
23 
30 template <typename MatType = arma::mat>
32 {
33  public:
43  RegularizedSVDFunction(const MatType& data,
44  const size_t rank,
45  const double lambda);
46 
50  void Shuffle();
51 
57  double Evaluate(const arma::mat& parameters) const;
58 
67  double Evaluate(const arma::mat& parameters,
68  const size_t start,
69  const size_t batchSize = 1) const;
70 
78  void Gradient(const arma::mat& parameters,
79  arma::mat& gradient) const;
80 
93  template <typename GradType>
94  void Gradient(const arma::mat& parameters,
95  const size_t start,
96  GradType& gradient,
97  const size_t batchSize = 1) const;
98 
100  const arma::mat& GetInitialPoint() const { return initialPoint; }
101 
103  const arma::mat& Dataset() const { return data; }
104 
106  size_t NumFunctions() const { return data.n_cols; }
107 
109  size_t NumUsers() const { return numUsers; }
110 
112  size_t NumItems() const { return numItems; }
113 
115  double Lambda() const { return lambda; }
116 
118  size_t Rank() const { return rank; }
119 
120  private:
122  MatType data;
124  arma::mat initialPoint;
126  size_t rank;
128  double lambda;
130  size_t numUsers;
132  size_t numItems;
133 };
134 
135 } // namespace svd
136 } // namespace mlpack
137 
138 namespace mlpack {
139 namespace optimization {
140 
147  template <>
148  template <>
149  inline double StandardSGD::Optimize(
151  arma::mat& parameters);
152 
153  template <>
154  template <>
155  inline double ParallelSGD<ExponentialBackoff>::Optimize(
157  arma::mat& parameters);
158 
159 } // namespace optimization
160 } // namespace mlpack
161 
162 #include "regularized_svd_function_impl.hpp"
163 
164 #endif
size_t NumFunctions() const
Return the number of training examples. Useful for SGD optimizer.
void Gradient(const arma::mat &parameters, arma::mat &gradient) const
Evaluates the full gradient of the cost function over all the training examples.
const arma::mat & GetInitialPoint() const
Return the initial point for the optimization.
.hpp
Definition: add_to_po.hpp:21
void Shuffle()
Shuffle the points in the dataset.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t NumUsers() const
Return the number of users in the data.
size_t NumItems() const
Return the number of items in the data.
double Lambda() const
Return the regularization parameters.
size_t Rank() const
Return the rank used for the factorization.
const arma::mat & Dataset() const
Return the dataset passed into the constructor.
RegularizedSVDFunction(const MatType &data, const size_t rank, const double lambda)
Constructor for RegularizedSVDFunction class.
double Evaluate(const arma::mat &parameters) const
Evaluates the cost function over all examples in the data.
The data is stored in a matrix of type MatType, so that this class can be used with both dense and sp...