MLPACK  1.0.11
sparse_coding.hpp
Go to the documentation of this file.
1 
23 #ifndef __MLPACK_METHODS_SPARSE_CODING_SPARSE_CODING_HPP
24 #define __MLPACK_METHODS_SPARSE_CODING_SPARSE_CODING_HPP
25 
26 #include <mlpack/core.hpp>
28 
29 // Include our three simple dictionary initializers.
30 #include "nothing_initializer.hpp"
32 #include "random_initializer.hpp"
33 
34 namespace mlpack {
35 namespace sparse_coding {
36 
118 template<typename DictionaryInitializer = DataDependentRandomInitializer>
120 {
121  public:
130  SparseCoding(const arma::mat& data,
131  const size_t atoms,
132  const double lambda1,
133  const double lambda2 = 0);
134 
146  void Encode(const size_t maxIterations = 0,
147  const double objTolerance = 0.01,
148  const double newtonTolerance = 1e-6);
149 
153  void OptimizeCode();
154 
167  double OptimizeDictionary(const arma::uvec& adjacencies,
168  const double newtonTolerance = 1e-6,
169  const size_t maxIterations = 50);
170 
174  void ProjectDictionary();
175 
179  double Objective() const;
180 
182  const arma::mat& Data() const { return data; }
183 
185  const arma::mat& Dictionary() const { return dictionary; }
187  arma::mat& Dictionary() { return dictionary; }
188 
190  const arma::mat& Codes() const { return codes; }
192  arma::mat& Codes() { return codes; }
193 
194  // Returns a string representation of this object.
195  std::string ToString() const;
196 
197  private:
199  size_t atoms;
200 
202  const arma::mat& data;
203 
205  arma::mat dictionary;
206 
208  arma::mat codes;
209 
211  double lambda1;
212 
214  double lambda2;
215 };
216 
217 }; // namespace sparse_coding
218 }; // namespace mlpack
219 
220 // Include implementation.
221 #include "sparse_coding_impl.hpp"
222 
223 #endif
arma::mat & Codes()
Modify the sparse codes.
void ProjectDictionary()
Project each atom of the dictionary back onto the unit ball, if necessary.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:31
const arma::mat & data
Data matrix (columns are points).
arma::mat & Dictionary()
Modify the dictionary.
const arma::mat & Dictionary() const
Access the dictionary.
void Encode(const size_t maxIterations=0, const double objTolerance=0.01, const double newtonTolerance=1e-6)
Run Sparse Coding with Dictionary Learning.
arma::mat dictionary
Dictionary (columns are atoms).
double lambda1
l1 regularization term.
An implementation of Sparse Coding with Dictionary Learning that achieves sparsity via an l1-norm reg...
const arma::mat & Data() const
Access the data.
void OptimizeCode()
Sparse code each point via LARS.
SparseCoding(const arma::mat &data, const size_t atoms, const double lambda1, const double lambda2=0)
Set the parameters to SparseCoding.
const arma::mat & Codes() const
Access the sparse codes.
double Objective() const
Compute the objective function.
double OptimizeDictionary(const arma::uvec &adjacencies, const double newtonTolerance=1e-6, const size_t maxIterations=50)
Learn dictionary via Newton method based on Lagrange dual.
double lambda2
l2 regularization term.
arma::mat codes
Sparse codes (columns are points).