[mlpack] 07/44: Backport SGD fixes from r17196.
Barak A. Pearlmutter
barak+git at pearlmutter.net
Mon Feb 15 19:35:52 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 87c237703b2c53f73cece77de3d125361907fee3
Author: Ryan Curtin <ryan at ratml.org>
Date: Sun Dec 7 19:18:31 2014 +0000
Backport SGD fixes from r17196.
---
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 079027d..55c9119 100644
--- a/src/mlpack/core/optimizers/sgd/sgd_impl.hpp
+++ b/src/mlpack/core/optimizers/sgd/sgd_impl.hpp
@@ -99,17 +99,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 c8db8e8..9ef9e11 100644
--- a/src/mlpack/core/optimizers/sgd/test_function.hpp
+++ b/src/mlpack/core/optimizers/sgd/test_function.hpp
@@ -29,9 +29,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