MLPACK  1.0.10
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 
165  double OptimizeDictionary(const arma::uvec& adjacencies,
166  const double newtonTolerance = 1e-6);
167 
171  void ProjectDictionary();
172 
176  double Objective() const;
177 
179  const arma::mat& Data() const { return data; }
180 
182  const arma::mat& Dictionary() const { return dictionary; }
184  arma::mat& Dictionary() { return dictionary; }
185 
187  const arma::mat& Codes() const { return codes; }
189  arma::mat& Codes() { return codes; }
190 
191  // Returns a string representation of this object.
192  std::string ToString() const;
193 
194  private:
196  size_t atoms;
197 
199  const arma::mat& data;
200 
202  arma::mat dictionary;
203 
205  arma::mat codes;
206 
208  double lambda1;
209 
211  double lambda2;
212 };
213 
214 }; // namespace sparse_coding
215 }; // namespace mlpack
216 
217 // Include implementation.
218 #include "sparse_coding_impl.hpp"
219 
220 #endif