mlpack 3.4.2
sparse_coding.hpp
Go to the documentation of this file.
1
13#ifndef MLPACK_METHODS_SPARSE_CODING_SPARSE_CODING_HPP
14#define MLPACK_METHODS_SPARSE_CODING_SPARSE_CODING_HPP
15
16#include <mlpack/prereqs.hpp>
18
19// Include our three simple dictionary initializers.
23
24namespace mlpack {
25namespace sparse_coding {
26
116{
117 public:
145 template<typename DictionaryInitializer = DataDependentRandomInitializer>
146 SparseCoding(const arma::mat& data,
147 const size_t atoms,
148 const double lambda1,
149 const double lambda2 = 0,
150 const size_t maxIterations = 0,
151 const double objTolerance = 0.01,
152 const double newtonTolerance = 1e-6,
153 const DictionaryInitializer& initializer =
154 DictionaryInitializer());
155
172 SparseCoding(const size_t atoms = 0,
173 const double lambda1 = 0,
174 const double lambda2 = 0,
175 const size_t maxIterations = 0,
176 const double objTolerance = 0.01,
177 const double newtonTolerance = 1e-6);
178
183 template<typename DictionaryInitializer = DataDependentRandomInitializer>
184 double Train(const arma::mat& data,
185 const DictionaryInitializer& initializer =
186 DictionaryInitializer());
187
195 void Encode(const arma::mat& data, arma::mat& codes);
196
208 double OptimizeDictionary(const arma::mat& data,
209 const arma::mat& codes,
210 const arma::uvec& adjacencies);
211
216
220 double Objective(const arma::mat& data, const arma::mat& codes) const;
221
223 const arma::mat& Dictionary() const { return dictionary; }
225 arma::mat& Dictionary() { return dictionary; }
226
228 size_t Atoms() const { return atoms; }
230 size_t& Atoms() { return atoms; }
231
233 double Lambda1() const { return lambda1; }
235 double& Lambda1() { return lambda1; }
236
238 double Lambda2() const { return lambda2; }
240 double& Lambda2() { return lambda2; }
241
243 size_t MaxIterations() const { return maxIterations; }
245 size_t& MaxIterations() { return maxIterations; }
246
248 double ObjTolerance() const { return objTolerance; }
250 double& ObjTolerance() { return objTolerance; }
251
253 double NewtonTolerance() const { return newtonTolerance; }
255 double& NewtonTolerance() { return newtonTolerance; }
256
258 template<typename Archive>
259 void serialize(Archive& ar, const unsigned int /* version */);
260
261 private:
263 size_t atoms;
264
266 arma::mat dictionary;
267
269 double lambda1;
271 double lambda2;
272
274 size_t maxIterations;
276 double objTolerance;
278 double newtonTolerance;
279};
280
281} // namespace sparse_coding
282} // namespace mlpack
283
284// Include implementation.
285#include "sparse_coding_impl.hpp"
286
287#endif
An implementation of Sparse Coding with Dictionary Learning that achieves sparsity via an l1-norm reg...
double & ObjTolerance()
Modify the objective tolerance.
double Lambda1() const
Access the L1 regularization term.
double OptimizeDictionary(const arma::mat &data, const arma::mat &codes, const arma::uvec &adjacencies)
Learn dictionary via Newton method based on Lagrange dual.
arma::mat & Dictionary()
Modify the dictionary.
const arma::mat & Dictionary() const
Access the dictionary.
size_t MaxIterations() const
Get the maximum number of iterations.
double & NewtonTolerance()
Modify the tolerance for Newton's method (dictionary optimization step).
void Encode(const arma::mat &data, arma::mat &codes)
Sparse code each point in the given dataset via LARS, using the current dictionary and store the enco...
SparseCoding(const arma::mat &data, const size_t atoms, const double lambda1, const double lambda2=0, const size_t maxIterations=0, const double objTolerance=0.01, const double newtonTolerance=1e-6, const DictionaryInitializer &initializer=DictionaryInitializer())
Set the parameters to SparseCoding.
double Train(const arma::mat &data, const DictionaryInitializer &initializer=DictionaryInitializer())
Train the sparse coding model on the given dataset.
double NewtonTolerance() const
Get the tolerance for Newton's method (dictionary optimization step).
size_t & MaxIterations()
Modify the maximum number of iterations.
double & Lambda1()
Modify the L1 regularization term.
double Objective(const arma::mat &data, const arma::mat &codes) const
Compute the objective function.
double ObjTolerance() const
Get the objective tolerance.
double Lambda2() const
Access the L2 regularization term.
void ProjectDictionary()
Project each atom of the dictionary back onto the unit ball, if necessary.
size_t & Atoms()
Modify the number of atoms.
size_t Atoms() const
Access the number of atoms.
SparseCoding(const size_t atoms=0, const double lambda1=0, const double lambda2=0, const size_t maxIterations=0, const double objTolerance=0.01, const double newtonTolerance=1e-6)
Set the parameters to SparseCoding.
void serialize(Archive &ar, const unsigned int)
Serialize the sparse coding model.
double & Lambda2()
Modify the L2 regularization term.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.