1
1
#include <math.h> // for fabs
2
2
3
- // Find an approximate row of \hat{Sigma }^{-1}
3
+ // Find an approximate row of \hat{nndef }^{-1}
4
4
5
5
// Solves a dual version of problem (4) of https://arxiv.org/pdf/1306.3171.pdf
6
6
11
11
// Therefore we don't have to negate the answer to get theta.
12
12
// Update one coordinate
13
13
14
- double objective_qp (double * Sigma_ptr , /* A covariance matrix: X^TX/n */
14
+ double objective_qp (double * nndef_ptr , /* A non-negative definite matrix */
15
15
double * linear_func_ptr , /* Linear term in objective */
16
16
int * ever_active_ptr , /* Ever active set: 0-based */
17
17
int * nactive_ptr , /* Size of ever active set */
18
- int nrow , /* how many rows in Sigma */
18
+ int nrow , /* how many rows in nndef */
19
19
double bound , /* Lagrange multipler for \ell_1 */
20
20
double * theta ) /* current value */
21
21
{
22
22
int irow , icol ;
23
23
double value = 0 ;
24
- double * Sigma_ptr_tmp = Sigma_ptr ;
24
+ double * nndef_ptr_tmp = nndef_ptr ;
25
25
double * linear_func_ptr_tmp = linear_func_ptr ;
26
26
double * theta_row_ptr , * theta_col_ptr ;
27
27
int * active_row_ptr , * active_col_ptr ;
@@ -43,9 +43,9 @@ double objective_qp(double *Sigma_ptr, /* A covariance matrix: X^TX/n */
43
43
active_col = * active_col_ptr - 1 ; // Ever-active is 1-based
44
44
theta_col_ptr = ((double * ) theta + active_col );
45
45
46
- Sigma_ptr_tmp = ((double * ) Sigma_ptr + nrow * active_col + active_row ); // Matrices are column-major order
46
+ nndef_ptr_tmp = ((double * ) nndef_ptr + nrow * active_col + active_row ); // Matrices are column-major order
47
47
48
- value += 0.5 * (* Sigma_ptr_tmp ) * (* theta_row_ptr ) * (* theta_col_ptr );
48
+ value += 0.5 * (* nndef_ptr_tmp ) * (* theta_row_ptr ) * (* theta_col_ptr );
49
49
}
50
50
value += bound * fabs ((* theta_row_ptr )); // the \ell_1 term
51
51
@@ -91,8 +91,8 @@ int update_ever_active_qp(int coord,
91
91
}
92
92
93
93
int check_KKT_qp (double * theta , /* current theta */
94
- double * gradient_ptr , /* Sigma times theta */
95
- int nrow , /* how many rows in Sigma */
94
+ double * gradient_ptr , /* nndef times theta + linear_func */
95
+ int nrow , /* how many rows in nndef */
96
96
double bound , /* Lagrange multipler for \ell_1 */
97
97
double tol ) /* precision for checking KKT conditions */
98
98
{
@@ -128,13 +128,13 @@ int check_KKT_qp(double *theta, /* current theta */
128
128
return (1 );
129
129
}
130
130
131
- double update_one_coord_qp (double * Sigma_ptr , /* A covariance matrix: X^TX/n */
131
+ double update_one_coord_qp (double * nndef_ptr , /* A non-negative definite matrix */
132
132
double * linear_func_ptr , /* Linear term in objective */
133
- double * Sigma_diag_ptr , /* Diagonal entries of Sigma */
134
- double * gradient_ptr , /* Sigma times theta */
133
+ double * nndef_diag_ptr , /* Diagonal of nndef */
134
+ double * gradient_ptr , /* nndef times theta + linear_func */
135
135
int * ever_active_ptr , /* Ever active set: 1-based */
136
136
int * nactive_ptr , /* Size of ever active set */
137
- int nrow , /* How many rows in Sigma */
137
+ int nrow , /* How many rows in nndef */
138
138
double bound , /* feasibility parameter */
139
139
double * theta , /* current value */
140
140
int coord , /* which coordinate to update: 0-based */
@@ -145,12 +145,12 @@ double update_one_coord_qp(double *Sigma_ptr, /* A covariance matrix:
145
145
double linear_term = 0 ;
146
146
double value = 0 ;
147
147
double old_value ;
148
- double * Sigma_ptr_tmp ;
148
+ double * nndef_ptr_tmp ;
149
149
double * gradient_ptr_tmp ;
150
150
double * theta_ptr ;
151
151
int icol = 0 ;
152
152
153
- double * quadratic_ptr = ((double * ) Sigma_diag_ptr + coord );
153
+ double * quadratic_ptr = ((double * ) nndef_diag_ptr + coord );
154
154
double quadratic_term = * quadratic_ptr ;
155
155
156
156
gradient_ptr_tmp = ((double * ) gradient_ptr + coord );
@@ -160,7 +160,7 @@ double update_one_coord_qp(double *Sigma_ptr, /* A covariance matrix:
160
160
old_value = * theta_ptr ;
161
161
162
162
// The coord entry of gradient_ptr term has a diagonal term in it:
163
- // Sigma [coord, coord] * theta[coord]
163
+ // nndef [coord, coord] * theta[coord]
164
164
// This removes it.
165
165
166
166
linear_term -= quadratic_term * old_value ;
@@ -191,13 +191,13 @@ double update_one_coord_qp(double *Sigma_ptr, /* A covariance matrix:
191
191
if (fabs (old_value - value ) > 1.e-6 * (fabs (value ) + fabs (old_value ))) {
192
192
193
193
delta = value - old_value ;
194
- Sigma_ptr_tmp = ((double * ) Sigma_ptr + coord * nrow );
194
+ nndef_ptr_tmp = ((double * ) nndef_ptr + coord * nrow );
195
195
gradient_ptr_tmp = ((double * ) gradient_ptr );
196
196
197
197
for (icol = 0 ; icol < nrow ; icol ++ ) {
198
- * gradient_ptr_tmp = * gradient_ptr_tmp + delta * (* Sigma_ptr_tmp );
198
+ * gradient_ptr_tmp = * gradient_ptr_tmp + delta * (* nndef_ptr_tmp );
199
199
gradient_ptr_tmp += 1 ;
200
- Sigma_ptr_tmp += 1 ;
200
+ nndef_ptr_tmp += 1 ;
201
201
}
202
202
203
203
theta_ptr = ((double * ) theta + coord );
@@ -209,13 +209,13 @@ double update_one_coord_qp(double *Sigma_ptr, /* A covariance matrix:
209
209
210
210
}
211
211
212
- int solve_qp (double * Sigma_ptr , /* A covariance matrix: X^TX/n */
212
+ int solve_qp (double * nndef_ptr , /* A non-negative definite matrix */
213
213
double * linear_func_ptr , /* Linear term in objective */
214
- double * Sigma_diag_ptr , /* Diagonal entry of covariance matrix */
215
- double * gradient_ptr , /* Sigma times theta */
214
+ double * nndef_diag_ptr , /* Diagonal of nndef */
215
+ double * gradient_ptr , /* nndef times theta */
216
216
int * ever_active_ptr , /* Ever active set: 1-based */
217
217
int * nactive_ptr , /* Size of ever active set */
218
- int nrow , /* How many rows in Sigma */
218
+ int nrow , /* How many rows in nndef */
219
219
double bound , /* feasibility parameter */
220
220
double * theta , /* current value */
221
221
int maxiter , /* max number of iterations */
@@ -235,7 +235,7 @@ int solve_qp(double *Sigma_ptr, /* A covariance matrix: X^TX/n */
235
235
236
236
if (check_objective ) {
237
237
238
- old_value = objective_qp (Sigma_ptr ,
238
+ old_value = objective_qp (nndef_ptr ,
239
239
linear_func_ptr ,
240
240
ever_active_ptr ,
241
241
nactive_ptr ,
@@ -253,9 +253,9 @@ int solve_qp(double *Sigma_ptr, /* A covariance matrix: X^TX/n */
253
253
active_ptr = (int * ) ever_active_ptr ;
254
254
255
255
for (iactive = 0 ; iactive < * nactive_ptr ; iactive ++ ) {
256
- update_one_coord_qp (Sigma_ptr ,
256
+ update_one_coord_qp (nndef_ptr ,
257
257
linear_func_ptr ,
258
- Sigma_diag_ptr ,
258
+ nndef_diag_ptr ,
259
259
gradient_ptr ,
260
260
ever_active_ptr ,
261
261
nactive_ptr ,
@@ -281,9 +281,9 @@ int solve_qp(double *Sigma_ptr, /* A covariance matrix: X^TX/n */
281
281
282
282
for (icoord = 0 ; icoord < nrow ; icoord ++ ) {
283
283
284
- update_one_coord_qp (Sigma_ptr ,
284
+ update_one_coord_qp (nndef_ptr ,
285
285
linear_func_ptr ,
286
- Sigma_diag_ptr ,
286
+ nndef_diag_ptr ,
287
287
gradient_ptr ,
288
288
ever_active_ptr ,
289
289
nactive_ptr ,
@@ -313,7 +313,7 @@ int solve_qp(double *Sigma_ptr, /* A covariance matrix: X^TX/n */
313
313
// Check relative decrease of objective
314
314
315
315
if (check_objective ) {
316
- new_value = objective_qp (Sigma_ptr ,
316
+ new_value = objective_qp (nndef_ptr ,
317
317
linear_func_ptr ,
318
318
ever_active_ptr ,
319
319
nactive_ptr ,
0 commit comments