[mlpack-git] master: Add maxIterations parameter to limit the number of iterations used in the Newton method. (c8316e9)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:04:38 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit c8316e9ae0eac64581db1ce8a1741d8359d87625
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date: Thu Dec 4 21:38:04 2014 +0000
Add maxIterations parameter to limit the number of iterations used in the Newton method.
>---------------------------------------------------------------
c8316e9ae0eac64581db1ce8a1741d8359d87625
src/mlpack/methods/sparse_coding/sparse_coding.hpp | 5 ++++-
src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp | 7 ++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/mlpack/methods/sparse_coding/sparse_coding.hpp b/src/mlpack/methods/sparse_coding/sparse_coding.hpp
index 7fec3ae..f3f258e 100644
--- a/src/mlpack/methods/sparse_coding/sparse_coding.hpp
+++ b/src/mlpack/methods/sparse_coding/sparse_coding.hpp
@@ -144,11 +144,14 @@ class SparseCoding
* the coding matrix Z that are non-zero (the adjacency matrix for the
* bipartite graph of points and atoms).
* @param newtonTolerance Tolerance of the Newton's method optimizer.
+ * @param maxIterations Maximum number of iterations to run the Newton's method.
+ * If 0, the method will run until convergence (or forever).
* @return the norm of the gradient of the Lagrange dual with respect to
* the dual variables
*/
double OptimizeDictionary(const arma::uvec& adjacencies,
- const double newtonTolerance = 1e-6);
+ const double newtonTolerance = 1e-6,
+ const size_t maxIterations = 50);
/**
* Project each atom of the dictionary back onto the unit ball, if necessary.
diff --git a/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp b/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
index 08ac5b7..17d04fb 100644
--- a/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
+++ b/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
@@ -119,7 +119,8 @@ void SparseCoding<DictionaryInitializer>::OptimizeCode()
template<typename DictionaryInitializer>
double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
const arma::uvec& adjacencies,
- const double newtonTolerance)
+ const double newtonTolerance,
+ const size_t maxIterations)
{
// Count the number of atomic neighbors for each point x^i.
arma::uvec neighborCounts = arma::zeros<arma::uvec>(data.n_cols, 1);
@@ -207,7 +208,7 @@ double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
}
double normGradient;
- double improvement;
+ double improvement = 0;
for (size_t t = 1; !converged; ++t)
{
arma::mat A = codesZT + diagmat(dualVars);
@@ -228,7 +229,7 @@ double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
const double rho = 0.9;
double sufficientDecrease = c * dot(gradient, searchDirection);
- while (true)
+ for (size_t t = 1; t != maxIterations; ++t)
{
// Calculate objective.
double sumDualVars = arma::sum(dualVars);
More information about the mlpack-git
mailing list