[mlpack] 18/149: Fix a couple bugs pointed out by Francois Berrier: SGD isn't actually shuffling, and also the final returned objective may not be correct.

Barak A. Pearlmutter barak+git at pearlmutter.net
Sat May 2 09:11:04 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 c1227336589c943108c6d806974be5913ffe2380
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Mon Sep 29 21:02:58 2014 +0000

    Fix a couple bugs pointed out by Francois Berrier: SGD isn't actually shuffling,
    and also the final returned objective may not be correct.
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17196 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/core/optimizers/sgd/sgd_impl.hpp      | 15 +++++++++++++--
 src/mlpack/core/optimizers/sgd/test_function.hpp |  6 +++---
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/mlpack/core/optimizers/sgd/sgd_impl.hpp b/src/mlpack/core/optimizers/sgd/sgd_impl.hpp
index 1054d5a..9c1f4ef 100644
--- a/src/mlpack/core/optimizers/sgd/sgd_impl.hpp
+++ b/src/mlpack/core/optimizers/sgd/sgd_impl.hpp
@@ -84,17 +84,28 @@ double SGD<DecomposableFunctionType>::Optimize(arma::mat& iterate)
     }
 
     // Evaluate the gradient for this iteration.
-    function.Gradient(iterate, currentFunction, gradient);
+    if (shuffle)
+      function.Gradient(iterate, visitationOrder[currentFunction], gradient);
+    else
+      function.Gradient(iterate, currentFunction, gradient);
 
     // And update the iterate.
     iterate -= stepSize * gradient;
 
     // Now add that to the overall objective function.
-    overallObjective += function.Evaluate(iterate, currentFunction);
+    if (shuffle)
+      overallObjective += function.Evaluate(iterate,
+          visitationOrder[currentFunction]);
+    else
+      overallObjective += function.Evaluate(iterate, currentFunction);
   }
 
   Log::Info << "SGD: maximum iterations (" << maxIterations << ") reached; "
       << "terminating optimization." << std::endl;
+  // Calculate final objective.
+  overallObjective = 0;
+  for (size_t i = 0; i < numFunctions; ++i)
+    overallObjective += function.Evaluate(iterate, i);
   return overallObjective;
 }
 
diff --git a/src/mlpack/core/optimizers/sgd/test_function.hpp b/src/mlpack/core/optimizers/sgd/test_function.hpp
index deaa5b0..7b8407c 100644
--- a/src/mlpack/core/optimizers/sgd/test_function.hpp
+++ b/src/mlpack/core/optimizers/sgd/test_function.hpp
@@ -14,9 +14,9 @@ namespace optimization {
 namespace test {
 
 //! Very, very simple test function which is the composite of three other
-//! functions.  It turns out that although this function is very simple,
-//! optimizing it fully can take a very long time.  It seems to take in excess
-//! of 10 million iterations with a step size of 0.0005.
+//! functions.  The gradient is not very steep far away from the optimum, so a
+//! larger step size may be required to optimize it in a reasonable number of
+//! iterations.
 class SGDTestFunction
 {
  public:

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