[mlpack-git] mlpack-1.0.x: Backport r17432:17437. (6899506)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed Jan 7 11:57:42 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : mlpack-1.0.x
Link       : https://github.com/mlpack/mlpack/compare/0000000000000000000000000000000000000000...904762495c039e345beba14c1142fd719b3bd50e

>---------------------------------------------------------------

commit 689950658575ac2b717e92d13967f152d256317b
Author: Ryan Curtin <ryan at ratml.org>
Date:   Sun Dec 7 19:47:07 2014 +0000

    Backport r17432:17437.


>---------------------------------------------------------------

689950658575ac2b717e92d13967f152d256317b
 HISTORY.txt                                        |  3 +++
 .../methods/sparse_coding/sparse_coding_impl.hpp   |  4 ++--
 src/mlpack/tests/cosine_tree_test.cpp              | 22 ++++++++--------------
 src/mlpack/tests/logistic_regression_test.cpp      |  7 +++++--
 src/mlpack/tests/sa_test.cpp                       |  2 +-
 src/mlpack/tests/svd_batch_test.cpp                |  6 +++---
 6 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/HISTORY.txt b/HISTORY.txt
index d0ce8c4..a906829 100644
--- a/HISTORY.txt
+++ b/HISTORY.txt
@@ -18,6 +18,9 @@
   * math::RandomSeed() now sets the random seed for recent (>=3.930) Armadillo
     versions.
 
+  * Handle Newton method convergence better for
+    SparseCoding::OptimizeDictionary() and make maximum iterations a parameter.
+
 2014-08-29    mlpack 1.0.10
 
   * Bugfix for NeighborSearch regression which caused very slow allknn/allkfn.
diff --git a/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp b/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
index d62e13a..2ffc32d 100644
--- a/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
+++ b/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
@@ -270,7 +270,7 @@ double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
         << "." << std::endl;
     Log::Debug << "  Improvement: " << std::scientific << improvement << ".\n";
 
-    if (improvement < newtonTolerance)
+    if (normGradient < newtonTolerance)
       converged = true;
   }
 
@@ -307,7 +307,7 @@ double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
       }
     }
   }
-  //printf("final reconstruction error: %e\n", norm(data - dictionary * codes, "fro"));
+
   return normGradient;
 }
 
diff --git a/src/mlpack/tests/cosine_tree_test.cpp b/src/mlpack/tests/cosine_tree_test.cpp
index 1e410f1..d4edd14 100644
--- a/src/mlpack/tests/cosine_tree_test.cpp
+++ b/src/mlpack/tests/cosine_tree_test.cpp
@@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit)
   nodeStack.push_back(&root);
 
   // While stack is not empty.
-  while(nodeStack.size())
+  while (nodeStack.size())
   {
     // Pop a node from the stack and split it.
     CosineTree *currentNode, *currentLeft, *currentRight;
@@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit)
     currentRight = currentNode->Right();
 
     // If children exist.
-    if(currentLeft && currentRight)
+    if (currentLeft && currentRight)
     {
       // Push the child nodes on to the stack.
       nodeStack.push_back(currentLeft);
@@ -112,28 +112,22 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit)
       cosines.zeros(currentNode->NumColumns());
 
       size_t i, j, k;
-      for(i = 0; i < leftIndices.size(); i++)
-      {
+      for (i = 0; i < leftIndices.size(); i++)
         cosines(i) = arma::norm_dot(data.col(leftIndices[i]), splitPoint);
-      }
-      for(j = 0, k = i; j < rightIndices.size(); j++, k++)
-      {
+
+      for (j = 0, k = i; j < rightIndices.size(); j++, k++)
         cosines(k) = arma::norm_dot(data.col(rightIndices[j]), splitPoint);
-      }
 
       // Check if the columns assigned to the children agree with the splitting
       // condition.
       double cosineMax = arma::max(cosines % (cosines < 1));
       double cosineMin = arma::min(cosines);
 
-      for(i = 0; i < leftIndices.size(); i++)
-      {
+      for (i = 0; i < leftIndices.size(); i++)
         BOOST_CHECK_LT(cosineMax - cosines(i), cosines(i) - cosineMin);
-      }
-      for(j = 0, k = i; j < rightIndices.size(); j++, k++)
-      {
+
+      for (j = 0, k = i; j < rightIndices.size(); j++, k++)
         BOOST_CHECK_GT(cosineMax - cosines(k), cosines(k) - cosineMin);
-      }
     }
   }
 }
diff --git a/src/mlpack/tests/logistic_regression_test.cpp b/src/mlpack/tests/logistic_regression_test.cpp
index 1039150..fa1f3ef 100644
--- a/src/mlpack/tests/logistic_regression_test.cpp
+++ b/src/mlpack/tests/logistic_regression_test.cpp
@@ -556,8 +556,11 @@ BOOST_AUTO_TEST_CASE(LogisticRegressionSGDRegularizationSimpleTest)
                  "1 2 3");
   arma::vec responses("1 1 0");
 
-  // Create a logistic regression object using SGD.
-  LogisticRegression<SGD> lr(data, responses, 0.001);
+  // Create a logistic regression object using custom SGD with a much smaller
+  // tolerance.
+  LogisticRegressionFunction lrf(data, responses, 0.001);
+  SGD<LogisticRegressionFunction> sgd(lrf, 0.005, 500000, 1e-10);
+  LogisticRegression<SGD> lr(sgd);
 
   // Test sigmoid function.
   arma::vec sigmoids = 1 / (1 + arma::exp(-lr.Parameters()[0]
diff --git a/src/mlpack/tests/sa_test.cpp b/src/mlpack/tests/sa_test.cpp
index e73ff8b..8b090fa 100644
--- a/src/mlpack/tests/sa_test.cpp
+++ b/src/mlpack/tests/sa_test.cpp
@@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(GeneralizedRosenbrockTest)
     result = sa.Optimize(coordinates);
     ++iteration;
 
-    BOOST_REQUIRE_LT(iteration, 3); // No more than three tries.
+    BOOST_REQUIRE_LT(iteration, 4); // No more than three tries.
   }
 
   // 0.1% tolerance for each coordinate.
diff --git a/src/mlpack/tests/svd_batch_test.cpp b/src/mlpack/tests/svd_batch_test.cpp
index 1e02eea..088047a 100644
--- a/src/mlpack/tests/svd_batch_test.cpp
+++ b/src/mlpack/tests/svd_batch_test.cpp
@@ -174,14 +174,14 @@ BOOST_AUTO_TEST_CASE(SVDBatchNegativeElementTest)
       RandomInitialization,
       SVDBatchLearning> amf(SimpleToleranceTermination<mat>(),
                             RandomInitialization(),
-                            SVDBatchLearning(0.3, 0.001, 0.001, 0));
+                            SVDBatchLearning(0.1, 0.001, 0.001, 0));
   mat m1, m2;
   amf.Apply(test, 3, m1, m2);
 
   arma::mat result = m1 * m2;
 
-  // 2% tolerance on the norm.
-  BOOST_REQUIRE_CLOSE(arma::norm(test, "fro"), arma::norm(result, "fro"), 2.0);
+  // 5% tolerance on the norm.
+  BOOST_REQUIRE_CLOSE(arma::norm(test, "fro"), arma::norm(result, "fro"), 5.0);
 }
 
 BOOST_AUTO_TEST_SUITE_END();



More information about the mlpack-git mailing list