Skip to content

Commit a9a8bbb

Browse files
renaming Sigma_theta to gradient, making sure we loop through active set
1 parent 7360386 commit a9a8bbb

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

selectiveInference/src/debias.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ int update_ever_active(int coord,
6565
int *ever_active_ptr = ever_active;
6666

6767
for (iactive=0; iactive<nactive; iactive++) {
68+
ever_active_ptr = ((int *) ever_active + iactive);
6869
active_var = (*ever_active_ptr);
6970
if (active_var == coord) {
7071

@@ -83,7 +84,7 @@ int update_ever_active(int coord,
8384
}
8485

8586
int check_KKT(double *theta, /* current theta */
86-
double *Sigma_theta, /* Sigma times theta */
87+
double *gradient_ptr, /* Sigma times theta */
8788
int nrow, /* how many rows in Sigma */
8889
int row, /* which row: 0-based */
8990
double bound) /* Lagrange multipler for \ell_1 */
@@ -93,16 +94,16 @@ int check_KKT(double *theta, /* current theta */
9394
int irow;
9495
int fail = 0;
9596
double tol = 1.e-4;
96-
double *theta_ptr, *Sigma_theta_ptr;
97+
double *theta_ptr, *gradient_ptr_tmp;
9798
double gradient;
9899

99100
for (irow=0; irow<nrow; irow++) {
100101
theta_ptr = ((double *) theta + irow);
101-
Sigma_theta_ptr = ((double *) Sigma_theta + irow);
102+
gradient_ptr_tmp = ((double *) gradient_ptr + irow);
102103

103104
// Compute this coordinate of the gradient
104105

105-
gradient = *Sigma_theta_ptr;
106+
gradient = *gradient_ptr_tmp;
106107
if (row == irow) {
107108
gradient -= 1;
108109
}
@@ -127,7 +128,7 @@ int check_KKT(double *theta, /* current theta */
127128

128129
double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n */
129130
double *Sigma_diag, /* Diagonal entries of Sigma */
130-
double *Sigma_theta, /* Sigma times theta */
131+
double *gradient_ptr, /* Sigma times theta */
131132
int *ever_active, /* Ever active set: 0-based */
132133
int *nactive_ptr, /* Size of ever active set */
133134
int nrow, /* How many rows in Sigma */
@@ -143,7 +144,7 @@ double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n
143144
double value = 0;
144145
double old_value;
145146
double *Sigma_ptr;
146-
double *Sigma_theta_ptr;
147+
double *gradient_ptr_tmp;
147148
double *theta_ptr;
148149
int icol = 0;
149150

@@ -152,13 +153,13 @@ double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n
152153

153154
int *ever_active_ptr;
154155

155-
Sigma_theta_ptr = ((double *) Sigma_theta + coord);
156-
linear_term = *Sigma_theta_ptr;
156+
gradient_ptr_tmp = ((double *) gradient_ptr + coord);
157+
linear_term = *gradient_ptr_tmp;
157158

158159
theta_ptr = ((double *) theta + coord);
159160
old_value = *theta_ptr;
160161

161-
// The coord entry of Sigma_theta term has a diagonal term in it:
162+
// The coord entry of gradient_ptr term has a diagonal term in it:
162163
// Sigma[coord, coord] * theta[coord]
163164
// This removes it.
164165
linear_term -= quadratic_term * old_value;
@@ -194,11 +195,11 @@ double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n
194195

195196
delta = value - old_value;
196197
Sigma_ptr = ((double *) Sigma + coord * nrow);
197-
Sigma_theta_ptr = ((double *) Sigma_theta);
198+
gradient_ptr_tmp = ((double *) gradient_ptr);
198199

199200
for (icol=0; icol<nrow; icol++) {
200-
*Sigma_theta_ptr = *Sigma_theta_ptr + delta * (*Sigma_ptr);
201-
Sigma_theta_ptr += 1;
201+
*gradient_ptr_tmp = *gradient_ptr_tmp + delta * (*Sigma_ptr);
202+
gradient_ptr_tmp += 1;
202203
Sigma_ptr += 1;
203204
}
204205

@@ -213,7 +214,7 @@ double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n
213214

214215
int find_one_row_(double *Sigma, /* A covariance matrix: X^TX/n */
215216
double *Sigma_diag, /* Diagonal entry of covariance matrix */
216-
double *Sigma_theta, /* Sigma times theta */
217+
double *gradient_ptr, /* Sigma times theta */
217218
int *ever_active, /* Ever active set: 0-based */
218219
int *nactive_ptr, /* Size of ever active set */
219220
int nrow, /* How many rows in Sigma */
@@ -247,7 +248,7 @@ int find_one_row_(double *Sigma, /* A covariance matrix: X^TX/n */
247248
for (iactive=0; iactive < *nactive_ptr; iactive++) {
248249
update_one_coord(Sigma,
249250
Sigma_diag,
250-
Sigma_theta,
251+
gradient_ptr,
251252
ever_active,
252253
nactive_ptr,
253254
nrow,
@@ -260,7 +261,7 @@ int find_one_row_(double *Sigma, /* A covariance matrix: X^TX/n */
260261
}
261262

262263
if (check_KKT(theta,
263-
Sigma_theta,
264+
gradient_ptr,
264265
nrow,
265266
row,
266267
bound) == 1) {
@@ -271,7 +272,7 @@ int find_one_row_(double *Sigma, /* A covariance matrix: X^TX/n */
271272

272273
update_one_coord(Sigma,
273274
Sigma_diag,
274-
Sigma_theta,
275+
gradient_ptr,
275276
ever_active,
276277
nactive_ptr,
277278
nrow,
@@ -283,7 +284,7 @@ int find_one_row_(double *Sigma, /* A covariance matrix: X^TX/n */
283284
}
284285

285286
if (check_KKT(theta,
286-
Sigma_theta,
287+
gradient_ptr,
287288
nrow,
288289
row,
289290
bound) == 1) {

0 commit comments

Comments
 (0)