[mlpack-svn] r16825 - in mlpack/trunk/src/mlpack: methods/amf methods/amf/termination_policies methods/amf/update_rules tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Jul 16 07:14:27 EDT 2014
Author: sumedhghaisas
Date: Wed Jul 16 07:14:27 2014
New Revision: 16825
Log:
* added svd incomplete incremental learning tests
* combined functions IsConverged and Step of termination policies into IsConverged
Modified:
mlpack/trunk/src/mlpack/methods/amf/amf_impl.hpp
mlpack/trunk/src/mlpack/methods/amf/termination_policies/incomplete_incremental_termination.hpp
mlpack/trunk/src/mlpack/methods/amf/termination_policies/simple_residue_termination.hpp
mlpack/trunk/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp
mlpack/trunk/src/mlpack/methods/amf/termination_policies/validation_RMSE_termination.hpp
mlpack/trunk/src/mlpack/methods/amf/update_rules/svd_incremental_learning.hpp
mlpack/trunk/src/mlpack/tests/svd_incremental_test.cpp
Modified: mlpack/trunk/src/mlpack/methods/amf/amf_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/amf/amf_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/amf/amf_impl.hpp Wed Jul 16 07:14:27 2014
@@ -55,11 +55,9 @@
// Update the values of W and H based on the update rules provided.
update.WUpdate(V, W, H);
update.HUpdate(V, W, H);
-
- terminationPolicy.Step(W, H);
}
- const double residue = sqrt(terminationPolicy.Index());
+ const double residue = terminationPolicy.Index();
const size_t iteration = terminationPolicy.Iteration();
Log::Info << "AMF converged to residue of " << residue << " in "
Modified: mlpack/trunk/src/mlpack/methods/amf/termination_policies/incomplete_incremental_termination.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/amf/termination_policies/incomplete_incremental_termination.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/amf/termination_policies/incomplete_incremental_termination.hpp Wed Jul 16 07:14:27 2014
@@ -28,13 +28,10 @@
bool IsConverged(arma::mat& W, arma::mat& H)
{
- return t_policy.IsConverged(W, H);
- }
-
- void Step(const arma::mat& W, const arma::mat& H)
- {
- if(iteration % incrementalIndex == 0) t_policy.Step(W, H);
iteration++;
+ if(iteration % incrementalIndex == 0)
+ return t_policy.IsConverged(W, H);
+ else return false;
}
const double& Index()
Modified: mlpack/trunk/src/mlpack/methods/amf/termination_policies/simple_residue_termination.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/amf/termination_policies/simple_residue_termination.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/amf/termination_policies/simple_residue_termination.hpp Wed Jul 16 07:14:27 2014
@@ -32,14 +32,6 @@
bool IsConverged(arma::mat& W, arma::mat& H)
{
- (void)W;
- (void)H;
- if(residue < minResidue || iteration > maxIterations) return true;
- else return false;
- }
-
- void Step(const arma::mat& W, const arma::mat& H)
- {
// Calculate norm of WH after each iteration.
arma::mat WH;
@@ -55,6 +47,9 @@
normOld = norm;
iteration++;
+
+ if(residue < minResidue || iteration > maxIterations) return true;
+ else return false;
}
const double& Index() { return residue; }
Modified: mlpack/trunk/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp Wed Jul 16 07:14:27 2014
@@ -32,6 +32,35 @@
bool IsConverged(arma::mat& W, arma::mat& H)
{
+ // Calculate norm of WH after each iteration.
+ arma::mat WH;
+
+ WH = W * H;
+
+ residueOld = residue;
+ size_t n = V->n_rows;
+ size_t m = V->n_cols;
+ double sum = 0;
+ size_t count = 0;
+ for(size_t i = 0;i < n;i++)
+ {
+ for(size_t j = 0;j < m;j++)
+ {
+ double temp = 0;
+ if((temp = (*V)(i,j)) != 0)
+ {
+ temp = (temp - WH(i, j));
+ temp = temp * temp;
+ sum += temp;
+ count++;
+ }
+ }
+ }
+ residue = sum / count;
+ residue = sqrt(residue);
+
+ iteration++;
+
if((residueOld - residue) / residueOld < tolerance && iteration > 4)
{
if(reverseStepCount == 0 && isCopy == false)
@@ -66,38 +95,6 @@
else return false;
}
- void Step(const arma::mat& W, const arma::mat& H)
- {
- // Calculate norm of WH after each iteration.
- arma::mat WH;
-
- WH = W * H;
-
- residueOld = residue;
- size_t n = V->n_rows;
- size_t m = V->n_cols;
- double sum = 0;
- size_t count = 0;
- for(size_t i = 0;i < n;i++)
- {
- for(size_t j = 0;j < m;j++)
- {
- double temp = 0;
- if((temp = (*V)(i,j)) != 0)
- {
- temp = (temp - WH(i, j));
- temp = temp * temp;
- sum += temp;
- count++;
- }
- }
- }
- residue = sum / count;
- residue = sqrt(residue);
-
- iteration++;
- }
-
const double& Index() { return residue; }
const size_t& Iteration() { return iteration; }
const size_t& MaxIterations() { return maxIterations; }
Modified: mlpack/trunk/src/mlpack/methods/amf/termination_policies/validation_RMSE_termination.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/amf/termination_policies/validation_RMSE_termination.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/amf/termination_policies/validation_RMSE_termination.hpp Wed Jul 16 07:14:27 2014
@@ -56,6 +56,30 @@
bool IsConverged(arma::mat& W, arma::mat& H)
{
+ // Calculate norm of WH after each iteration.
+ arma::mat WH;
+
+ WH = W * H;
+
+ if (iteration != 0)
+ {
+ rmseOld = rmse;
+ rmse = 0;
+ for(size_t i = 0; i < num_test_points; i++)
+ {
+ size_t t_row = test_points(i, 0);
+ size_t t_col = test_points(i, 1);
+ double t_val = test_points(i, 2);
+ double temp = (t_val - WH(t_row, t_col));
+ temp *= temp;
+ rmse += temp;
+ }
+ rmse /= num_test_points;
+ rmse = sqrt(rmse);
+ }
+
+ iteration++;
+
if((rmseOld - rmse) / rmseOld < tolerance && iteration > 4)
{
if(reverseStepCount == 0 && isCopy == false)
@@ -89,34 +113,7 @@
}
else return false;
}
-
- void Step(const arma::mat& W, const arma::mat& H)
- {
- // Calculate norm of WH after each iteration.
- arma::mat WH;
-
- WH = W * H;
-
- if (iteration != 0)
- {
- rmseOld = rmse;
- rmse = 0;
- for(size_t i = 0; i < num_test_points; i++)
- {
- size_t t_row = test_points(i, 0);
- size_t t_col = test_points(i, 1);
- double t_val = test_points(i, 2);
- double temp = (t_val - WH(t_row, t_col));
- temp *= temp;
- rmse += temp;
- }
- rmse /= num_test_points;
- rmse = sqrt(rmse);
- }
-
- iteration++;
- }
-
+
const double& Index() { return rmse; }
const size_t& Iteration() { return iteration; }
Modified: mlpack/trunk/src/mlpack/methods/amf/update_rules/svd_incremental_learning.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/amf/update_rules/svd_incremental_learning.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/amf/update_rules/svd_incremental_learning.hpp Wed Jul 16 07:14:27 2014
@@ -49,7 +49,7 @@
if((val = V(i, currentUserIndex)) != 0)
deltaW.row(i) += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
arma::trans(H.col(currentUserIndex));
- if(kw != 0) deltaW -= kw * W.row(i);
+ if(kw != 0) deltaW.row(i) -= kw * W.row(i);
}
W += u*deltaW;
@@ -112,7 +112,7 @@
size_t i = it.row();
deltaW.row(i) += (val - arma::dot(W.row(i), H.col(currentUserIndex))) *
arma::trans(H.col(currentUserIndex));
- if(kw != 0) deltaW -= kw * W.row(i);
+ if(kw != 0) deltaW.row(i) -= kw * W.row(i);
}
W += u*deltaW;
Modified: mlpack/trunk/src/mlpack/tests/svd_incremental_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/svd_incremental_test.cpp (original)
+++ mlpack/trunk/src/mlpack/tests/svd_incremental_test.cpp Wed Jul 16 07:14:27 2014
@@ -4,6 +4,7 @@
#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 <mlpack/methods/amf/termination_policies/validation_RMSE_termination.hpp>
#include <boost/test/unit_test.hpp>
#include "old_boost_test_definitions.hpp"
@@ -35,7 +36,7 @@
amf.TerminationPolicy().MaxIterations());
}
-/*
+
BOOST_AUTO_TEST_CASE(SVDIncrementalRegularizationTest)
{
mat dataset;
@@ -78,14 +79,12 @@
RandomInitialization,
SVDIncrementalLearning> amf_2(vrt2,
RandomInitialization(),
- SVDIncrementalLearning(0.001, 1e-5, 2e-5));
+ SVDIncrementalLearning(0.001, 0.01, 0.01));
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_REQUIRE_LT(RMSE_2, RMSE_1);
}
-*/
BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-svn
mailing list