13 #ifndef MLPACK_METHODS_SPARSE_CODING_SPARSE_CODING_HPP 14 #define MLPACK_METHODS_SPARSE_CODING_SPARSE_CODING_HPP 25 namespace sparse_coding {
145 template<
typename DictionaryInitializer = DataDependentRandomInitializer>
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());
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);
183 template<
typename DictionaryInitializer = DataDependentRandomInitializer>
184 double Train(
const arma::mat& data,
185 const DictionaryInitializer& initializer =
186 DictionaryInitializer());
195 void Encode(
const arma::mat& data, arma::mat& codes);
209 const arma::mat& codes,
210 const arma::uvec& adjacencies);
220 double Objective(
const arma::mat& data,
const arma::mat& codes)
const;
228 size_t Atoms()
const {
return atoms; }
258 template<
typename Archive>
259 void serialize(Archive& ar,
const uint32_t );
266 arma::mat dictionary;
274 size_t maxIterations;
278 double newtonTolerance;
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
double Train(const arma::mat &data, const DictionaryInitializer &initializer=DictionaryInitializer())
Train the sparse coding model on the given dataset.
Definition: sparse_coding_impl.hpp:43
The core includes that mlpack expects; standard C++ includes and Armadillo.
void ProjectDictionary()
Project each atom of the dictionary back onto the unit ball, if necessary.
Definition: sparse_coding.cpp:243
double & Lambda1()
Modify the L1 regularization term.
Definition: sparse_coding.hpp:235
arma::mat & Dictionary()
Modify the dictionary.
Definition: sparse_coding.hpp:225
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.
Definition: sparse_coding_impl.hpp:23
double Lambda1() const
Access the L1 regularization term.
Definition: sparse_coding.hpp:233
size_t Atoms() const
Access the number of atoms.
Definition: sparse_coding.hpp:228
An implementation of Sparse Coding with Dictionary Learning that achieves sparsity via an l1-norm reg...
Definition: sparse_coding.hpp:115
double NewtonTolerance() const
Get the tolerance for Newton's method (dictionary optimization step).
Definition: sparse_coding.hpp:253
void serialize(Archive &ar, const uint32_t)
Serialize the sparse coding model.
Definition: sparse_coding_impl.hpp:113
double & ObjTolerance()
Modify the objective tolerance.
Definition: sparse_coding.hpp:250
const arma::mat & Dictionary() const
Access the dictionary.
Definition: sparse_coding.hpp:223
double Lambda2() const
Access the L2 regularization term.
Definition: sparse_coding.hpp:238
double Objective(const arma::mat &data, const arma::mat &codes) const
Compute the objective function.
Definition: sparse_coding.cpp:258
size_t & Atoms()
Modify the number of atoms.
Definition: sparse_coding.hpp:230
double & NewtonTolerance()
Modify the tolerance for Newton's method (dictionary optimization step).
Definition: sparse_coding.hpp:255
size_t MaxIterations() const
Get the maximum number of iterations.
Definition: sparse_coding.hpp:243
size_t & MaxIterations()
Modify the maximum number of iterations.
Definition: sparse_coding.hpp:245
double ObjTolerance() const
Get the objective tolerance.
Definition: sparse_coding.hpp:248
double & Lambda2()
Modify the L2 regularization term.
Definition: sparse_coding.hpp:240
double OptimizeDictionary(const arma::mat &data, const arma::mat &codes, const arma::uvec &adjacencies)
Learn dictionary via Newton method based on Lagrange dual.
Definition: sparse_coding.cpp:62
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...
Definition: sparse_coding.cpp:36