[mlpack] 136/149: Add maxIterations parameter to limit the number of iterations used in the Newton method.

Barak A. Pearlmutter barak+git at pearlmutter.net
Sat May 2 09:11:18 UTC 2015


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit d6f3f237cfbaa1c4577ea9ff0dff4042dc208faf
Author: marcus <marcus at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Thu Dec 4 21:38:04 2014 +0000

    Add maxIterations parameter to limit the number of iterations used in the Newton method.
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17442 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/methods/sparse_coding/sparse_coding.hpp      | 5 ++++-
 src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp | 7 ++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/mlpack/methods/sparse_coding/sparse_coding.hpp b/src/mlpack/methods/sparse_coding/sparse_coding.hpp
index 7fec3ae..f3f258e 100644
--- a/src/mlpack/methods/sparse_coding/sparse_coding.hpp
+++ b/src/mlpack/methods/sparse_coding/sparse_coding.hpp
@@ -144,11 +144,14 @@ class SparseCoding
    *    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.
diff --git a/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp b/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
index 08ac5b7..17d04fb 100644
--- a/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
+++ b/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
@@ -119,7 +119,8 @@ void SparseCoding<DictionaryInitializer>::OptimizeCode()
 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 SparseCoding<DictionaryInitializer>::OptimizeDictionary(
   }
 
   double normGradient;
-  double improvement;
+  double improvement = 0;
   for (size_t t = 1; !converged; ++t)
   {
     arma::mat A = codesZT + diagmat(dualVars);
@@ -228,7 +229,7 @@ double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
     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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list