@@ -2,9 +2,9 @@ library(selectiveInference)
2
2
3
3
4
4
# # Approximates inverse covariance matrix theta
5
- InverseLinfty <- function (sigma , n , resol = 1.5 , mu = NULL , maxiter = 50 , threshold = 1e-10 , verbose = TRUE ) {
5
+ InverseLinfty <- function (sigma , n , resol = 1.5 , bound = NULL , maxiter = 50 , threshold = 1e-10 , verbose = TRUE ) {
6
6
isgiven <- 1 ;
7
- if (is.null(mu )){
7
+ if (is.null(bound )){
8
8
isgiven <- 0 ;
9
9
}
10
10
@@ -19,43 +19,43 @@ InverseLinfty <- function(sigma, n, resol=1.5, mu=NULL, maxiter=50, threshold=1e
19
19
print(paste(xperc ," % done" ,sep = " " )); }
20
20
}
21
21
if (isgiven == 0 ){
22
- mu <- (1 / sqrt(n )) * qnorm(1 - (0.1 / (p ^ 2 )));
22
+ bound <- (1 / sqrt(n )) * qnorm(1 - (0.1 / (p ^ 2 )));
23
23
}
24
- mu .stop <- 0 ;
24
+ bound .stop <- 0 ;
25
25
try.no <- 1 ;
26
26
incr <- 0 ;
27
- while ((mu .stop != 1 )&& (try.no < 10 )){
27
+ while ((bound .stop != 1 )&& (try.no < 10 )){
28
28
last.beta <- beta
29
- output <- InverseLinftyOneRow(sigma , i , mu , maxiter = maxiter , threshold = threshold )
29
+ output <- InverseLinftyOneRow(sigma , i , bound , maxiter = maxiter , threshold = threshold )
30
30
beta <- output $ optsol
31
31
iter <- output $ iter
32
32
if (isgiven == 1 ){
33
- mu .stop <- 1
33
+ bound .stop <- 1
34
34
}
35
35
else {
36
36
if (try.no == 1 ){
37
37
if (iter == (maxiter + 1 )){
38
38
incr <- 1 ;
39
- mu <- mu * resol ;
39
+ bound <- bound * resol ;
40
40
} else {
41
41
incr <- 0 ;
42
- mu <- mu / resol ;
42
+ bound <- bound / resol ;
43
43
}
44
44
}
45
45
if (try.no > 1 ){
46
46
if ((incr == 1 )&& (iter == (maxiter + 1 ))){
47
- mu <- mu * resol ;
47
+ bound <- bound * resol ;
48
48
}
49
49
if ((incr == 1 )&& (iter < (maxiter + 1 ))){
50
- mu .stop <- 1 ;
50
+ bound .stop <- 1 ;
51
51
}
52
52
if ((incr == 0 )&& (iter < (maxiter + 1 ))){
53
- mu <- mu / resol ;
53
+ bound <- bound / resol ;
54
54
}
55
55
if ((incr == 0 )&& (iter == (maxiter + 1 ))){
56
- mu <- mu * resol ;
56
+ bound <- bound * resol ;
57
57
beta <- last.beta ;
58
- mu .stop <- 1 ;
58
+ bound .stop <- 1 ;
59
59
}
60
60
}
61
61
}
@@ -66,14 +66,14 @@ InverseLinfty <- function(sigma, n, resol=1.5, mu=NULL, maxiter=50, threshold=1e
66
66
return (M )
67
67
}
68
68
69
- InverseLinftyOneRow <- function ( sigma , i , mu , maxiter = 50 , threshold = 1e-10 ) {
69
+ InverseLinftyOneRow <- function ( sigma , i , bound , maxiter = 50 , threshold = 1e-10 ) {
70
70
p <- nrow(sigma );
71
71
rho <- max(abs(sigma [i ,- i ])) / sigma [i ,i ];
72
- mu0 <- rho / (1 + rho );
72
+ bound0 <- rho / (1 + rho );
73
73
beta <- rep(0 ,p );
74
74
75
- # if (mu >= mu0 ){
76
- # beta[i] <- (1-mu0 )/sigma[i,i];
75
+ # if (bound >= bound0 ){
76
+ # beta[i] <- (1-bound0 )/sigma[i,i];
77
77
# returnlist <- list("optsol" = beta, "iter" = 0);
78
78
# return(returnlist);
79
79
# }
@@ -82,7 +82,7 @@ InverseLinftyOneRow <- function ( sigma, i, mu, maxiter=50, threshold=1e-10) {
82
82
last.norm2 <- 1 ;
83
83
iter <- 1 ;
84
84
iter.old <- 1 ;
85
- beta [i ] <- (1 - mu0 )/ sigma [i ,i ];
85
+ beta [i ] <- (1 - bound0 )/ sigma [i ,i ];
86
86
beta.old <- beta ;
87
87
sigma.tilde <- sigma ;
88
88
diag(sigma.tilde ) <- 0 ;
@@ -95,7 +95,7 @@ InverseLinftyOneRow <- function ( sigma, i, mu, maxiter=50, threshold=1e-10) {
95
95
v <- vs [j ];
96
96
if (j == i )
97
97
v <- v + 1 ;
98
- beta [j ] <- SoftThreshold(v ,mu )/ sigma [j ,j ];
98
+ beta [j ] <- SoftThreshold(v ,bound )/ sigma [j ,j ];
99
99
if (oldval != beta [j ]){
100
100
vs <- vs + (oldval - beta [j ])* sigma.tilde [,j ];
101
101
}
@@ -112,7 +112,7 @@ InverseLinftyOneRow <- function ( sigma, i, mu, maxiter=50, threshold=1e-10) {
112
112
# vs <- -sigma.tilde%*%beta;
113
113
}
114
114
115
- # print(c(iter, maxiter, diff.norm2, threshold * last.norm2, threshold, mu ))
115
+ # print(c(iter, maxiter, diff.norm2, threshold * last.norm2, threshold, bound ))
116
116
117
117
}
118
118
@@ -142,19 +142,21 @@ n = 100; p = 50
142
142
X = matrix (rnorm(n * p ), n , p )
143
143
S = t(X ) %*% X / n
144
144
145
- mu = 7.791408e-02
145
+ debiasing_bound = 7.791408e-02
146
146
147
147
tol = 1.e-12
148
148
149
- rows = c(1 : 2 )
150
- A1 = debiasingMatrix(S , FALSE , n , rows , mu = mu , max_iter = 1000 , kkt_tol = tol , objective_tol = tol , parameter_tol = tol )
151
- A2 = debiasingMatrix(S / n , FALSE , n , rows , mu = mu , max_iter = 1000 , kkt_tol = tol , objective_tol = tol , parameter_tol = tol )
149
+ rows = as.integer(c(1 : 2 ))
150
+ print(' here' )
151
+ print(rows )
152
+ A1 = debiasingMatrix(S , FALSE , n , rows , bound = debiasing_bound , max_iter = 1000 , kkt_tol = tol , objective_tol = tol , parameter_tol = tol , linesearch = FALSE )
152
153
153
- B1 = debiasingMatrix(X , TRUE , n , rows , mu = mu , max_iter = 1000 , kkt_tol = tol , objective_tol = tol , parameter_tol = tol )
154
- B2 = debiasingMatrix(X / sqrt(n ), TRUE , n , rows , mu = mu , max_iter = 1000 , kkt_tol = tol , objective_tol = tol , parameter_tol = tol )
154
+ A2 = debiasingMatrix(S / n , FALSE , n , rows , bound = debiasing_bound , max_iter = 1000 , kkt_tol = tol , objective_tol = tol , parameter_tol = tol , linesearch = FALSE )
155
+ B1 = debiasingMatrix(X , TRUE , n , rows , bound = debiasing_bound , max_iter = 1000 , kkt_tol = tol , objective_tol = tol , parameter_tol = tol , linesearch = FALSE )
156
+ B2 = debiasingMatrix(X / sqrt(n ), TRUE , n , rows , bound = debiasing_bound , max_iter = 1000 , kkt_tol = tol , objective_tol = tol , parameter_tol = tol , linesearch = FALSE )
155
157
156
- C1 = InverseLinfty(S , n , mu = mu , maxiter = 1000 )[rows ,]
157
- C2 = InverseLinfty(S / n , n , mu = mu , maxiter = 1000 )[rows ,]
158
+ C1 = InverseLinfty(S , n , bound = debiasing_bound , maxiter = 1000 )[rows ,]
159
+ C2 = InverseLinfty(S / n , n , bound = debiasing_bound , maxiter = 1000 )[rows ,]
158
160
159
161
par(mfrow = c(2 ,3 ))
160
162
@@ -172,30 +174,30 @@ print(c('C', sum(C1[1,] == 0)))
172
174
173
175
# # Are our points feasible
174
176
175
- feasibility = function (S , soln , j , mu ) {
177
+ feasibility = function (S , soln , j , debiasing_bound ) {
176
178
p = nrow(S )
177
179
E = rep(0 , p )
178
180
E [j ] = 1
179
181
G = S %*% soln - E
180
- return (c(max(abs(G )), mu ))
182
+ return (c(max(abs(G )), debiasing_bound ))
181
183
}
182
184
183
- print(c(' feasibility A' , feasibility(S , A1 [1 ,], 1 , mu )))
184
- print(c(' feasibility B' , feasibility(S , B1 [1 ,], 1 , mu )))
185
- print(c(' feasibility C' , feasibility(S , C1 [1 ,], 1 , mu )))
185
+ print(c(' feasibility A' , feasibility(S , A1 [1 ,], 1 , debiasing_bound )))
186
+ print(c(' feasibility B' , feasibility(S , B1 [1 ,], 1 , debiasing_bound )))
187
+ print(c(' feasibility C' , feasibility(S , C1 [1 ,], 1 , debiasing_bound )))
186
188
187
- active_KKT = function (S , soln , j , mu ) {
189
+ active_KKT = function (S , soln , j , debiasing_bound ) {
188
190
p = nrow(S )
189
191
E = rep(0 , p )
190
192
E [j ] = 1
191
193
G = S %*% soln - E
192
194
print(which(soln != 0 ))
193
195
print(G [j ])
194
- return (c(G [soln != 0 ] * sign(soln )[soln != 0 ], mu ))
196
+ return (c(G [soln != 0 ] * sign(soln )[soln != 0 ], debiasing_bound ))
195
197
}
196
198
197
- print(c(' active_KKT A' , active_KKT(S , A1 [1 ,], 1 , mu )))
198
- print(c(' active_KKT B' , active_KKT(S , B1 [1 ,], 1 , mu )))
199
- print(c(' active_KKT C' , active_KKT(S , C1 [1 ,], 1 , mu )))
199
+ print(c(' active_KKT A' , active_KKT(S , A1 [1 ,], 1 , debiasing_bound )))
200
+ print(c(' active_KKT B' , active_KKT(S , B1 [1 ,], 1 , debiasing_bound )))
201
+ print(c(' active_KKT C' , active_KKT(S , C1 [1 ,], 1 , debiasing_bound )))
200
202
201
203
0 commit comments