@@ -27,15 +27,16 @@ double objective(double *Sigma, /* A covariance matrix: X^TX/n */
27
27
28
28
for (irow = 0 ; irow < nrow ; irow ++ ) {
29
29
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
+ }
34
36
}
35
37
if (irow == row ) {
36
38
value -= (* theta_row_ptr ); // the elementary basis vector term
37
39
}
38
-
39
40
value = value + bound * fabs ((* theta_row_ptr )); // the \ell_1 term
40
41
theta_row_ptr ++ ;
41
42
}
@@ -108,39 +109,11 @@ double update_one_coord(double *Sigma, /* A covariance matrix: X^TX/n
108
109
Sigma_ptr += 1 ;
109
110
}
110
111
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 ;
132
114
133
115
}
134
116
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
-
144
117
return (value );
145
118
146
119
}
@@ -201,11 +174,10 @@ void find_one_row(double *Sigma, /* A covariance matrix: X^TX/n */
201
174
bound ,
202
175
theta );
203
176
204
- if (((old_value - new_value ) < tol * fabs (new_value )) && (iter > 5 )) {
177
+ if (((old_value - new_value ) < tol * fabs (new_value )) && (iter > 0 )) {
205
178
break ;
206
179
}
207
180
208
- fprintf (stderr , "%f %f value\n" , old_value , new_value );
209
181
old_value = new_value ;
210
182
}
211
183
0 commit comments