mlpack  1.0.12
sparse_coding.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_SPARSE_CODING_SPARSE_CODING_HPP
16 #define __MLPACK_METHODS_SPARSE_CODING_SPARSE_CODING_HPP
17 
18 #include <mlpack/core.hpp>
20 
21 // Include our three simple dictionary initializers.
22 #include "nothing_initializer.hpp"
24 #include "random_initializer.hpp"
25 
26 namespace mlpack {
27 namespace sparse_coding {
28 
110 template<typename DictionaryInitializer = DataDependentRandomInitializer>
112 {
113  public:
122  SparseCoding(const arma::mat& data,
123  const size_t atoms,
124  const double lambda1,
125  const double lambda2 = 0);
126 
138  void Encode(const size_t maxIterations = 0,
139  const double objTolerance = 0.01,
140  const double newtonTolerance = 1e-6);
141 
145  void OptimizeCode();
146 
159  double OptimizeDictionary(const arma::uvec& adjacencies,
160  const double newtonTolerance = 1e-6,
161  const size_t maxIterations = 50);
162 
166  void ProjectDictionary();
167 
171  double Objective() const;
172 
174  const arma::mat& Data() const { return data; }
175 
177  const arma::mat& Dictionary() const { return dictionary; }
179  arma::mat& Dictionary() { return dictionary; }
180 
182  const arma::mat& Codes() const { return codes; }
184  arma::mat& Codes() { return codes; }
185 
186  // Returns a string representation of this object.
187  std::string ToString() const;
188 
189  private:
191  size_t atoms;
192 
194  const arma::mat& data;
195 
197  arma::mat dictionary;
198 
200  arma::mat codes;
201 
203  double lambda1;
204 
206  double lambda2;
207 };
208 
209 }; // namespace sparse_coding
210 }; // namespace mlpack
211 
212 // Include implementation.
213 #include "sparse_coding_impl.hpp"
214 
215 #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:23
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).