Skip to content

Commit f13bce4

Browse files
allowing randomization to be 0 in solver
1 parent 83b0426 commit f13bce4

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

selectiveInference/R/funs.randomized.R

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ fit_randomized_lasso = function(X,
2222

2323
noise_type = match.arg(noise_type)
2424

25-
if (noise_type == 'gaussian') {
26-
D = Norm(mean=0, sd=noise_scale)
25+
if (noise_scale > 0) {
26+
if (noise_type == 'gaussian') {
27+
D = Norm(mean=0, sd=noise_scale)
28+
}
29+
else if (noise_type == 'laplace') {
30+
D = DExp(rate = 1 / noise_scale) # D is a Laplace distribution with rate = 1.
31+
}
32+
perturb_ = distr::r(D)(p)
33+
} else {
34+
perturb_ = rep(0, p)
2735
}
28-
else if (noise_type == 'laplace') {
29-
D = DExp(rate = 1 / noise_scale) # D is a Laplace distribution with rate = 1.
30-
}
31-
perturb_ = distr::r(D)(p)
32-
36+
3337
lam = as.numeric(lam)
3438
if (length(lam) == 1) {
3539
lam = rep(lam, p)

tests/test_QP.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ X = matrix(rnorm(n * p), n, p)
77
Y = rnorm(n)
88
lam = 2
99

10-
soln1 = selectiveInference:::fit_randomized_lasso(X, Y, lam, 1.e-12, 0)$soln
10+
soln1 = selectiveInference:::fit_randomized_lasso(X, Y, lam, 0, 0)$soln
1111
G = glmnet(X, Y, intercept=FALSE, standardize=FALSE)
1212
soln2 = coef(G, s=1/n, exact=TRUE, x=X, y=Y)[-1]
1313

0 commit comments

Comments
 (0)