[mlpack-svn] r13271 - mlpack/trunk/src/mlpack/methods/sparse_coding

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Jul 20 15:35:01 EDT 2012


Author: niche
Date: 2012-07-20 15:35:00 -0400 (Fri, 20 Jul 2012)
New Revision: 13271

Modified:
   mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp
   mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
Log:
modified OptimizeDictionary to return norm of gradient of Lagrange dual (with respect to dual variables)

Modified: mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp	2012-07-20 19:18:22 UTC (rev 13270)
+++ mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp	2012-07-20 19:35:00 UTC (rev 13271)
@@ -144,9 +144,11 @@
    *    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.
+   * @return the norm of the gradient of the Lagrange dual with respect to
+   *    the dual variables
    */
-  void OptimizeDictionary(const arma::uvec& adjacencies,
-                          const double newtonTolerance = 1e-6);
+  double 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-07-20 19:18:22 UTC (rev 13270)
+++ mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp	2012-07-20 19:35:00 UTC (rev 13271)
@@ -113,7 +113,7 @@
 
 // Dictionary step for optimization.
 template<typename DictionaryInitializer>
-void SparseCoding<DictionaryInitializer>::OptimizeDictionary(
+double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
     const arma::uvec& adjacencies,
     const double newtonTolerance)
 {
@@ -202,6 +202,7 @@
     codesZT = matActiveZ * trans(matActiveZ);
   }
 
+  double normGradient;
   double improvement;
   for (size_t t = 1; !converged; ++t)
   {
@@ -244,7 +245,7 @@
 
     // Take step and print useful information.
     dualVars += searchDirection;
-    double normGradient = norm(gradient, 2);
+    normGradient = norm(gradient, 2);
     Log::Debug << "Newton Method iteration " << t << ":" << std::endl;
     Log::Debug << "  Gradient norm: " << std::scientific << normGradient
         << "." << std::endl;
@@ -288,6 +289,7 @@
     }
   }
   //printf("final reconstruction error: %e\n", norm(data - dictionary * codes, "fro"));
+  return normGradient;
 }
 
 // Project each atom of the dictionary back into the unit ball (if necessary).




More information about the mlpack-svn mailing list