@@ -6,7 +6,7 @@ fixedLassoInf <- function(x, y, beta,
6
6
lambda , family = c(" gaussian" ," binomial" ," cox" ),
7
7
intercept = TRUE , add.targets = NULL , status = NULL ,
8
8
sigma = NULL , alpha = 0.1 ,
9
- type = c(" partial" ," full" ), tol.beta = 1e-5 , tol.kkt = 0.1 ,
9
+ type = c(" partial" , " full" ), tol.beta = 1e-5 , tol.kkt = 0.1 ,
10
10
gridrange = c(- 100 ,100 ), bits = NULL , verbose = FALSE ,
11
11
linesearch.try = 10 ) {
12
12
@@ -150,7 +150,7 @@ fixedLassoInf <- function(x, y, beta,
150
150
ci = tailarea = matrix (0 ,k ,2 )
151
151
152
152
if (type == " full" & p > n ) {
153
- if (intercept == T ) {
153
+ if (intercept == TRUE ) {
154
154
pp = p + 1
155
155
Xint <- cbind(rep(1 ,n ),x )
156
156
# indices of selected predictors
@@ -189,8 +189,10 @@ fixedLassoInf <- function(x, y, beta,
189
189
}
190
190
191
191
M <- (((htheta %*% t(Xordered ))+ ithetasigma %*% FS %*% hsigmaSinv %*% t(XS ))/ n )
192
+
192
193
# vector which is offset for testing debiased beta's
193
194
null_value <- (((ithetasigma %*% FS %*% hsigmaSinv )%*% sign(hbetaS ))* lambda / n )
195
+
194
196
if (intercept == T ) {
195
197
M = M [- 1 ,] # remove intercept row
196
198
null_value = null_value [- 1 ] # remove intercept element
@@ -238,12 +240,23 @@ fixedLassoInf <- function(x, y, beta,
238
240
tailarea [j ,] = a $ tailarea
239
241
}
240
242
241
- out = list (type = type ,lambda = lambda ,pv = pv ,ci = ci ,
242
- tailarea = tailarea ,vlo = vlo ,vup = vup ,vmat = vmat ,y = y ,
243
- vars = vars ,sign = sign_vars ,sigma = sigma ,alpha = alpha ,
244
- sd = sigma * sqrt(rowSums(vmat ^ 2 )),
245
- coef0 = vmat %*% y ,
246
- call = this.call )
243
+ out = list (type = type ,
244
+ lambda = lambda ,
245
+ pv = pv ,
246
+ ci = ci ,
247
+ tailarea = tailarea ,
248
+ vlo = vlo ,
249
+ vup = vup ,
250
+ vmat = vmat ,
251
+ y = y ,
252
+ vars = vars ,
253
+ sign = sign_vars ,
254
+ sigma = sigma ,
255
+ alpha = alpha ,
256
+ sd = sigma * sqrt(rowSums(vmat ^ 2 )),
257
+ coef0 = vmat %*% y ,
258
+ call = this.call )
259
+
247
260
class(out ) = " fixedLassoInf"
248
261
return (out )
249
262
}
@@ -306,15 +319,19 @@ debiasingMatrix = function(Xinfo, # could be X or t(X) %*% X / n d
306
319
nsample ,
307
320
rows ,
308
321
verbose = FALSE ,
309
- mu = NULL , # starting value of mu
322
+ bound = NULL , # starting value of bound
310
323
linesearch = TRUE , # do a linesearch?
311
324
scaling_factor = 1.5 , # multiplicative factor for linesearch
312
325
max_active = NULL , # how big can active set get?
313
326
max_try = 10 , # how many steps in linesearch?
314
327
warn_kkt = FALSE , # warn if KKT does not seem to be satisfied?
315
- max_iter = 100 , # how many iterations for each optimization problem
328
+ max_iter = 50 , # how many iterations for each optimization problem
329
+ kkt_stop = TRUE , # stop based on KKT conditions?
330
+ parameter_stop = TRUE , # stop based on relative convergence of parameter?
331
+ objective_stop = TRUE , # stop based on relative decrease in objective?
316
332
kkt_tol = 1.e-4 , # tolerance for the KKT conditions
317
- objective_tol = 1.e-8 # tolerance for relative decrease in objective
333
+ parameter_tol = 1.e-4 , # tolerance for relative convergence of parameter
334
+ objective_tol = 1.e-4 # tolerance for relative decrease in objective
318
335
) {
319
336
320
337
@@ -325,8 +342,8 @@ debiasingMatrix = function(Xinfo, # could be X or t(X) %*% X / n d
325
342
p = ncol(Xinfo );
326
343
M = matrix (0 , length(rows ), p );
327
344
328
- if (is.null(mu )) {
329
- mu = (1 / sqrt(nsample )) * qnorm(1 - (0.1 / (p ^ 2 )))
345
+ if (is.null(bound )) {
346
+ bound = (1 / sqrt(nsample )) * qnorm(1 - (0.1 / (p ^ 2 )))
330
347
}
331
348
332
349
xperc = 0 ;
@@ -342,14 +359,18 @@ debiasingMatrix = function(Xinfo, # could be X or t(X) %*% X / n d
342
359
output = debiasingRow(Xinfo , # could be X or t(X) %*% X / n depending on is_wide
343
360
is_wide ,
344
361
row ,
345
- mu ,
362
+ bound ,
346
363
linesearch = linesearch ,
347
364
scaling_factor = scaling_factor ,
348
365
max_active = max_active ,
349
366
max_try = max_try ,
350
367
warn_kkt = FALSE ,
351
368
max_iter = max_iter ,
369
+ kkt_stop = kkt_stop ,
370
+ parameter_stop = parameter_stop ,
371
+ objective_stop = objective_stop ,
352
372
kkt_tol = kkt_tol ,
373
+ parameter_tol = parameter_tol ,
353
374
objective_tol = objective_tol )
354
375
355
376
if (warn_kkt && (! output $ kkt_check )) {
@@ -372,15 +393,19 @@ debiasingMatrix = function(Xinfo, # could be X or t(X) %*% X / n d
372
393
debiasingRow = function (Xinfo , # could be X or t(X) %*% X / n depending on is_wide
373
394
is_wide ,
374
395
row ,
375
- mu ,
396
+ bound ,
376
397
linesearch = TRUE , # do a linesearch?
377
- scaling_factor = 1.2 , # multiplicative factor for linesearch
398
+ scaling_factor = 1.5 , # multiplicative factor for linesearch
378
399
max_active = NULL , # how big can active set get?
379
400
max_try = 10 , # how many steps in linesearch?
380
401
warn_kkt = FALSE , # warn if KKT does not seem to be satisfied?
381
- max_iter = 100 , # how many iterations for each optimization problem
402
+ max_iter = 50 , # how many iterations for each optimization problem
403
+ kkt_stop = TRUE , # stop based on KKT conditions?
404
+ parameter_stop = TRUE , # stop based on relative convergence of parameter?
405
+ objective_stop = TRUE , # stop based on relative decrease in objective?
382
406
kkt_tol = 1.e-4 , # tolerance for the KKT conditions
383
- objective_tol = 1.e-8 # tolerance for relative decrease in objective
407
+ parameter_tol = 1.e-4 , # tolerance for relative convergence of parameter
408
+ objective_tol = 1.e-4 # tolerance for relative decrease in objective
384
409
) {
385
410
386
411
p = ncol(Xinfo )
@@ -389,9 +414,11 @@ debiasingRow = function (Xinfo, # could be X or t(X) %*% X / n dep
389
414
max_active = min(nrow(Xinfo ), ncol(Xinfo ))
390
415
}
391
416
417
+
392
418
# Initialize variables
393
419
394
420
soln = rep(0 , p )
421
+ soln = as.numeric(soln )
395
422
ever_active = rep(0 , p )
396
423
ever_active [1 ] = row # 1-based
397
424
ever_active = as.integer(ever_active )
@@ -407,11 +434,15 @@ debiasingRow = function (Xinfo, # could be X or t(X) %*% X / n dep
407
434
408
435
last_output = NULL
409
436
437
+ if (is_wide ) {
438
+ Xsoln = as.numeric(rep(0 , nrow(Xinfo )))
439
+ }
440
+
410
441
while (counter_idx < max_try ) {
411
442
412
443
if (! is_wide ) {
413
444
result = solve_QP(Xinfo , # this is non-neg-def matrix
414
- mu ,
445
+ bound ,
415
446
max_iter ,
416
447
soln ,
417
448
linear_func ,
@@ -420,11 +451,15 @@ debiasingRow = function (Xinfo, # could be X or t(X) %*% X / n dep
420
451
nactive ,
421
452
kkt_tol ,
422
453
objective_tol ,
423
- max_active )
454
+ parameter_tol ,
455
+ max_active ,
456
+ kkt_stop ,
457
+ objective_stop ,
458
+ parameter_stop )
424
459
} else {
425
- Xsoln = rep( 0 , nrow( Xinfo ))
426
- result = solve_QP_wide( Xinfo , # this is a design matrix
427
- mu ,
460
+ result = solve_QP_wide( Xinfo , # this is a design matrix
461
+ as.numeric(rep( bound , p )), # vector of Lagrange multipliers
462
+ 0 , # ridge_term
428
463
max_iter ,
429
464
soln ,
430
465
linear_func ,
@@ -434,7 +469,11 @@ debiasingRow = function (Xinfo, # could be X or t(X) %*% X / n dep
434
469
nactive ,
435
470
kkt_tol ,
436
471
objective_tol ,
437
- max_active )
472
+ parameter_tol ,
473
+ max_active ,
474
+ kkt_stop ,
475
+ objective_stop ,
476
+ parameter_stop )
438
477
439
478
}
440
479
@@ -458,13 +497,13 @@ debiasingRow = function (Xinfo, # could be X or t(X) %*% X / n dep
458
497
if ((iter < (max_iter + 1 )) && (counter_idx > 1 )) {
459
498
break ; # we've found a feasible point and solved the problem
460
499
}
461
- mu = mu * scaling_factor ;
500
+ bound = bound * scaling_factor ;
462
501
} else { # trying to drop the bound parameter further
463
502
if ((iter == (max_iter + 1 )) && (counter_idx > 1 )) {
464
503
result = last_output ; # problem seems infeasible because we didn't solve it
465
504
break ; # so we revert to previously found solution
466
505
}
467
- mu = mu / scaling_factor ;
506
+ bound = bound / scaling_factor ;
468
507
}
469
508
470
509
# If the active set has grown to a certain size
@@ -490,7 +529,8 @@ debiasingRow = function (Xinfo, # could be X or t(X) %*% X / n dep
490
529
}
491
530
492
531
return (list (soln = result $ soln ,
493
- kkt_check = result $ kkt_check ))
532
+ kkt_check = result $ kkt_check ,
533
+ gradient = result $ gradient ))
494
534
495
535
}
496
536
0 commit comments