Skip to content

Commit 6238a92

Browse files
WIP: working on wide X QP
1 parent 86a92fd commit 6238a92

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

selectiveInference/src/quadratic_program_wide.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// Throughout X is a design matrix
1515

1616
double objective_wide(double *X_ptr, /* A design matrix */
17+
double *X_theta_ptr, /* Fitted values */
1718
double *linear_func_ptr, /* Linear term in objective */
1819
int *ever_active_ptr, /* Ever active set: 0-based */
1920
int *nactive_ptr, /* Size of ever active set */
@@ -24,7 +25,7 @@ double objective_wide(double *X_ptr, /* A design matrix */
2425
{
2526
int irow, icol;
2627
double value = 0;
27-
double *X_ptr_tmp = X_ptr;
28+
double *X_theta_ptr_tmp = X_theta_ptr;
2829
double *linear_func_ptr_tmp = linear_func_ptr;
2930
double *theta_row_ptr, *theta_col_ptr;
3031
int *active_row_ptr, *active_col_ptr;
@@ -34,29 +35,32 @@ double objective_wide(double *X_ptr, /* A design matrix */
3435
theta_row_ptr = theta;
3536
theta_col_ptr = theta;
3637

37-
for (irow=0; irow<nactive; irow++) {
38+
double entry = 0; // An entry of X\theta
3839

39-
active_row_ptr = ((int *) ever_active_ptr + irow);
40-
active_row = *active_row_ptr - 1; // Ever-active is 1-based
41-
theta_row_ptr = ((double *) theta + active_row);
40+
// The term \|X\theta\|^2_2/nrow
4241

43-
for (icol=0; icol<nactive; icol++) {
44-
45-
active_col_ptr = ((int *) ever_active_ptr + icol);
46-
active_col = *active_col_ptr - 1; // Ever-active is 1-based
47-
theta_col_ptr = ((double *) theta + active_col);
42+
for (irow=0; irow<nrow; irow++) {
4843

49-
X_ptr_tmp = ((double *) X_ptr + nrow * active_col + active_row); // Matrices are column-major order
44+
X_theta_ptr = ((double *) X_theta_ptr + irow);
45+
value += (*(X_theta_ptr)) * (*(X_theta_ptr));
5046

51-
value += 0.5 * (*X_ptr_tmp) * (*theta_row_ptr) * (*theta_col_ptr);
52-
}
53-
value += bound * fabs((*theta_row_ptr)); // the \ell_1 term
47+
}
48+
49+
for (irow=0; irow<nactive; irow++) {
5450

5551
// The linear term in the objective
5652

53+
active_row_ptr = ((int *) ever_active_ptr + irow);
54+
active_row = *active_row_ptr - 1; // Ever-active is 1-based
55+
theta_row_ptr = ((double *) theta + active_row);
56+
5757
linear_func_ptr_tmp = ((double *) linear_func_ptr + active_row);
5858
value += (*linear_func_ptr_tmp) * (*theta_row_ptr);
5959

60+
// The \ell_1 term
61+
62+
value += bound * fabs((*theta_row_ptr));
63+
6064
}
6165

6266
return(value);

0 commit comments

Comments
 (0)