[mlpack] 26/44: Backport r17442:17443.

Barak A. Pearlmutter barak+git at pearlmutter.net
Mon Feb 15 19:35:54 UTC 2016


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

bap pushed a commit to tag mlpack-1.0.11
in repository mlpack.

commit af614c331d34a684d34f4cbcd3acd18f420f6086
Author: Ryan Curtin <ryan at ratml.org>
Date:   Sun Dec 7 19:48:08 2014 +0000

    Backport r17442:17443.
---
 src/mlpack/methods/sparse_coding/sparse_coding.hpp      | 5 ++++-
 src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp | 7 ++++---
 src/mlpack/tests/sa_test.cpp                            | 2 +-
 src/mlpack/tests/svd_batch_test.cpp                     | 2 +-
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/mlpack/methods/sparse_coding/sparse_coding.hpp b/src/mlpack/methods/sparse_coding/sparse_coding.hpp
index a356319..654e97f 100644
--- a/src/mlpack/methods/sparse_coding/sparse_coding.hpp
+++ b/src/mlpack/methods/sparse_coding/sparse_coding.hpp
@@ -159,11 +159,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 2ffc32d..6ec6fda 100644
--- a/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
+++ b/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
@@ -134,7 +134,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);
@@ -222,7 +223,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);
@@ -243,7 +244,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 = sum(dualVars);
diff --git a/src/mlpack/tests/sa_test.cpp b/src/mlpack/tests/sa_test.cpp
index 8b090fa..96e12d4 100644
--- a/src/mlpack/tests/sa_test.cpp
+++ b/src/mlpack/tests/sa_test.cpp
@@ -42,7 +42,7 @@ BOOST_AUTO_TEST_SUITE(SATest);
 
 BOOST_AUTO_TEST_CASE(GeneralizedRosenbrockTest)
 {
-  math::RandomSeed(std::time(NULL));
+  mlpack::math::RandomSeed(std::time(NULL));
   size_t dim = 50;
   GeneralizedRosenbrockFunction f(dim);
 
diff --git a/src/mlpack/tests/svd_batch_test.cpp b/src/mlpack/tests/svd_batch_test.cpp
index 088047a..b18e2c5 100644
--- a/src/mlpack/tests/svd_batch_test.cpp
+++ b/src/mlpack/tests/svd_batch_test.cpp
@@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(SVDBatchRegularizationTest)
  */
 BOOST_AUTO_TEST_CASE(SVDBatchNegativeElementTest)
 {
-  math::RandomSeed(std::time(NULL));
+  mlpack::math::RandomSeed(std::time(NULL));
   // Create two 5x3 matrices that we should be able to recover.
   mat testLeft;
   testLeft.randu(5, 3);

-- 
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