Skip to content

Commit 8c956f8

Browse files
making a choice for solver
1 parent 3405f23 commit 8c956f8

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

selectiveInference/R/funs.fixed.R

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ sigma=NULL, alpha=0.1,
2626

2727
else{
2828

29-
30-
3129
checkargs.xy(x,y)
3230
if (missing(beta) || is.null(beta)) stop("Must supply the solution beta")
3331
if (missing(lambda) || is.null(lambda)) stop("Must supply the tuning parameter value lambda")
@@ -338,7 +336,8 @@ InverseLinfty <- function(sigma, n, e, resol=1.2, mu=NULL, maxiter=50, threshold
338336
return(M)
339337
}
340338

341-
InverseLinftyOneRow <- function (Sigma, i, mu, maxiter=50, soln_result=NULL, kkt_tol=1.e-6, objective_tol=1.e-6) {
339+
InverseLinftyOneRow <- function (Sigma, i, mu, maxiter=50, soln_result=NULL, kkt_tol=1.e-6, objective_tol=1.e-6,
340+
use_QP=TRUE) {
342341

343342
# If soln_result is not Null, it is used as a warm start.
344343
# It should be a list
@@ -352,31 +351,30 @@ InverseLinftyOneRow <- function (Sigma, i, mu, maxiter=50, soln_result=NULL, kkt
352351
ever_active[1] = i-1 # 0-based
353352
ever_active = as.integer(ever_active)
354353
nactive = as.integer(1)
355-
linear_func = rep(0, p)
356-
linear_func[i] = -1
357-
linear_func = as.numeric(linear_func)
358-
gradient = 1. * linear_func
354+
if (use_QP) {
355+
linear_func = rep(0, p)
356+
linear_func[i] = -1
357+
linear_func = as.numeric(linear_func)
358+
gradient = 1. * linear_func
359+
} else {
360+
gradient = rep(0, p)
361+
}
359362
}
360363
else {
361364
soln = soln_result$soln
362365
gradient = soln_result$gradient
363366
ever_active = as.integer(soln_result$ever_active)
364367
nactive = as.integer(soln_result$nactive)
365-
linear_func = soln_result$linear_func
368+
if (use_QP) {
369+
linear_func = soln_result$linear_func
370+
}
366371
}
367372

368-
soln1 = rep(0, p)
369-
gradient1 = rep(0, p)
370-
ever_active1 = rep(0, p)
371-
ever_active1[1] = i-1
372-
nactive1 = as.integer(1)
373-
result1 = find_one_row_debiasingM(Sigma, i-1, mu, maxiter, soln1, gradient1, ever_active1, nactive1, kkt_tol, objective_tol) # C function uses 0-based indexing
374-
result = solve_QP(Sigma, mu, maxiter, soln, linear_func, gradient, ever_active, nactive, kkt_tol, objective_tol)
375-
print("close?")
376-
print(c(sqrt(sum((result1$soln-result$soln)^2)/sum(result$soln^2)), sum(result$soln^2)))
377-
print(c(result1$iter, result$iter, sum(result1$soln^2)))
378-
379-
#result = find_one_row_debiasingM(Sigma, i-1, mu, maxiter, soln, gradient, ever_active, nactive, kkt_tol, objective_tol) # C function uses 0-based indexing
373+
if (use_QP) {
374+
result = solve_QP(Sigma, mu, maxiter, soln, linear_func, gradient, ever_active, nactive, kkt_tol, objective_tol)
375+
} else {
376+
result = find_one_row_debiasingM(Sigma, i-1, mu, maxiter, soln, gradient, ever_active, nactive, kkt_tol, objective_tol) # C function uses 0-based indexing
377+
}
380378

381379
# Check feasibility
382380

selectiveInference/src/debias.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <stdio.h>
21
#include <math.h> // for fabs
32

43
// Find an approximate row of \hat{Sigma}^{-1}
@@ -68,7 +67,6 @@ int update_ever_active(int coord,
6867
for (iactive=0; iactive<nactive; iactive++) {
6968
ever_active_ptr_tmp = ((int *) ever_active_ptr + iactive);
7069
active_var = (*ever_active_ptr_tmp);
71-
// fprintf(stderr, "%d %d\n", iactive, active_var);
7270
if (active_var == coord) {
7371
return(1);
7472
}

0 commit comments

Comments
 (0)