[mlpack-git] master: Provide per-iteration information; avoid W*H. (3d23964)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed May 27 20:15:31 EDT 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/29ab461472f64f72cfbdb93b0d9045024050cc95...3d239640213ec47c6756803bdb50df8e16b94e75
>---------------------------------------------------------------
commit 3d239640213ec47c6756803bdb50df8e16b94e75
Author: ryan <ryan at ratml.org>
Date: Wed May 27 20:15:13 2015 -0400
Provide per-iteration information; avoid W*H.
>---------------------------------------------------------------
3d239640213ec47c6756803bdb50df8e16b94e75
.../amf/termination_policies/simple_residue_termination.hpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
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 7baf92c..8883ff7 100644
--- a/src/mlpack/methods/amf/termination_policies/simple_residue_termination.hpp
+++ b/src/mlpack/methods/amf/termination_policies/simple_residue_termination.hpp
@@ -62,8 +62,11 @@ class SimpleResidueTermination
*/
bool IsConverged(arma::mat& W, arma::mat& H)
{
- // Calculate the norm and compute the residue
- const double norm = arma::norm(W * H, "fro");
+ // Calculate the norm and compute the residue, but do it by hand, so as to
+ // avoid calculating (W*H), which may be very large.
+ double norm = 0.0;
+ for (size_t j = 0; j < H.n_cols; ++j)
+ norm += arma::norm(W * H.col(j), "fro");
residue = fabs(normOld - norm) / normOld;
// Store the norm.
@@ -71,6 +74,7 @@ class SimpleResidueTermination
// Increment iteration count
iteration++;
+ Log::Info << "Iteration " << iteration << "; residue " << residue << ".\n";
// Check if termination criterion is met.
return (residue < minResidue || iteration > maxIterations);
More information about the mlpack-git
mailing list