[mlpack-svn] r17196 - mlpack/trunk/src/mlpack/core/optimizers/sgd
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Sep 29 17:02:59 EDT 2014
Author: rcurtin
Date: Mon Sep 29 17:02:58 2014
New Revision: 17196
Log:
Fix a couple bugs pointed out by Francois Berrier: SGD isn't actually shuffling,
and also the final returned objective may not be correct.
Modified:
mlpack/trunk/src/mlpack/core/optimizers/sgd/sgd_impl.hpp
mlpack/trunk/src/mlpack/core/optimizers/sgd/test_function.hpp
Modified: mlpack/trunk/src/mlpack/core/optimizers/sgd/sgd_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/optimizers/sgd/sgd_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/core/optimizers/sgd/sgd_impl.hpp Mon Sep 29 17:02:58 2014
@@ -84,17 +84,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/trunk/src/mlpack/core/optimizers/sgd/test_function.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/optimizers/sgd/test_function.hpp (original)
+++ mlpack/trunk/src/mlpack/core/optimizers/sgd/test_function.hpp Mon Sep 29 17:02:58 2014
@@ -14,9 +14,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