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