Skip to content

Commit 210d0fe

Browse files
using C for each row
1 parent e87d12d commit 210d0fe

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

selectiveInference/R/funs.fixed.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ sigma=NULL, alpha=0.1,
159159
hsigmaSinv <- solve(hsigmaS) # pinv(hsigmaS)
160160

161161
# Approximate inverse covariance matrix for when (n < p) from lasso_Inference.R
162-
htheta <- InverseLinfty(hsigma, n, length(S), verbose=FALSE)
162+
useC = TRUE
163+
htheta <- InverseLinfty(hsigma, n, length(S), verbose=FALSE, useC=useC)
163164
# htheta <- InverseLinfty(hsigma, n, verbose=FALSE)
164165

165166
FS = rbind(diag(length(S)),matrix(0,pp-length(S),length(S)))
@@ -269,7 +270,7 @@ fixedLasso.poly=
269270
### Functions borrowed and slightly modified from lasso_inference.R
270271

271272
## Approximates inverse covariance matrix theta
272-
InverseLinfty <- function(sigma, n, e, resol=1.5, mu=NULL, maxiter=50, threshold=1e-2, verbose = TRUE) {
273+
InverseLinfty <- function(sigma, n, e, resol=1.5, mu=NULL, maxiter=50, threshold=1e-2, verbose = TRUE, useC = FALSE) {
273274
# InverseLinfty <- function(sigma, n, resol=1.5, mu=NULL, maxiter=50, threshold=1e-2, verbose = TRUE) {
274275
isgiven <- 1;
275276
if (is.null(mu)){
@@ -294,7 +295,11 @@ InverseLinfty <- function(sigma, n, e, resol=1.5, mu=NULL, maxiter=50, threshold
294295
incr <- 0;
295296
while ((mu.stop != 1)&&(try.no<10)){
296297
last.beta <- beta
297-
output <- InverseLinftyOneRow(sigma, i, mu, maxiter=maxiter, threshold=threshold)
298+
if (useC == FALSE) {
299+
output <- InverseLinftyOneRow(sigma, i, mu, maxiter=maxiter, threshold=threshold)
300+
} else {
301+
output <- InverseLinftyOneRowC(sigma, i, mu, maxiter=maxiter)
302+
}
298303
beta <- output$optsol
299304
iter <- output$iter
300305
if (isgiven==1){
@@ -334,7 +339,7 @@ InverseLinfty <- function(sigma, n, e, resol=1.5, mu=NULL, maxiter=50, threshold
334339
return(M)
335340
}
336341

337-
InverseLinftyOneRowC <- function (Sigma, i, mu, maxiter=50, threshold=1e-2 ) {
342+
InverseLinftyOneRowC <- function (Sigma, i, mu, maxiter=50) {
338343

339344
p = nrow(Sigma)
340345
basis_vector = rep(0, p)

0 commit comments

Comments
 (0)