[mlpack-git] mlpack-1.0.x: Backport r17442:17443. (a5e481f)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed Jan 7 11:58:00 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : mlpack-1.0.x
Link       : https://github.com/mlpack/mlpack/compare/0000000000000000000000000000000000000000...904762495c039e345beba14c1142fd719b3bd50e

>---------------------------------------------------------------

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

    Backport r17442:17443.


>---------------------------------------------------------------

a5e481f64a57ed7e46b3f5ad559aba4b3156bf12
 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);



More information about the mlpack-git mailing list