@@ -78,11 +78,11 @@ randomizedLasso = function(X,
78
78
nactive ,
79
79
kkt_tol ,
80
80
objective_tol ,
81
- parameter_tol ,
81
+ parameter_tol ,
82
82
p ,
83
- objective_stop , # objective_stop
84
- kkt_stop , # kkt_stop
85
- parameter_stop ) # param_stop
83
+ objective_stop , # objective_stop
84
+ kkt_stop , # kkt_stop
85
+ parameter_stop ) # param_stop
86
86
87
87
sign_soln = sign(result $ soln )
88
88
@@ -100,7 +100,7 @@ randomizedLasso = function(X,
100
100
observed_unpen = result $ soln [unpenalized ]
101
101
observed_subgrad = - n * result $ gradient [inactive ]
102
102
103
- if (sum(abs(observed_subgrad )> lam * (1.001 )) > 0 ){
103
+ if (sum(abs(observed_subgrad )> lam [ inactive ] * (1.001 )) > 0 ){
104
104
stop(" subgradient eq not satisfied" )
105
105
}
106
106
@@ -144,14 +144,17 @@ randomizedLasso = function(X,
144
144
coef_term = coef_term %*% diag(signs_ ) # scaligns are non-negative
145
145
}
146
146
147
- subgrad_term = matrix (0 , p , sum(inactive )) # for subgrad
148
- for (i in 1 : sum(inactive )) {
149
- subgrad_term [inactive_set [i ], i ] = 1
150
- }
151
-
152
- linear_term = cbind(coef_term ,
153
- subgrad_term )
154
-
147
+ if (sum(inactive ) > 0 ) {
148
+ subgrad_term = matrix (0 , p , sum(inactive )) # for subgrad
149
+ for (i in 1 : sum(inactive )) {
150
+ subgrad_term [inactive_set [i ], i ] = 1
151
+ }
152
+
153
+ linear_term = cbind(coef_term ,
154
+ subgrad_term )
155
+ } else {
156
+ linear_term = coef_term
157
+ }
155
158
offset_term = rep(0 , p )
156
159
offset_term [active ] = lam [active ] * sign_soln [active ]
157
160
@@ -167,9 +170,14 @@ randomizedLasso = function(X,
167
170
168
171
active_term = - L_E # for \bar{\beta}_E
169
172
170
- inactive_term = - subgrad_term
171
- linear_term = cbind(active_term ,
172
- inactive_term )
173
+ if (sum(inactive ) > 0 ) {
174
+ inactive_term = - subgrad_term
175
+ linear_term = cbind(active_term ,
176
+ inactive_term )
177
+ } else {
178
+ linear_term = active_term
179
+ }
180
+
173
181
offset_term = rep(0 , p )
174
182
internal_transform = list (linear_term = linear_term ,
175
183
offset_term = offset_term )
0 commit comments