[mlpack-git] mlpack-1.0.x: Backport SGD fixes from r17196. (e85da00)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed Jan 7 11:57:44 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : mlpack-1.0.x
Link : https://github.com/mlpack/mlpack/compare/0000000000000000000000000000000000000000...904762495c039e345beba14c1142fd719b3bd50e
>---------------------------------------------------------------
commit e85da001c184a74c0f72f18df16688ec058dfc93
Author: Ryan Curtin <ryan at ratml.org>
Date: Sun Dec 7 19:18:31 2014 +0000
Backport SGD fixes from r17196.
>---------------------------------------------------------------
e85da001c184a74c0f72f18df16688ec058dfc93
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:
More information about the mlpack-git
mailing list