@@ -154,20 +154,24 @@ fixedLassoInf <- function(x, y, beta,
154
154
155
155
# Reorder so that active set S is first
156
156
Xordered = Xint [,c(S ,notS ,recursive = T )]
157
+ hsigmaS = 1 / n * (t(XS )%*% XS ) # hsigma[S,S]
158
+ hsigmaSinv = solve(hsigmaS ) # pinv(hsigmaS)
157
159
158
- hsigma <- 1 / n * (t(Xordered )%*% Xordered )
159
- hsigmaS <- 1 / n * (t(XS )%*% XS ) # hsigma[S,S]
160
- hsigmaSinv <- solve(hsigmaS ) # pinv(hsigmaS)
160
+ FS = rbind(diag(length(S )),matrix (0 ,pp - length(S ),length(S )))
161
+ GS = cbind(diag(length(S )),matrix (0 ,length(S ),pp - length(S )))
161
162
162
- # Approximate inverse covariance matrix for when (n < p) from lasso_Inference.R
163
+ is_wide = n < ( 2 * p ) # somewhat arbitrary decision -- it is really for when we don't want to form with pxp matrices
163
164
164
- htheta = debiasingMatrix(hsigma , n , 1 : length(S ), verbose = FALSE , max_try = linesearch.try , warn_kkt = TRUE )
165
+ # Approximate inverse covariance matrix for when (n < p) from lasso_Inference.R
166
+ if (! is_wide ) {
167
+ hsigma = 1 / n * (t(Xordered )%*% Xordered )
168
+ htheta = debiasingMatrix(hsigma , is_wide , n , 1 : length(S ), verbose = FALSE , max_try = linesearch.try , warn_kkt = TRUE )
169
+ ithetasigma = (GS - (htheta %*% hsigma ))
170
+ } else {
171
+ htheta = debiasingMatrix(Xordered , is_wide , n , 1 : length(S ), verbose = FALSE , max_try = linesearch.try , warn_kkt = TRUE )
172
+ ithetasigma = (GS - ((htheta %*% t(Xordered )) %*% Xordered )/ n )
173
+ }
165
174
166
- FS = rbind(diag(length(S )),matrix (0 ,pp - length(S ),length(S )))
167
- GS = cbind(diag(length(S )),matrix (0 ,length(S ),pp - length(S )))
168
- ithetasigma = (GS - (htheta %*% hsigma ))
169
- # ithetasigma = (diag(pp) - (htheta%*%hsigma))
170
-
171
175
M <- (((htheta %*% t(Xordered ))+ ithetasigma %*% FS %*% hsigmaSinv %*% t(XS ))/ n )
172
176
# vector which is offset for testing debiased beta's
173
177
null_value <- (((ithetasigma %*% FS %*% hsigmaSinv )%*% sign(hbetaS ))* lambda / n )
@@ -264,10 +268,11 @@ fixedLassoPoly =
264
268
# # Approximates inverse covariance matrix theta
265
269
# # using coordinate descent
266
270
267
- debiasingMatrix = function (Sigma ,
271
+ debiasingMatrix = function (Xinfo , # could be X or t(X) %*% X / n depending on is_wide
272
+ is_wide ,
268
273
nsample ,
269
274
rows ,
270
- verbose = FALSE ,
275
+ verbose = FALSE ,
271
276
mu = NULL , # starting value of mu
272
277
linesearch = TRUE , # do a linesearch?
273
278
scaling_factor = 1.5 , # multiplicative factor for linesearch
@@ -284,7 +289,7 @@ debiasingMatrix = function(Sigma,
284
289
max_active = max(50 , 0.3 * nsample )
285
290
}
286
291
287
- p = nrow( Sigma );
292
+ p = ncol( Xinfo );
288
293
M = matrix (0 , length(rows ), p );
289
294
290
295
if (is.null(mu )) {
@@ -302,12 +307,13 @@ debiasingMatrix = function(Sigma,
302
307
print(paste(xperc ," % done" ,sep = " " )); }
303
308
}
304
309
305
- output = debiasingRow(Sigma ,
310
+ output = debiasingRow(Xinfo , # could be X or t(X) %*% X / n depending on is_wide
311
+ is_wide ,
306
312
row ,
307
313
mu ,
308
314
linesearch = linesearch ,
309
315
scaling_factor = scaling_factor ,
310
- max_active = max_active ,
316
+ max_active = max_active ,
311
317
max_try = max_try ,
312
318
warn_kkt = FALSE ,
313
319
max_iter = max_iter ,
@@ -329,25 +335,26 @@ debiasingMatrix = function(Sigma,
329
335
return (M )
330
336
}
331
337
332
- # Find one row of the debiasing matrix
338
+ # Find one row of the debiasing matrix -- assuming X^TX/n is not too large -- i.e. X is tall
333
339
334
- debiasingRow = function (Sigma ,
340
+ debiasingRow = function (Xinfo , # could be X or t(X) %*% X / n depending on is_wide
341
+ is_wide ,
335
342
row ,
336
343
mu ,
337
- linesearch = TRUE , # do a linesearch?
344
+ linesearch = TRUE , # do a linesearch?
338
345
scaling_factor = 1.2 , # multiplicative factor for linesearch
339
- max_active = NULL , # how big can active set get?
346
+ max_active = NULL , # how big can active set get?
340
347
max_try = 10 , # how many steps in linesearch?
341
348
warn_kkt = FALSE , # warn if KKT does not seem to be satisfied?
342
349
max_iter = 100 , # how many iterations for each optimization problem
343
350
kkt_tol = 1.e-4 , # tolerance for the KKT conditions
344
351
objective_tol = 1.e-8 # tolerance for relative decrease in objective
345
352
) {
346
353
347
- p = nrow( Sigma )
354
+ p = ncol( Xinfo )
348
355
349
356
if (is.null(max_active )) {
350
- max_active = nrow(Sigma )
357
+ max_active = nrow(Xinfo )
351
358
}
352
359
353
360
# Initialize variables
@@ -371,18 +378,37 @@ debiasingRow = function (Sigma,
371
378
372
379
while (counter_idx < max_try ) {
373
380
374
- result = solve_QP(Sigma ,
375
- mu ,
376
- max_iter ,
377
- soln ,
378
- linear_func ,
379
- gradient ,
380
- ever_active ,
381
- nactive ,
382
- kkt_tol ,
383
- objective_tol ,
384
- max_active )
381
+ if (! is_wide ) {
382
+ Sigma = Xinfo
383
+ result = solve_QP(Sigma ,
384
+ mu ,
385
+ max_iter ,
386
+ soln ,
387
+ linear_func ,
388
+ gradient ,
389
+ ever_active ,
390
+ nactive ,
391
+ kkt_tol ,
392
+ objective_tol ,
393
+ max_active )
394
+ } else {
395
+ X = Xinfo
396
+ n = nrow(X )
397
+ Xsoln = rep(0 , n )
398
+ result = solve_QP_wide(X ,
399
+ mu ,
400
+ max_iter ,
401
+ soln ,
402
+ linear_func ,
403
+ gradient ,
404
+ Xsoln ,
405
+ ever_active ,
406
+ nactive ,
407
+ kkt_tol ,
408
+ objective_tol ,
409
+ max_active )
385
410
411
+ }
386
412
iter = result $ iter
387
413
388
414
# Logic for whether we should continue the line search
@@ -439,6 +465,7 @@ debiasingRow = function (Sigma,
439
465
440
466
}
441
467
468
+
442
469
# #############################
443
470
444
471
print.fixedLassoInf <- function (x , tailarea = TRUE , ... ) {
0 commit comments