[mlpack] 183/324: * Added convergence test for SVDBatch and SVDIncremental learning
Barak A. Pearlmutter
barak+git at cs.nuim.ie
Sun Aug 17 08:22:08 UTC 2014
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch svn-trunk
in repository mlpack.
commit bf1be19e2dd9641afd7c367115f2f31d9da0cb90
Author: sumedhghaisas <sumedhghaisas at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date: Mon Jul 14 20:37:58 2014 +0000
* Added convergence test for SVDBatch and SVDIncremental learning
git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16822 9d5b8971-822b-0410-80eb-d18c1038ef23
---
.../incomplete_incremental_termination.hpp | 6 +-
.../simple_residue_termination.hpp | 1 +
.../simple_tolerance_termination.hpp | 1 +
.../validation_RMSE_termination.hpp | 12 +--
.../amf/update_rules/svd_incremental_learning.hpp | 2 +
src/mlpack/tests/CMakeLists.txt | 1 +
src/mlpack/tests/svd_batch_test.cpp | 32 ++++++--
src/mlpack/tests/svd_incremental_test.cpp | 91 ++++++++++++++++++++++
8 files changed, 130 insertions(+), 16 deletions(-)
diff --git a/src/mlpack/methods/amf/termination_policies/incomplete_incremental_termination.hpp b/src/mlpack/methods/amf/termination_policies/incomplete_incremental_termination.hpp
index 91424db..cfa499e 100644
--- a/src/mlpack/methods/amf/termination_policies/incomplete_incremental_termination.hpp
+++ b/src/mlpack/methods/amf/termination_policies/incomplete_incremental_termination.hpp
@@ -45,7 +45,11 @@ class IncompleteIncrementalTermination
{
return iteration;
}
-
+ const size_t& MaxIterations()
+ {
+ return t_policy.MaxIterations();
+ }
+
private:
TerminationPolicy t_policy;
diff --git a/src/mlpack/methods/amf/termination_policies/simple_residue_termination.hpp b/src/mlpack/methods/amf/termination_policies/simple_residue_termination.hpp
index cbae4ba..b5c4fb5 100644
--- a/src/mlpack/methods/amf/termination_policies/simple_residue_termination.hpp
+++ b/src/mlpack/methods/amf/termination_policies/simple_residue_termination.hpp
@@ -59,6 +59,7 @@ class SimpleResidueTermination
const double& Index() { return residue; }
const size_t& Iteration() { return iteration; }
+ const size_t& MaxIterations() { return maxIterations; }
public:
double minResidue;
diff --git a/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp b/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp
index 8518b54..dfc78bd 100644
--- a/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp
+++ b/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp
@@ -100,6 +100,7 @@ class SimpleToleranceTermination
const double& Index() { return residue; }
const size_t& Iteration() { return iteration; }
+ const size_t& MaxIterations() { return maxIterations; }
private:
double tolerance;
diff --git a/src/mlpack/methods/amf/termination_policies/validation_RMSE_termination.hpp b/src/mlpack/methods/amf/termination_policies/validation_RMSE_termination.hpp
index ceb7b0c..7f03954 100644
--- a/src/mlpack/methods/amf/termination_policies/validation_RMSE_termination.hpp
+++ b/src/mlpack/methods/amf/termination_policies/validation_RMSE_termination.hpp
@@ -117,15 +117,11 @@ class ValidationRMSETermination
iteration++;
}
- const double& Index()
- {
- return rmse;
- }
+ const double& Index() { return rmse; }
- const size_t& Iteration()
- {
- return iteration;
- }
+ const size_t& Iteration() { return iteration; }
+
+ const size_t& MaxIterations() { return maxIterations; }
private:
double tolerance;
diff --git a/src/mlpack/methods/amf/update_rules/svd_incremental_learning.hpp b/src/mlpack/methods/amf/update_rules/svd_incremental_learning.hpp
index d1ec14d..a0388c1 100644
--- a/src/mlpack/methods/amf/update_rules/svd_incremental_learning.hpp
+++ b/src/mlpack/methods/amf/update_rules/svd_incremental_learning.hpp
@@ -19,6 +19,8 @@ class SVDIncrementalLearning
template<typename MatType>
void Initialize(const MatType& dataset, const size_t rank)
{
+ (void)rank;
+
n = dataset.n_rows;
m = dataset.n_cols;
diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt
index 5a8794c..897520b 100644
--- a/src/mlpack/tests/CMakeLists.txt
+++ b/src/mlpack/tests/CMakeLists.txt
@@ -51,6 +51,7 @@ add_executable(mlpack_test
tree_traits_test.cpp
union_find_test.cpp
svd_batch_test.cpp
+ svd_incremental_test.cpp
)
# Link dependencies of test executable.
target_link_libraries(mlpack_test
diff --git a/src/mlpack/tests/svd_batch_test.cpp b/src/mlpack/tests/svd_batch_test.cpp
index af14247..820e6f6 100644
--- a/src/mlpack/tests/svd_batch_test.cpp
+++ b/src/mlpack/tests/svd_batch_test.cpp
@@ -16,9 +16,27 @@ using namespace mlpack::amf;
using namespace arma;
/**
+ * Make sure the SVD Batch lerning is converging.
+ */
+BOOST_AUTO_TEST_CASE(SVDBatchConvergenceElementTest)
+{
+ mlpack::math::RandomSeed(10);
+ sp_mat data;
+ data.sprandn(1000, 1000, 0.2);
+ AMF<SimpleToleranceTermination<sp_mat>,
+ RandomInitialization,
+ SVDBatchLearning> amf;
+ mat m1,m2;
+ amf.Apply(data, 2, m1, m2);
+
+ BOOST_REQUIRE_NE(amf.TerminationPolicy().Iteration(),
+ amf.TerminationPolicy().MaxIterations());
+}
+
+/**
* Make sure the momentum is working okay.
*/
-BOOST_AUTO_TEST_CASE(SVDMomentumTest)
+BOOST_AUTO_TEST_CASE(SVDBatchMomentumTest)
{
mat dataset;
data::Load("GroupLens100k.csv", dataset);
@@ -51,7 +69,7 @@ BOOST_AUTO_TEST_CASE(SVDMomentumTest)
SVDBatchLearning(0.0009, 0, 0, 0));
mat m1,m2;
- size_t RMSE_1 = amf_1.Apply(cleanedData, 2, m1, m2);
+ double RMSE_1 = amf_1.Apply(cleanedData, 2, m1, m2);
size_t iter_1 = amf_1.TerminationPolicy().Iteration();
mlpack::math::RandomSeed(10);
@@ -61,7 +79,7 @@ BOOST_AUTO_TEST_CASE(SVDMomentumTest)
RandomInitialization(),
SVDBatchLearning(0.0009, 0, 0, 0.8));
- size_t RMSE_2 = amf_2.Apply(cleanedData, 2, m1, m2);
+ double RMSE_2 = amf_2.Apply(cleanedData, 2, m1, m2);
size_t iter_2 = amf_2.TerminationPolicy().Iteration();
BOOST_REQUIRE_LE(RMSE_2, RMSE_1);
@@ -71,7 +89,7 @@ BOOST_AUTO_TEST_CASE(SVDMomentumTest)
/**
* Make sure the regularization is working okay.
*/
-BOOST_AUTO_TEST_CASE(SVDRegularizationTest)
+BOOST_AUTO_TEST_CASE(SVDBatchRegularizationTest)
{
mat dataset;
data::Load("GroupLens100k.csv", dataset);
@@ -104,7 +122,7 @@ BOOST_AUTO_TEST_CASE(SVDRegularizationTest)
SVDBatchLearning(0.0009, 0, 0, 0));
mat m1,m2;
- size_t RMSE_1 = amf_1.Apply(cleanedData, 2, m1, m2);
+ double RMSE_1 = amf_1.Apply(cleanedData, 2, m1, m2);
mlpack::math::RandomSeed(10);
AMF<ValidationRMSETermination<sp_mat>,
@@ -113,7 +131,7 @@ BOOST_AUTO_TEST_CASE(SVDRegularizationTest)
RandomInitialization(),
SVDBatchLearning(0.0009, 0.5, 0.5, 0.8));
- size_t RMSE_2 = amf_2.Apply(cleanedData, 2, m1, m2);
+ double RMSE_2 = amf_2.Apply(cleanedData, 2, m1, m2);
BOOST_REQUIRE_LE(RMSE_2, RMSE_1);
}
@@ -121,7 +139,7 @@ BOOST_AUTO_TEST_CASE(SVDRegularizationTest)
/**
* Make sure the SVD can factorize matrices with negative entries.
*/
-BOOST_AUTO_TEST_CASE(SVDNegativeElementTest)
+BOOST_AUTO_TEST_CASE(SVDBatchNegativeElementTest)
{
mat test;
test.zeros(3,3);
diff --git a/src/mlpack/tests/svd_incremental_test.cpp b/src/mlpack/tests/svd_incremental_test.cpp
new file mode 100644
index 0000000..00b55d3
--- /dev/null
+++ b/src/mlpack/tests/svd_incremental_test.cpp
@@ -0,0 +1,91 @@
+#include <mlpack/core.hpp>
+#include <mlpack/methods/amf/amf.hpp>
+#include <mlpack/methods/amf/update_rules/svd_incremental_learning.hpp>
+#include <mlpack/methods/amf/init_rules/random_init.hpp>
+#include <mlpack/methods/amf/termination_policies/incomplete_incremental_termination.hpp>
+#include <mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp>
+
+#include <boost/test/unit_test.hpp>
+#include "old_boost_test_definitions.hpp"
+
+BOOST_AUTO_TEST_SUITE(SVDIncrementalTest);
+
+using namespace std;
+using namespace mlpack;
+using namespace mlpack::amf;
+using namespace arma;
+
+/**
+ * Test for convergence
+ */
+BOOST_AUTO_TEST_CASE(SVDIncrementalConvergenceTest)
+{
+ mlpack::math::RandomSeed(10);
+ sp_mat data;
+ data.sprandn(1000, 1000, 0.2);
+ SVDIncrementalLearning svd(0.01);
+ IncompleteIncrementalTermination<SimpleToleranceTermination<sp_mat> > iit;
+ AMF<IncompleteIncrementalTermination<SimpleToleranceTermination<sp_mat> >,
+ RandomInitialization,
+ SVDIncrementalLearning> amf(iit, RandomInitialization(), svd);
+ mat m1,m2;
+ amf.Apply(data, 2, m1, m2);
+
+ BOOST_REQUIRE_NE(amf.TerminationPolicy().Iteration(),
+ amf.TerminationPolicy().MaxIterations());
+}
+
+/*
+BOOST_AUTO_TEST_CASE(SVDIncrementalRegularizationTest)
+{
+ mat dataset;
+ data::Load("GroupLens100k.csv", dataset);
+
+ // Generate list of locations for batch insert constructor for sparse
+ // matrices.
+ arma::umat locations(2, dataset.n_cols);
+ arma::vec values(dataset.n_cols);
+ for (size_t i = 0; i < dataset.n_cols; ++i)
+ {
+ // We have to transpose it because items are rows, and users are columns.
+ locations(0, i) = ((arma::uword) dataset(0, i));
+ locations(1, i) = ((arma::uword) dataset(1, i));
+ values(i) = dataset(2, i);
+ }
+
+ // Find maximum user and item IDs.
+ const size_t maxUserID = (size_t) max(locations.row(0)) + 1;
+ const size_t maxItemID = (size_t) max(locations.row(1)) + 1;
+
+ // Fill sparse matrix.
+ sp_mat cleanedData = arma::sp_mat(locations, values, maxUserID, maxItemID);
+ sp_mat cleanedData2 = cleanedData;
+
+ mlpack::math::RandomSeed(10);
+ ValidationRMSETermination<sp_mat> vrt(cleanedData, 2000);
+ AMF<IncompleteIncrementalTermination<ValidationRMSETermination<sp_mat> >,
+ RandomInitialization,
+ SVDIncrementalLearning> amf_1(vrt,
+ RandomInitialization(),
+ SVDIncrementalLearning(0.001, 0, 0));
+
+ mat m1,m2;
+ double RMSE_1 = amf_1.Apply(cleanedData, 2, m1, m2);
+
+ mlpack::math::RandomSeed(10);
+ ValidationRMSETermination<sp_mat> vrt2(cleanedData2, 2000);
+ AMF<IncompleteIncrementalTermination<ValidationRMSETermination<sp_mat> >,
+ RandomInitialization,
+ SVDIncrementalLearning> amf_2(vrt2,
+ RandomInitialization(),
+ SVDIncrementalLearning(0.001, 1e-5, 2e-5));
+
+ mat m3, m4;
+ double RMSE_2 = amf_2.Apply(cleanedData2, 2, m3, m4);
+
+ // RMSE_2 should be less than RMSE_1
+ std::cout << RMSE_1 << " " << RMSE_2 << std::endl;
+}
+*/
+
+BOOST_AUTO_TEST_SUITE_END();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git
More information about the debian-science-commits
mailing list