12 #ifndef MLPACK_METHODS_LOCAL_COORDINATE_CODING_LCC_IMPL_HPP 13 #define MLPACK_METHODS_LOCAL_COORDINATE_CODING_LCC_IMPL_HPP 21 template<
typename DictionaryInitializer>
23 const arma::mat&
data,
26 const size_t maxIterations,
27 const double tolerance,
28 const DictionaryInitializer& initializer) :
31 maxIterations(maxIterations),
35 Train(data, initializer);
38 template<
typename DictionaryInitializer>
40 const arma::mat&
data,
41 const DictionaryInitializer& initializer)
46 initializer.Initialize(data, atoms, dictionary);
48 double lastObjVal = DBL_MAX;
52 Log::Info <<
"Initial Coding Step." << std::endl;
56 arma::uvec adjacencies = find(codes);
58 Log::Info <<
" Sparsity level: " << 100.0 * ((double)(adjacencies.n_elem)) /
59 ((
double)(atoms * data.n_cols)) <<
"%.\n";
63 for (
size_t t = 1; t != maxIterations; t++)
65 Log::Info <<
"Iteration " << t <<
" of " << maxIterations <<
"." 69 Log::Info <<
"Performing dictionary step..." << std::endl;
71 double dsObjVal =
Objective(data, codes, adjacencies);
72 Log::Info <<
" Objective value: " << dsObjVal <<
"." << std::endl;
75 Log::Info <<
"Performing coding step..." << std::endl;
77 adjacencies = find(codes);
78 Log::Info <<
" Sparsity level: " << 100.0 * ((double) (adjacencies.n_elem))
79 / ((
double)(atoms * data.n_cols)) <<
"%.\n";
82 double curObjVal =
Objective(data, codes, adjacencies);
83 if (curObjVal > dsObjVal)
85 Log::Warn <<
"Objective increased in coding step! Terminating." 92 double improvement = lastObjVal - curObjVal;
93 Log::Info <<
"Objective value: " << curObjVal <<
" (improvement " 94 << std::scientific << improvement <<
")." << std::endl;
96 if (improvement < tolerance)
98 Log::Info <<
"Converged within tolerance " << tolerance <<
".\n";
102 lastObjVal = curObjVal;
109 template<
typename Archive>
113 ar(CEREAL_NVP(atoms));
114 ar(CEREAL_NVP(dictionary));
115 ar(CEREAL_NVP(lambda));
116 ar(CEREAL_NVP(maxIterations));
117 ar(CEREAL_NVP(tolerance));
static void Start(const std::string &name)
Start the given timer.
Definition: timers.cpp:28
double Objective(const arma::mat &data, const arma::mat &codes, const arma::uvec &adjacencies) const
Compute objective function given the list of adjacencies.
Definition: lcc.cpp:226
void OptimizeDictionary(const arma::mat &data, const arma::mat &codes, const arma::uvec &adjacencies)
Learn dictionary by solving linear system.
Definition: lcc.cpp:66
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void serialize(Archive &ar, const uint32_t)
Serialize the model.
Definition: lcc_impl.hpp:110
static MLPACK_EXPORT util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
Definition: log.hpp:87
static void Stop(const std::string &name)
Stop the given timer.
Definition: timers.cpp:36
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.
Definition: lcc_impl.hpp:22
static MLPACK_EXPORT util::PrefixedOutStream Info
Prints informational messages if –verbose is specified, prefixed with [INFO ].
Definition: log.hpp:84
void Encode(const arma::mat &data, arma::mat &codes)
Code each point via distance-weighted LARS.
Definition: lcc.cpp:31
double Train(const arma::mat &data, const DictionaryInitializer &initializer=DictionaryInitializer())
Run local coordinate coding.
Definition: lcc_impl.hpp:39