You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by de...@apache.org on 2017/04/07 00:08:28 UTC

incubator-systemml git commit: [SYSTEMML-1382] Remove warnings from ALS-CG.dml execution

Repository: incubator-systemml
Updated Branches:
  refs/heads/master 174bf7db2 -> 5744e752d


[SYSTEMML-1382] Remove warnings from ALS-CG.dml execution

Remove initialization warnings for loss_init, col_nonzeros, and row_nonzeros.
Remove redundant comments.
Update input parameter docs to reflect actual default value of check param.

Closes #423.


Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/5744e752
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/5744e752
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/5744e752

Branch: refs/heads/master
Commit: 5744e752dedc7e4fe3de286c8c91afd608a6e1c1
Parents: 174bf7d
Author: Deron Eriksson <de...@us.ibm.com>
Authored: Thu Apr 6 16:51:57 2017 -0700
Committer: Deron Eriksson <de...@us.ibm.com>
Committed: Thu Apr 6 16:51:57 2017 -0700

----------------------------------------------------------------------
 scripts/algorithms/ALS-CG.dml | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/5744e752/scripts/algorithms/ALS-CG.dml
----------------------------------------------------------------------
diff --git a/scripts/algorithms/ALS-CG.dml b/scripts/algorithms/ALS-CG.dml
index e5c85fc..eb37510 100644
--- a/scripts/algorithms/ALS-CG.dml
+++ b/scripts/algorithms/ALS-CG.dml
@@ -20,9 +20,9 @@
 #-------------------------------------------------------------
 
 #  
-# THIS SCRIPT COMPUTES AN APPROXIMATE FACTORIZATIONOF A LOW-RANK MATRIX X INTO TWO MATRICES U AND V 
-# USING ALTERNATING-LEAST-SQUARES (ALS) ALGORITHM WITH CONJUGATE GRADIENT 
-# MATRICES U AND V ARE COMPUTED BY MINIMIZING A LOSS FUNCTION (WITH REGULARIZATION)
+# THIS SCRIPT COMPUTES AN APPROXIMATE FACTORIZATION OF A LOW-RANK MATRIX X INTO TWO MATRICES U AND V
+# USING THE ALTERNATING-LEAST-SQUARES (ALS) ALGORITHM WITH CONJUGATE GRADIENT.
+# MATRICES U AND V ARE COMPUTED BY MINIMIZING A LOSS FUNCTION (WITH REGULARIZATION).
 #
 # INPUT   PARAMETERS:
 # ---------------------------------------------------------------------------------------------
@@ -37,7 +37,7 @@
 #                           "wL2" = weighted L2 regularization
 # lambda  Double   0.000001 Regularization parameter, no regularization if 0.0
 # maxi    Int      50       Maximum number of iterations
-# check   Boolean  FALSE    Check for convergence after every iteration, i.e., updating U and V once
+# check   Boolean  TRUE     Check for convergence after every iteration, i.e., updating U and V once
 # thr     Double   0.0001   Assuming check is set to TRUE, the algorithm stops and convergence is declared 
 #                           if the decrease in loss in any two consecutive iterations falls below this threshold; 
 #                           if check is FALSE thr is ignored
@@ -55,13 +55,13 @@ fileU      = $U;
 fileV      = $V;
 
 # Default values of some parameters
-r          = ifdef ($rank, 10);         # $rank=10;
-reg	       = ifdef ($reg, "L2")         # $reg="L2";
-lambda	   = ifdef ($lambda, 0.000001); # $lambda=0.000001;
-max_iter   = ifdef ($maxi, 50);         # $maxi=50;
-check      = ifdef ($check, TRUE);	    # $check=FALSE;
-thr        = ifdef ($thr, 0.0001);      # $thr=0.0001;
-fmtO       = ifdef ($fmt, "text");      # $fmt="text";
+r          = ifdef($rank, 10);
+reg        = ifdef($reg, "L2");
+lambda     = ifdef($lambda, 0.000001);
+max_iter   = ifdef($maxi, 50);
+check      = ifdef($check, TRUE);
+thr        = ifdef($thr, 0.0001);
+fmtO       = ifdef($fmt, "text");
  
  
 ###### MAIN PART ######
@@ -76,6 +76,8 @@ V = rand (rows = n, cols = r, min = -0.5, max = 0.5); # nxr
 W = (X != 0);
   
 # check for regularization
+row_nonzeros = matrix(0,rows=1,cols=1);
+col_nonzeros = matrix(0,rows=1,cols=1);
 if( reg == "L2" ) {
   print ("BEGIN ALS-CG SCRIPT WITH NONZERO SQUARED LOSS + L2 WITH LAMBDA - " + lambda);
   row_nonzeros = matrix(1, nrow(W), 1);
@@ -100,6 +102,7 @@ else {
 is_U = TRUE;  # TRUE = Optimize U, FALSE = Optimize V
 maxinneriter = r ; # min (ncol (U), 15);
 
+loss_init = 0.0; # only used if check is TRUE
 if( check ) {
   loss_init = 0.5 * sum( (X != 0) * (U %*% t(V) - X) ^ 2);
   loss_init = loss_init + 0.5 * lambda * (sum (U ^ 2 * row_nonzeros) + sum (V ^ 2 * col_nonzeros));