lcc.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_LOCAL_COORDINATE_CODING_LCC_HPP
14 #define MLPACK_METHODS_LOCAL_COORDINATE_CODING_LCC_HPP
15 
16 #include <mlpack/prereqs.hpp>
18 
19 // Include three simple dictionary initializers from sparse coding.
20 #include "../sparse_coding/nothing_initializer.hpp"
21 #include "../sparse_coding/data_dependent_random_initializer.hpp"
22 #include "../sparse_coding/random_initializer.hpp"
23 
24 namespace mlpack {
25 namespace lcc {
26 
80 {
81  public:
103  template<
104  typename DictionaryInitializer =
106  >
107  LocalCoordinateCoding(const arma::mat& data,
108  const size_t atoms,
109  const double lambda,
110  const size_t maxIterations = 0,
111  const double tolerance = 0.01,
112  const DictionaryInitializer& initializer =
113  DictionaryInitializer());
114 
127  LocalCoordinateCoding(const size_t atoms = 0,
128  const double lambda = 0.0,
129  const size_t maxIterations = 0,
130  const double tolerance = 0.01);
131 
139  template<
140  typename DictionaryInitializer =
142  >
143  double Train(const arma::mat& data,
144  const DictionaryInitializer& initializer =
145  DictionaryInitializer());
146 
153  void Encode(const arma::mat& data, arma::mat& codes);
154 
164  void OptimizeDictionary(const arma::mat& data,
165  const arma::mat& codes,
166  const arma::uvec& adjacencies);
167 
177  double Objective(const arma::mat& data,
178  const arma::mat& codes,
179  const arma::uvec& adjacencies) const;
180 
182  size_t Atoms() const { return atoms; }
184  size_t& Atoms() { return atoms; }
185 
187  const arma::mat& Dictionary() const { return dictionary; }
189  arma::mat& Dictionary() { return dictionary; }
190 
192  double Lambda() const { return lambda; }
194  double& Lambda() { return lambda; }
195 
197  size_t MaxIterations() const { return maxIterations; }
199  size_t& MaxIterations() { return maxIterations; }
200 
202  double Tolerance() const { return tolerance; }
204  double& Tolerance() { return tolerance; }
205 
207  template<typename Archive>
208  void serialize(Archive& ar, const uint32_t /* version */);
209 
210  private:
212  size_t atoms;
213 
215  arma::mat dictionary;
216 
218  double lambda;
219 
221  size_t maxIterations;
223  double tolerance;
224 };
225 
226 } // namespace lcc
227 } // namespace mlpack
228 
229 // Include implementation.
230 #include "lcc_impl.hpp"
231 
232 #endif
double & Lambda()
Modify the L1 regularization parameter.
Definition: lcc.hpp:194
Linear algebra utility functions, generally performed on matrices or vectors.
size_t MaxIterations() const
Get the maximum number of iterations.
Definition: lcc.hpp:197
double & Tolerance()
Modify the objective tolerance.
Definition: lcc.hpp:204
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Encode(const arma::mat &data, arma::mat &codes)
Code each point via distance-weighted LARS.
size_t & Atoms()
Modify the number of atoms.
Definition: lcc.hpp:184
A data-dependent random dictionary initializer for SparseCoding.
arma::mat & Dictionary()
Mutator for dictionary.
Definition: lcc.hpp:189
An implementation of Local Coordinate Coding (LCC) that codes data which approximately lives on a man...
Definition: lcc.hpp:79
const arma::mat & Dictionary() const
Accessor for dictionary.
Definition: lcc.hpp:187
double Objective(const arma::mat &data, const arma::mat &codes, const arma::uvec &adjacencies) const
Compute objective function given the list of adjacencies.
double Tolerance() const
Get the objective tolerance.
Definition: lcc.hpp:202
double Train(const arma::mat &data, const DictionaryInitializer &initializer=DictionaryInitializer())
Run local coordinate coding.
void OptimizeDictionary(const arma::mat &data, const arma::mat &codes, const arma::uvec &adjacencies)
Learn dictionary by solving linear system.
size_t & MaxIterations()
Modify the maximum number of iterations.
Definition: lcc.hpp:199
void serialize(Archive &ar, const uint32_t)
Serialize the model.
size_t Atoms() const
Get the number of atoms.
Definition: lcc.hpp:182
LocalCoordinateCoding(const arma::mat &data, const size_t atoms, const double lambda, const size_t maxIterations=0, const double tolerance=0.01, const DictionaryInitializer &initializer=DictionaryInitializer())
Set the parameters to LocalCoordinateCoding, and train the dictionary.
double Lambda() const
Get the L1 regularization parameter.
Definition: lcc.hpp:192