[mlpack-svn] r13120 - mlpack/trunk/src/mlpack/methods/sparse_coding
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Jun 27 16:21:28 EDT 2012
Author: rcurtin
Date: 2012-06-27 16:21:28 -0400 (Wed, 27 Jun 2012)
New Revision: 13120
Modified:
mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp
mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
Log:
Make OBJ_TOL and NEWTON_TOL parameters to the methods.
Modified: mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp 2012-06-27 19:57:06 UTC (rev 13119)
+++ mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp 2012-06-27 20:21:28 UTC (rev 13120)
@@ -122,8 +122,15 @@
*
* @param maxIterations Maximum number of iterations to run algorithm. If 0,
* the algorithm will run until convergence (or forever).
+ * @param objTolerance Tolerance for objective function. When an iteration of
+ * the algorithm produces an improvement smaller than this, the algorithm
+ * will terminate.
+ * @param newtonTolerance Tolerance for the Newton's method dictionary
+ * optimization step.
*/
- void Encode(const size_t maxIterations = 0);
+ void Encode(const size_t maxIterations = 0,
+ const double objTolerance = 0.01,
+ const double newtonTolerance = 1e-6);
/**
* Sparse code each point via LARS.
@@ -136,8 +143,10 @@
* @param adjacencies Indices of entries (unrolled column by column) of
* 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.
*/
- void OptimizeDictionary(const arma::uvec& adjacencies);
+ void OptimizeDictionary(const arma::uvec& adjacencies,
+ const double newtonTolerance = 1e-6);
/**
* Project each atom of the dictionary back onto the unit ball, if necessary.
Modified: mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp 2012-06-27 19:57:06 UTC (rev 13119)
+++ mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp 2012-06-27 20:21:28 UTC (rev 13120)
@@ -14,10 +14,6 @@
namespace mlpack {
namespace sparse_coding {
-// TODO: parameterizable; options to methods?
-#define OBJ_TOL 1e-2 // 1E-9
-#define NEWTON_TOL 1e-6 // 1E-9
-
template<typename DictionaryInitializer>
SparseCoding<DictionaryInitializer>::SparseCoding(const arma::mat& data,
const size_t atoms,
@@ -34,7 +30,9 @@
}
template<typename DictionaryInitializer>
-void SparseCoding<DictionaryInitializer>::Encode(const size_t maxIterations)
+void SparseCoding<DictionaryInitializer>::Encode(const size_t maxIterations,
+ const double objTolerance,
+ const double newtonTolerance)
{
double lastObjVal = DBL_MAX;
@@ -56,7 +54,7 @@
// First step: optimize the dictionary.
Log::Info << "Performing dictionary step... " << std::endl;
- OptimizeDictionary(adjacencies);
+ OptimizeDictionary(adjacencies, newtonTolerance);
Log::Info << " Objective value: " << Objective() << "." << std::endl;
// Second step: perform the coding.
@@ -75,9 +73,9 @@
<< std::scientific << improvement << ")." << std::endl;
// Have we converged?
- if (improvement < OBJ_TOL)
+ if (improvement < objTolerance)
{
- Log::Info << "Converged within tolerance " << OBJ_TOL << ".\n";
+ Log::Info << "Converged within tolerance " << objTolerance << ".\n";
break;
}
@@ -112,7 +110,8 @@
// Dictionary step for optimization.
template<typename DictionaryInitializer>
void SparseCoding<DictionaryInitializer>::OptimizeDictionary(
- const arma::uvec& adjacencies)
+ const arma::uvec& adjacencies,
+ const double newtonTolerance)
{
// Count the number of atomic neighbors for each point x^i.
arma::uvec neighborCounts = arma::zeros<arma::uvec>(data.n_cols, 1);
@@ -250,7 +249,7 @@
<< "." << std::endl;
Log::Debug << " Improvement: " << std::scientific << improvement << ".\n";
- if (improvement < NEWTON_TOL)
+ if (improvement < newtonTolerance)
converged = true;
}
More information about the mlpack-svn
mailing list