[mlpack-svn] r17454 - in mlpack/tags/mlpack-1.0.11: . src/mlpack/core/optimizers/sgd

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Sun Dec 7 14:18:32 EST 2014


Author: rcurtin
Date: Sun Dec  7 14:18:31 2014
New Revision: 17454

Log:
Backport SGD fixes from r17196.


Modified:
   mlpack/tags/mlpack-1.0.11/   (props changed)
   mlpack/tags/mlpack-1.0.11/src/mlpack/core/optimizers/sgd/sgd_impl.hpp
   mlpack/tags/mlpack-1.0.11/src/mlpack/core/optimizers/sgd/test_function.hpp

Modified: mlpack/tags/mlpack-1.0.11/src/mlpack/core/optimizers/sgd/sgd_impl.hpp
==============================================================================
--- mlpack/tags/mlpack-1.0.11/src/mlpack/core/optimizers/sgd/sgd_impl.hpp	(original)
+++ mlpack/tags/mlpack-1.0.11/src/mlpack/core/optimizers/sgd/sgd_impl.hpp	Sun Dec  7 14:18:31 2014
@@ -99,17 +99,28 @@
     }
 
     // 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;
 }
 

Modified: mlpack/tags/mlpack-1.0.11/src/mlpack/core/optimizers/sgd/test_function.hpp
==============================================================================
--- mlpack/tags/mlpack-1.0.11/src/mlpack/core/optimizers/sgd/test_function.hpp	(original)
+++ mlpack/tags/mlpack-1.0.11/src/mlpack/core/optimizers/sgd/test_function.hpp	Sun Dec  7 14:18:31 2014
@@ -29,9 +29,9 @@
 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:



More information about the mlpack-svn mailing list