Skip to content

Commit f6ae738

Browse files
removing debug statements, making objective computation faster
1 parent c7c41e4 commit f6ae738

File tree

2 files changed

+9
-43
lines changed

2 files changed

+9
-43
lines changed

selectiveInference/R/funs.fixed.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,6 @@ InverseLinftyOneRowC <- function (Sigma, i, mu, maxiter=50) {
361361

362362
# Check feasibility
363363

364-
# DEBUG statements
365-
#print(diag(Sigma))
366-
#print(0.5 * sum(val$theta * (Sigma %*% val$theta)) - val$theta[i] + mu * sum(abs(val$theta)))
367-
#print(Sigma %*% val$theta - val$Sigma_theta)
368-
#print(val$nrow) # number of iterations
369-
370364
if (max(abs(Sigma %*% val$theta - basis_vector)) > 1.01 * mu) {
371365
warning("Solution for row of M does not seem to be feasible")
372366
}

selectiveInference/src/debiasing_matrix.c

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ double objective(double *Sigma, /* A covariance matrix: X^TX/n */
2727

2828
for (irow=0; irow<nrow; irow++) {
2929
double *theta_col_ptr = theta;
30-
for (icol=0; icol<nrow; icol++) {
31-
value += 0.5 * (*Sigma_ptr) * (*theta_row_ptr) * (*theta_col_ptr);
32-
Sigma_ptr++;
33-
theta_col_ptr++;
30+
if (*theta_row_ptr != 0) {
31+
for (icol=0; icol<nrow; icol++) {
32+
value += 0.5 * (*Sigma_ptr) * (*theta_row_ptr) * (*theta_col_ptr);
33+
Sigma_ptr++;
34+
theta_col_ptr++;
35+
}
3436
}
3537
if (irow == row) {
3638
value -= (*theta_row_ptr); // the elementary basis vector term
3739
}
38-
3940
value = value + bound * fabs((*theta_row_ptr)); // the \ell_1 term
4041
theta_row_ptr++;
4142
}
@@ -108,39 +109,11 @@ double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n
108109
Sigma_ptr += 1;
109110
}
110111

111-
double before = objective(Sigma,
112-
nrow,
113-
row,
114-
bound,
115-
theta);
116-
fprintf(stderr, "before %f\n", before);
117-
118-
theta_ptr = ((double *) theta + coord);
119-
*theta_ptr = value;
120-
121-
double after = objective(Sigma,
122-
nrow,
123-
row,
124-
bound,
125-
theta);
126-
127-
fprintf(stderr, "after %f\n", after);
128-
if (after > before) {
129-
fprintf(stderr, "not a descent step!!!!!!!!!!!!!!!!!!!!!\n");
130-
}
131-
112+
theta_ptr = ((double *) theta + coord);
113+
*theta_ptr = value;
132114

133115
}
134116

135-
Sigma_ptr = ((double *) Sigma + coord * nrow);
136-
Sigma_theta_ptr = ((double *) Sigma_theta);
137-
for (icol=0; icol<nrow; icol++) {
138-
139-
Sigma_theta_ptr += 1;
140-
Sigma_ptr += 1;
141-
}
142-
143-
144117
return(value);
145118

146119
}
@@ -201,11 +174,10 @@ void find_one_row(double *Sigma, /* A covariance matrix: X^TX/n */
201174
bound,
202175
theta);
203176

204-
if (((old_value - new_value) < tol * fabs(new_value)) && (iter > 5)) {
177+
if (((old_value - new_value) < tol * fabs(new_value)) && (iter > 0)) {
205178
break;
206179
}
207180

208-
fprintf(stderr, "%f %f value\n", old_value, new_value);
209181
old_value = new_value;
210182
}
211183

0 commit comments

Comments
 (0)