You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by mb...@apache.org on 2016/01/05 17:04:17 UTC

[3/3] incubator-systemml git commit: Improved lasso script (sign computation, cleanup indentation)

Improved lasso script (sign computation, cleanup indentation)

Incl cleanup test suite packages (missing tests, ordering)

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

Branch: refs/heads/master
Commit: 86583584fccf09da320c54cf3cdacd9134bc3465
Parents: e80f94b
Author: Matthias Boehm <mb...@us.ibm.com>
Authored: Tue Jan 5 00:07:17 2016 -0800
Committer: Matthias Boehm <mb...@us.ibm.com>
Committed: Tue Jan 5 00:07:17 2016 -0800

----------------------------------------------------------------------
 scripts/staging/regression/lasso/lasso.dml      | 38 ++++++++++----------
 .../functions/unary/matrix/ZPackageSuite.java   | 20 +++++------
 2 files changed, 29 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/86583584/scripts/staging/regression/lasso/lasso.dml
----------------------------------------------------------------------
diff --git a/scripts/staging/regression/lasso/lasso.dml b/scripts/staging/regression/lasso/lasso.dml
index 16761f3..fb520df 100644
--- a/scripts/staging/regression/lasso/lasso.dml
+++ b/scripts/staging/regression/lasso/lasso.dml
@@ -23,6 +23,8 @@
 
 X = read($X)
 y = read($Y)
+n = nrow(X)
+m = ncol(X)
 
 #params
 tol = 10^(-15)
@@ -30,9 +32,6 @@ M = 5
 tau = 1
 maxiter = 1000
 
-n = nrow(X)
-m = ncol(X)
-
 #constants
 eta = 2
 sigma = 0.01
@@ -55,7 +54,7 @@ history[M,1] = obj
 inactive_set = matrix(1, rows=m, cols=1)
 iter = 0
 continue = TRUE
-while(iter < maxiter & continue){
+while(iter < maxiter & continue) {
 	dw = matrix(0, rows=m, cols=1)
 	dg = matrix(0, rows=m, cols=1)
 	relChangeObj = -1.0
@@ -63,22 +62,20 @@ while(iter < maxiter & continue){
 	inner_iter = 0
 	inner_continue = TRUE
 	inner_maxiter = 100
-	while(inner_iter < inner_maxiter & inner_continue){
+	while(inner_iter < inner_maxiter & inner_continue) {
 		u = w - g/alpha
 		lambda = tau/alpha
 		
-		signum_u = ppred(u, 0, ">") - ppred(u, 0, "<")
-		wnew = signum_u * (abs(u) - lambda) * ppred(abs(u) - lambda, 0, ">")
-	
+		wnew = sign(u) * (abs(u) - lambda) * ppred(abs(u) - lambda, 0, ">")
 		dw = wnew - w
 		dw2 = sum(dw*dw)
 		
 		r = X %*% wnew - y
 		gnew = t(X) %*% r
-		objnew = 0.5 * sum(r*r) + tau*sum(abs(wnew))
-		
+		objnew = 0.5 * sum(r*r) + tau*sum(abs(wnew))		
 		obj_threshold = max(history) - 0.5*sigma*alpha*dw2
-		if(objnew <= obj_threshold){
+		
+		if(objnew <= obj_threshold) {
 			w = wnew
 			dg = gnew - g
 			g = gnew
@@ -88,25 +85,28 @@ while(iter < maxiter & continue){
 			history[M,1] = objnew
 			relChangeObj = abs(objnew - obj)/obj
 			obj = objnew
-		}else alpha = eta*alpha
+		}
+		else 
+			alpha = eta*alpha
 	
 		inner_iter = inner_iter + 1
 	}
 	
-	if(inner_continue) print("Inner loop did not converge")
+	if(inner_continue) 
+		print("Inner loop did not converge")
 	
 	alphanew = sum(dw*dg)/sum(dw*dw)
 	alpha = max(alpha_min, min(alpha_max, alphanew))
 	
 	old_inactive_set = inactive_set
-    inactive_set = ppred(w, 0, "!=")
-    diff = sum(abs(old_inactive_set - inactive_set))
-
-    if(diff == 0 & relChangeObj < tol) continue = FALSE
+	inactive_set = ppred(w, 0, "!=")
+	diff = sum(abs(old_inactive_set - inactive_set))
 
-    num_inactive = sum(ppred(w, 0, "!="))
-    print("ITER=" + iter + " OBJ=" + obj + " relative change=" + relChangeObj + " num_inactive=" + num_inactive)
+	if(diff == 0 & relChangeObj < tol) 
+		continue = FALSE
 
+	num_inactive = sum(ppred(w, 0, "!="))
+	print("ITER=" + iter + " OBJ=" + obj + " relative change=" + relChangeObj + " num_inactive=" + num_inactive)
 	iter = iter + 1
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/86583584/src/test_suites/java/org/apache/sysml/test/integration/functions/unary/matrix/ZPackageSuite.java
----------------------------------------------------------------------
diff --git a/src/test_suites/java/org/apache/sysml/test/integration/functions/unary/matrix/ZPackageSuite.java b/src/test_suites/java/org/apache/sysml/test/integration/functions/unary/matrix/ZPackageSuite.java
index 137eba3..dac067d 100644
--- a/src/test_suites/java/org/apache/sysml/test/integration/functions/unary/matrix/ZPackageSuite.java
+++ b/src/test_suites/java/org/apache/sysml/test/integration/functions/unary/matrix/ZPackageSuite.java
@@ -33,28 +33,28 @@ import org.junit.runners.Suite;
 	CastAsScalarTest.class,
 	CosTest.class,
 	DiagTest.class,
+	EigenFactorizeTest.class,
+	FullCummaxTest.class,
+	FullCumminTest.class,
+	FullCumprodTest.class,
+	FullCumsumTest.class,
+	FullSelectPosTest.class,
+	FullSignTest.class,
 	IQMTest.class,
+	LUFactorizeTest.class,
 	MatrixInverseTest.class,
 	MinusTest.class,
+	MLUnaryBuiltinTest.class,
 	NegationTest.class,
 	PrintTest.class,
 	QRSolverTest.class,
+	RemoveEmptyTest.class,
 	ReplaceTest.class,
 	RoundTest.class,
 	SinTest.class,
 	SqrtTest.class,
 	TanTest.class,
 	TransposeTest.class,
-	
-	EigenFactorizeTest.class,
-	FullCumminTest.class,
-	FullCummaxTest.class,
-	FullCumprodTest.class,
-	FullCumsumTest.class,
-	FullSelectPosTest.class,
-	LUFactorizeTest.class,
-	RemoveEmptyTest.class,
-	MLUnaryBuiltinTest.class
 })