Skip to content

Commit 4d67199

Browse files
added a warning about feasibility -- but it didn't print in gist?
1 parent 248ce54 commit 4d67199

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

selectiveInference/R/funs.fixed.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,15 @@ InverseLinfty <- function(sigma, n, e, resol=1.5, mu=NULL, maxiter=50, threshold
334334
return(M)
335335
}
336336

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

339-
p = nrow(sigma)
339+
p = nrow(Sigma)
340+
basis_vector = rep(0, p)
341+
basis_vector[i] = 1.
340342
theta = rep(0, p)
341343

342344
val = .C("find_one_row",
343-
Sigma=as.double(sigma),
345+
Sigma=as.double(Sigma),
344346
nrow=as.integer(p),
345347
bound=as.double(mu),
346348
theta=as.double(theta),
@@ -350,6 +352,13 @@ InverseLinftyOneRowC <- function ( sigma, i, mu, maxiter=50, threshold=1e-2 ) {
350352
dup=FALSE,
351353
package="selectiveInference")
352354

355+
# Check feasibility
356+
357+
if (max(abs(Sigma %*% val$theta - basis_vector)) > 1.01 * mu) {
358+
print("Solution for row of M does not seem to be feasible")
359+
warning("Solution for row of M does not seem to be feasible")
360+
}
361+
353362
return(val$theta)
354363
}
355364

selectiveInference/src/debiasing_matrix.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
// Find an approximate row of \hat{Sigma}^{-1}
55

6-
// Problem (4) of ????
6+
// Solves a dual version of problem (4) of https://arxiv.org/pdf/1306.3171.pdf
77

8+
// Dual problem: \text{min}_{\theta} 1/2 \theta^T \Sigma \theta - e_i^T\theta + \mu \|\theta\|_1
9+
10+
// This is the "negative" of the problem as in https://gist.github.com/jonathan-taylor/07774d209173f8bc4e42aa37712339bf
11+
// Therefore we don't have to negate the answer to get theta.
812
// Update one coordinate
913

1014
double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n */
@@ -36,19 +40,22 @@ double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n */
3640
}
3741

3842
if (row == coord) {
39-
linear_term += 1;
43+
linear_term -= 1;
4044
}
4145

4246
// Now soft-threshold the coord entry of theta
4347

4448
// Objective is t \mapsto q/2 * t^2 + l * t + bound |t|
4549
// with q=quadratic_term and l=linear_term
4650

51+
// With a negative linear term, solution should be
52+
// positive
53+
4754
if (linear_term < -bound) {
48-
value = - (-linear_term - bound) / quadratic_term;
55+
value = (-linear_term - bound) / quadratic_term;
4956
}
5057
else if (linear_term > bound) {
51-
value = (linear_term - bound) / quadratic_term;
58+
value = -(linear_term - bound) / quadratic_term;
5259
}
5360

5461
theta_ptr = ((double *) theta + coord);

0 commit comments

Comments
 (0)