@@ -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