Skip to content

Commit 4fc539d

Browse files
Merge branch 'master' into logistic
2 parents 157c1db + 183bc3a commit 4fc539d

File tree

4 files changed

+20
-47
lines changed

4 files changed

+20
-47
lines changed

selectiveInference/R/RcppExports.R

Lines changed: 0 additions & 35 deletions
This file was deleted.

selectiveInference/R/funs.randomized.R

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ randomizedLasso = function(X,
3434
noise_scale = 0.5 * sd(y) * sqrt(mean_diag)
3535
}
3636

37-
print(paste("ridge term", ridge_term))
38-
print(paste("noise scale", noise_scale))
39-
4037
noise_type = match.arg(noise_type)
4138

4239
if (noise_scale > 0) {
@@ -101,8 +98,8 @@ randomizedLasso = function(X,
10198
observed_unpen = result$soln[unpenalized]
10299
observed_subgrad = -n*result$gradient[inactive]
103100

104-
if (length(which(abs(observed_subgrad)>lam[1]))){
105-
print("subgradient eq not satisfied")
101+
if (sum(abs(observed_subgrad)>lam*(1.001)) > 0){
102+
stop("subgradient eq not satisfied")
106103
}
107104

108105
observed_opt_state = c(observed_unpen, observed_scalings, observed_subgrad)
@@ -355,15 +352,16 @@ conditional_density = function(noise_scale, lasso_soln) {
355352
randomizedLassoInf = function(X,
356353
y,
357354
lam,
358-
family="gaussian",
359-
sampler="A",
355+
family=c("gaussian", "logistic"),
356+
sampler=c("norejection", "adaptMCMC"),
360357
sigma=NULL,
361358
noise_scale=NULL,
362359
ridge_term=NULL,
363360
condition_subgrad=TRUE,
364361
level=0.9,
365-
nsample=10000,
366-
burnin=2000,
362+
sampler=c("norejection", "adaptMCMC"),
363+
nsample=10000,
364+
burnin=2000,
367365
max_iter=100, # how many iterations for each optimization problem
368366
kkt_tol=1.e-4, # tolerance for the KKT conditions
369367
parameter_tol=1.e-8, # tolerance for relative convergence of parameter
@@ -376,6 +374,8 @@ randomizedLassoInf = function(X,
376374
n = nrow(X)
377375
p = ncol(X)
378376

377+
family = match.arg(family)
378+
379379
lasso_soln = randomizedLasso(X,
380380
y,
381381
lam,
@@ -392,7 +392,7 @@ randomizedLassoInf = function(X,
392392

393393
active_set = lasso_soln$active_set
394394
nactive = length(active_set)
395-
print(paste("nactive", nactive))
395+
396396
if (nactive==0){
397397
return (list(active_set=active_set, pvalues=c(), ci=c()))
398398
}
@@ -418,10 +418,12 @@ randomizedLassoInf = function(X,
418418

419419
ndim = length(lasso_soln$observed_opt_state)
420420

421-
if (sampler =="R"){
421+
sampler = match.arg(sampler)
422+
423+
if (sampler == "adaptMCMC"){
422424
S = sample_opt_variables(lasso_soln, jump_scale=rep(1/sqrt(n), ndim), nsample=nsample)
423425
opt_samples = as.matrix(S$samples[(burnin+1):nsample,,drop=FALSE])
424-
} else if (sampler == "A"){
426+
} else if (sampler == "norejection") {
425427
opt_samples = gaussian_sampler(noise_scale,
426428
lasso_soln$observed_opt_state,
427429
cur_opt_transform$linear_term,

selectiveInference/R/sampler.R renamed to selectiveInference/R/funs.sampler.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# A no-rejection MCMC algorithm Jelena and Amir have been working on
12

23
log_concave_sampler = function(negative_log_density,
34
grad_negative_log_density,

selectiveInference/man/randomizedLassoInf.Rd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ randomizedLassoInf(X,
1919
ridge_term=NULL,
2020
condition_subgrad=TRUE,
2121
level=0.9,
22+
sampler=c("norejection", "adaptMCMC"),
2223
nsample=10000,
2324
burnin=2000,
2425
max_iter=100,
@@ -71,6 +72,10 @@ Default is TRUE.
7172
\item{level}{
7273
Level for confidence intervals.
7374
}
75+
\item{sampler}{
76+
Which sampler to use -- default is a no-rejection sampler. Otherwise
77+
use MCMC from the adaptMCMC package.
78+
}
7479
\item{nsample}{
7580
Number of samples of optimization variables to sample.
7681
}

0 commit comments

Comments
 (0)