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>
17 #include <ensmallen.hpp>
18 
19 namespace mlpack {
20 namespace svd {
21 
28 template <typename MatType = arma::mat>
30 {
31  public:
41  RegularizedSVDFunction(const MatType& data,
42  const size_t rank,
43  const double lambda);
44 
48  void Shuffle();
49 
55  double Evaluate(const arma::mat& parameters) const;
56 
65  double Evaluate(const arma::mat& parameters,
66  const size_t start,
67  const size_t batchSize = 1) const;
68 
76  void Gradient(const arma::mat& parameters,
77  arma::mat& gradient) const;
78 
91  template <typename GradType>
92  void Gradient(const arma::mat& parameters,
93  const size_t start,
94  GradType& gradient,
95  const size_t batchSize = 1) const;
96 
98  const arma::mat& GetInitialPoint() const { return initialPoint; }
99 
101  const arma::mat& Dataset() const { return data; }
102 
104  size_t NumFunctions() const { return data.n_cols; }
105 
107  size_t NumUsers() const { return numUsers; }
108 
110  size_t NumItems() const { return numItems; }
111 
113  double Lambda() const { return lambda; }
114 
116  size_t Rank() const { return rank; }
117 
118  private:
120  MatType data;
122  arma::mat initialPoint;
124  size_t rank;
126  double lambda;
128  size_t numUsers;
130  size_t numItems;
131 };
132 
133 } // namespace svd
134 } // namespace mlpack
135 
136 namespace ens {
137 
144  template <>
145  template <>
146  inline double StandardSGD::Optimize(
148  arma::mat& parameters);
149 
150  template <>
151  template <>
152  inline double ParallelSGD<ExponentialBackoff>::Optimize(
154  arma::mat& parameters);
155 
156 } // namespace ens
157 
158 #include "regularized_svd_function_impl.hpp"
159 
160 #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.
strip_type.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...