@@ -95,17 +95,15 @@ m_lmCG = function(Matrix[Double] X, Matrix[Double] y, Integer icpt = 0,
95
95
lambda = scale_lambda * regularization
96
96
beta_unscaled = matrix(0, rows = m_ext, cols = 1)
97
97
98
- if(( max_iteration == 0) | (max_iteration > m_ext) ){
98
+ if(max_iteration == 0){
99
99
max_iteration = m_ext
100
100
}
101
101
i = 0
102
102
103
103
# BEGIN THE CONJUGATE GRADIENT ALGORITHM
104
104
if(verbose) print("Running the CG algorithm...")
105
105
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
109
107
110
108
if(intercept_status == 2){
111
109
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,
118
116
if(verbose){
119
117
print("||r|| initial value = " + sqrt(norm_r2_initial) +
120
118
", target value = " + sqrt(norm_r2_target))
121
- print("Max Iteraton: " + max_iteration)
122
119
}
123
120
124
-
125
121
while(i < max_iteration & norm_r2 > norm_r2_target){
126
122
if(intercept_status == 2){
127
123
ssX_p = scale_X * p
@@ -132,15 +128,10 @@ m_lmCG = function(Matrix[Double] X, Matrix[Double] y, Integer icpt = 0,
132
128
133
129
q = t(X) %*% (X %*% ssX_p)
134
130
135
-
136
-
137
-
138
131
if(intercept_status == 2) {
139
132
q = scale_X * q + shift_X %*% q [m_ext, ]
140
133
}
141
134
142
- qi = q;
143
-
144
135
q += lambda * p
145
136
a = norm_r2 / sum(p * q)
146
137
beta_unscaled += a * p
@@ -151,8 +142,7 @@ m_lmCG = function(Matrix[Double] X, Matrix[Double] y, Integer icpt = 0,
151
142
i = i + 1
152
143
if(verbose){
153
144
print("Iteration " + i + ": ||r|| / ||r init|| = "
154
- + sqrt(norm_r2 / norm_r2_initial)
155
- + " : " + sum(qi))
145
+ + sqrt(norm_r2 / norm_r2_initial))
156
146
}
157
147
}
158
148
0 commit comments