[mlpack-svn] r17442 - mlpack/trunk/src/mlpack/methods/sparse_coding
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Dec 4 16:38:04 EST 2014
Author: marcus
Date: Thu Dec 4 16:38:04 2014
New Revision: 17442
Log:
Add maxIterations parameter to limit the number of iterations used in the Newton method.
Modified:
mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp
mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
Modified: mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp Thu Dec 4 16:38:04 2014
@@ -144,11 +144,14 @@
* the coding matrix Z that are non-zero (the adjacency matrix for the
* bipartite graph of points and atoms).
* @param newtonTolerance Tolerance of the Newton's method optimizer.
+ * @param maxIterations Maximum number of iterations to run the Newton's method.
+ * If 0, the method will run until convergence (or forever).
* @return the norm of the gradient of the Lagrange dual with respect to
* the dual variables
*/
double OptimizeDictionary(const arma::uvec& adjacencies,
- const double newtonTolerance = 1e-6);
+ const double newtonTolerance = 1e-6,
+ const size_t maxIterations = 50);
/**
* Project each atom of the dictionary back onto the unit ball, if necessary.
Modified: mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp Thu Dec 4 16:38:04 2014
@@ -119,7 +119,8 @@
template<typename DictionaryInitializer>
double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
const arma::uvec& adjacencies,
- const double newtonTolerance)
+ const double newtonTolerance,
+ const size_t maxIterations)
{
// Count the number of atomic neighbors for each point x^i.
arma::uvec neighborCounts = arma::zeros<arma::uvec>(data.n_cols, 1);
@@ -207,7 +208,7 @@
}
double normGradient;
- double improvement;
+ double improvement = 0;
for (size_t t = 1; !converged; ++t)
{
arma::mat A = codesZT + diagmat(dualVars);
@@ -228,7 +229,7 @@
const double rho = 0.9;
double sufficientDecrease = c * dot(gradient, searchDirection);
- while (true)
+ for (size_t t = 1; t != maxIterations; ++t)
{
// Calculate objective.
double sumDualVars = arma::sum(dualVars);
More information about the mlpack-svn
mailing list