10
10
// Therefore we don't have to negate the answer to get theta.
11
11
// Update one coordinate
12
12
13
- double objective (double * Sigma , /* A covariance matrix: X^TX/n */
13
+ double objective (double * Sigma_ptr , /* A covariance matrix: X^TX/n */
14
14
int * ever_active_ptr , /* Ever active set: 0-based */
15
15
int * nactive_ptr , /* Size of ever active set */
16
16
int nrow , /* how many rows in Sigma */
@@ -20,7 +20,7 @@ double objective(double *Sigma, /* A covariance matrix: X^TX/n */
20
20
{
21
21
int irow , icol ;
22
22
double value = 0 ;
23
- double * Sigma_ptr = Sigma ;
23
+ double * Sigma_ptr_tmp = Sigma_ptr ;
24
24
double * theta_row_ptr , * theta_col_ptr ;
25
25
int * active_row_ptr , * active_col_ptr ;
26
26
int active_row , active_col ;
@@ -41,9 +41,9 @@ double objective(double *Sigma, /* A covariance matrix: X^TX/n */
41
41
active_col = * active_col_ptr ;
42
42
theta_col_ptr = ((double * ) theta + active_col );
43
43
44
- Sigma_ptr = ((double * ) Sigma + nrow * active_col + active_row ); // Matrices are column-major order
44
+ Sigma_ptr_tmp = ((double * ) Sigma_ptr + nrow * active_col + active_row ); // Matrices are column-major order
45
45
46
- value += 0.5 * (* Sigma_ptr ) * (* theta_row_ptr ) * (* theta_col_ptr );
46
+ value += 0.5 * (* Sigma_ptr_tmp ) * (* theta_row_ptr ) * (* theta_col_ptr );
47
47
}
48
48
value = value + bound * fabs ((* theta_row_ptr )); // the \ell_1 term
49
49
}
@@ -126,8 +126,8 @@ int check_KKT(double *theta, /* current theta */
126
126
return (fail == 0 );
127
127
}
128
128
129
- double update_one_coord (double * Sigma , /* A covariance matrix: X^TX/n */
130
- double * Sigma_diag , /* Diagonal entries of Sigma */
129
+ double update_one_coord (double * Sigma_ptr , /* A covariance matrix: X^TX/n */
130
+ double * Sigma_diag_ptr , /* Diagonal entries of Sigma */
131
131
double * gradient_ptr , /* Sigma times theta */
132
132
int * ever_active_ptr , /* Ever active set: 0-based */
133
133
int * nactive_ptr , /* Size of ever active set */
@@ -143,12 +143,12 @@ double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n
143
143
double linear_term = 0 ;
144
144
double value = 0 ;
145
145
double old_value ;
146
- double * Sigma_ptr ;
146
+ double * Sigma_ptr_tmp ;
147
147
double * gradient_ptr_tmp ;
148
148
double * theta_ptr ;
149
149
int icol = 0 ;
150
150
151
- double * quadratic_ptr = ((double * ) Sigma_diag + coord );
151
+ double * quadratic_ptr = ((double * ) Sigma_diag_ptr + coord );
152
152
double quadratic_term = * quadratic_ptr ;
153
153
154
154
// int *ever_active_ptr_tmp;
@@ -194,13 +194,13 @@ double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n
194
194
if (fabs (old_value - value ) > 1.e-6 * (fabs (value ) + fabs (old_value ))) {
195
195
196
196
delta = value - old_value ;
197
- Sigma_ptr = ((double * ) Sigma + coord * nrow );
197
+ Sigma_ptr_tmp = ((double * ) Sigma_ptr + coord * nrow );
198
198
gradient_ptr_tmp = ((double * ) gradient_ptr );
199
199
200
200
for (icol = 0 ; icol < nrow ; icol ++ ) {
201
- * gradient_ptr_tmp = * gradient_ptr_tmp + delta * (* Sigma_ptr );
201
+ * gradient_ptr_tmp = * gradient_ptr_tmp + delta * (* Sigma_ptr_tmp );
202
202
gradient_ptr_tmp += 1 ;
203
- Sigma_ptr += 1 ;
203
+ Sigma_ptr_tmp += 1 ;
204
204
}
205
205
206
206
theta_ptr = ((double * ) theta + coord );
@@ -212,8 +212,8 @@ double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n
212
212
213
213
}
214
214
215
- int find_one_row_ (double * Sigma , /* A covariance matrix: X^TX/n */
216
- double * Sigma_diag , /* Diagonal entry of covariance matrix */
215
+ int find_one_row_ (double * Sigma_ptr , /* A covariance matrix: X^TX/n */
216
+ double * Sigma_diag_ptr , /* Diagonal entry of covariance matrix */
217
217
double * gradient_ptr , /* Sigma times theta */
218
218
int * ever_active_ptr , /* Ever active set: 0-based */
219
219
int * nactive_ptr , /* Size of ever active set */
@@ -229,7 +229,7 @@ int find_one_row_(double *Sigma, /* A covariance matrix: X^TX/n */
229
229
int iactive = 0 ;
230
230
int * active_ptr ;
231
231
232
- double old_value = objective (Sigma ,
232
+ double old_value = objective (Sigma_ptr ,
233
233
ever_active_ptr ,
234
234
nactive_ptr ,
235
235
nrow ,
@@ -246,8 +246,8 @@ int find_one_row_(double *Sigma, /* A covariance matrix: X^TX/n */
246
246
active_ptr = (int * ) ever_active_ptr ;
247
247
248
248
for (iactive = 0 ; iactive < * nactive_ptr ; iactive ++ ) {
249
- update_one_coord (Sigma ,
250
- Sigma_diag ,
249
+ update_one_coord (Sigma_ptr ,
250
+ Sigma_diag_ptr ,
251
251
gradient_ptr ,
252
252
ever_active_ptr ,
253
253
nactive_ptr ,
@@ -260,6 +260,8 @@ int find_one_row_(double *Sigma, /* A covariance matrix: X^TX/n */
260
260
active_ptr ++ ;
261
261
}
262
262
263
+ // Check KKT
264
+
263
265
if (check_KKT (theta ,
264
266
gradient_ptr ,
265
267
nrow ,
@@ -268,10 +270,12 @@ int find_one_row_(double *Sigma, /* A covariance matrix: X^TX/n */
268
270
break ;
269
271
}
270
272
273
+ // Update all variables
274
+
271
275
for (icoord = 0 ; icoord < nrow ; icoord ++ ) {
272
276
273
- update_one_coord (Sigma ,
274
- Sigma_diag ,
277
+ update_one_coord (Sigma_ptr ,
278
+ Sigma_diag_ptr ,
275
279
gradient_ptr ,
276
280
ever_active_ptr ,
277
281
nactive_ptr ,
@@ -283,6 +287,8 @@ int find_one_row_(double *Sigma, /* A covariance matrix: X^TX/n */
283
287
0 );
284
288
}
285
289
290
+ // Check KKT
291
+
286
292
if (check_KKT (theta ,
287
293
gradient_ptr ,
288
294
nrow ,
@@ -291,7 +297,7 @@ int find_one_row_(double *Sigma, /* A covariance matrix: X^TX/n */
291
297
break ;
292
298
}
293
299
294
- new_value = objective (Sigma ,
300
+ new_value = objective (Sigma_ptr ,
295
301
ever_active_ptr ,
296
302
nactive_ptr ,
297
303
nrow ,
0 commit comments