Skip to content

Commit 5006475

Browse files
committed
revert builtin
1 parent 5e7ce76 commit 5006475

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

scripts/builtin/l2svm.dml

+2-5
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ m_l2svm = function(Matrix[Double] X, Matrix[Double] Y, Boolean intercept = FALSE
8888
w = matrix(0, rows=ncol(X), cols=1)
8989
Xw = matrix(0, rows=nrow(X), cols=1)
9090

91-
## rewrite t(X) %*% Y
92-
g_old = t(t(Y) %*% X)
91+
g_old = t(X) %*% Y
9392
s = g_old
9493

9594
iter = 0
@@ -122,9 +121,7 @@ m_l2svm = function(Matrix[Double] X, Matrix[Double] Y, Boolean intercept = FALSE
122121
sv = (out > 0)
123122
out = sv * out
124123
obj = 0.5 * sum(out * out) + reg/2 * sum(w * w)
125-
## rewrite t(X) %*% (out * Y) - reg * w
126-
g_new = t(t(out*Y) %*% X) - reg * w
127-
# g_new = t(X) %*% (out * Y) - reg * w
124+
g_new = t(X) %*% (out * Y) - reg * w
128125

129126
if(verbose) {
130127
colstr = ifelse(columnId!=-1, "-- MSVM class="+columnId+": ", "")

scripts/builtin/lmCG.dml

+3-13
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,15 @@ m_lmCG = function(Matrix[Double] X, Matrix[Double] y, Integer icpt = 0,
9595
lambda = scale_lambda * regularization
9696
beta_unscaled = matrix(0, rows = m_ext, cols = 1)
9797

98-
if((max_iteration == 0) | (max_iteration > m_ext)){
98+
if(max_iteration == 0){
9999
max_iteration = m_ext
100100
}
101101
i = 0
102102

103103
# BEGIN THE CONJUGATE GRADIENT ALGORITHM
104104
if(verbose) print("Running the CG algorithm...")
105105

106-
# Equivalent to - t(X) %*% y, we have a rewrite to detect it
107-
# But CLA does not do it correctly... TODO to fix that rewrite.
108-
r = - t(t(y) %*% X)
106+
r = - t(X) %*% y
109107

110108
if(intercept_status == 2){
111109
r = scale_X * r + shift_X %*% r [m_ext, ]
@@ -118,10 +116,8 @@ m_lmCG = function(Matrix[Double] X, Matrix[Double] y, Integer icpt = 0,
118116
if(verbose){
119117
print("||r|| initial value = " + sqrt(norm_r2_initial) +
120118
", target value = " + sqrt(norm_r2_target))
121-
print("Max Iteraton: " + max_iteration)
122119
}
123120

124-
125121
while(i < max_iteration & norm_r2 > norm_r2_target){
126122
if(intercept_status == 2){
127123
ssX_p = scale_X * p
@@ -132,15 +128,10 @@ m_lmCG = function(Matrix[Double] X, Matrix[Double] y, Integer icpt = 0,
132128

133129
q = t(X) %*% (X %*% ssX_p)
134130

135-
136-
137-
138131
if(intercept_status == 2) {
139132
q = scale_X * q + shift_X %*% q [m_ext, ]
140133
}
141134

142-
qi = q;
143-
144135
q += lambda * p
145136
a = norm_r2 / sum(p * q)
146137
beta_unscaled += a * p
@@ -151,8 +142,7 @@ m_lmCG = function(Matrix[Double] X, Matrix[Double] y, Integer icpt = 0,
151142
i = i + 1
152143
if(verbose){
153144
print("Iteration " + i + ": ||r|| / ||r init|| = "
154-
+ sqrt(norm_r2 / norm_r2_initial)
155-
+ " : " + sum(qi))
145+
+ sqrt(norm_r2 / norm_r2_initial))
156146
}
157147
}
158148

0 commit comments

Comments
 (0)