Skip to content

Commit 15762af

Browse files
BF: KKT wrong for active conditions, still have debug statements
1 parent d1debcd commit 15762af

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

selectiveInference/R/funs.fixed.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,7 @@ InverseLinftyOneRow <- function (Sigma, i, mu, maxiter=50, soln_result=NULL) {
363363
linear_func = soln_result$linear_func
364364
}
365365

366-
#print(c(soln, "soln"))
367-
#print(c(gradient, "grad"))
368-
#print(c(ever_active, "ever_active"))
369-
#print(c(nactive, "nactive"))
370-
#print(c(linear_func, "linear_func"))
371-
372-
result = find_one_row_debiasingM(Sigma, i-1, mu, maxiter, soln, linear_func, gradient, ever_active, nactive) # C function uses 0-based indexing
366+
result = find_one_row_debiasingM(Sigma, mu, maxiter, soln, linear_func, gradient, ever_active, nactive) # C function uses 0-based indexing
373367

374368
# Check feasibility
375369

selectiveInference/src/Rcpp-debias.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
// [[Rcpp::export]]
55
Rcpp::List find_one_row_debiasingM(Rcpp::NumericMatrix Sigma,
6-
int row, // 0-based
76
double bound,
87
int maxiter,
98
Rcpp::NumericVector theta,

selectiveInference/src/debias.c

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,34 +100,52 @@ int check_KKT(double *theta, /* current theta */
100100

101101
int irow;
102102
int fail = 0;
103-
double tol = 1.e-4;
104-
double *theta_ptr, *gradient_ptr_tmp;
103+
double tol = 1.e-5;
104+
double *theta_ptr = theta;
105+
double *gradient_ptr_tmp = gradient_ptr;
105106
double gradient;
106107

107108
for (irow=0; irow<nrow; irow++) {
108-
theta_ptr = ((double *) theta + irow);
109-
gradient_ptr_tmp = ((double *) gradient_ptr + irow);
110-
111-
// Compute this coordinate of the gradient
112109

113110
gradient = *gradient_ptr_tmp;
114111

115-
if (*theta_ptr != 0) { // these coordinates of gradients should be equal to -bound
116-
if ((*theta_ptr > 0) && (fabs(gradient + bound) > (1. + tol) * bound)) {
117-
fail += 1;
112+
fprintf(stderr, "how does it look %d %f %f\n", irow, *theta_ptr, gradient);
113+
114+
// Compute this coordinate of the gradient
115+
116+
if (fabs(*theta_ptr) > tol) { // these coordinates of gradients should be equal to \pm bound
117+
fprintf(stderr, "active %f %f\n", fabs(fabs(gradient) - bound), bound);
118+
if (fabs(fabs(gradient) - bound) > tol * bound) {
119+
fprintf(stderr, "here1 %d %f %f\n", irow, *theta_ptr, gradient);
120+
return(0);
121+
// fail += 1;
118122
}
119-
else if ((*theta_ptr < 0) && (fabs(gradient - bound) > (1. + tol) * bound)) {
120-
fail += 1;
123+
else if ((*theta_ptr > 0) && (gradient > 0)) {
124+
fprintf(stderr, "here2 %d %f %f\n", irow, *theta_ptr, gradient);
125+
return(0);
126+
// fail += 1;
127+
}
128+
else if ((*theta_ptr < 0) && (gradient < 0)) {
129+
fprintf(stderr, "here3 %d %f %f\n", irow, *theta_ptr, gradient);
130+
return(0);
131+
// fail += 1;
121132
}
122133
}
123134
else {
135+
fprintf(stderr, "before4 %d %f %f\n", irow, *theta_ptr, gradient);
124136
if (fabs(gradient) > (1. + tol) * bound) {
125-
fail += 1;
137+
fprintf(stderr, "here4 %d %f %f\n", irow, *theta_ptr, gradient);
138+
return(0);
139+
// fail += 1;
126140
}
127141
}
142+
theta_ptr++;
143+
gradient_ptr_tmp++;
128144
}
129145

146+
fprintf(stderr, "OK now\n");
130147
return(fail == 0);
148+
131149
}
132150

133151
double update_one_coord(double *Sigma_ptr, /* A covariance matrix: X^TX/n */
@@ -236,7 +254,7 @@ int find_one_row_(double *Sigma_ptr, /* A covariance matrix: X^TX/n */
236254
bound,
237255
theta);
238256
double new_value;
239-
double tol=1.e-5;
257+
double tol=1.e-8;
240258

241259
for (iter=0; iter<maxiter; iter++) {
242260

@@ -265,6 +283,7 @@ int find_one_row_(double *Sigma_ptr, /* A covariance matrix: X^TX/n */
265283
gradient_ptr,
266284
nrow,
267285
bound) == 1) {
286+
fprintf(stderr, "here5 \n");
268287
break;
269288
}
270289

@@ -291,6 +310,7 @@ int find_one_row_(double *Sigma_ptr, /* A covariance matrix: X^TX/n */
291310
gradient_ptr,
292311
nrow,
293312
bound) == 1) {
313+
fprintf(stderr, "here6 \n");
294314
break;
295315
}
296316

@@ -302,9 +322,9 @@ int find_one_row_(double *Sigma_ptr, /* A covariance matrix: X^TX/n */
302322
bound,
303323
theta);
304324

305-
if (((old_value - new_value) < tol * fabs(new_value)) && (iter > 0)) {
306-
break;
307-
}
325+
/* if (((old_value - new_value) < tol * fabs(new_value)) && (iter > 0)) { */
326+
/* break; */
327+
/* } */
308328

309329
old_value = new_value;
310330
}

0 commit comments

Comments
 (0)