@@ -149,22 +149,28 @@ T als_implicit(const dMappedCSC& Conf, arma::Mat<T>& X, arma::Mat<T>& Y,
149
149
// C = 1 (so we omit multiplication on eye matrix)
150
150
// rhs = X * eye * (0 - x_biases) = -X * x_biases
151
151
rhs_init *= -x_biases;
152
- }
153
-
154
- else {
152
+ } else {
155
153
rhs_init = - (drop_row<T>(X, is_x_bias_last_row) * (x_biases + global_bias));
156
154
}
157
- }
158
-
159
- else if (global_bias) {
155
+ } else if (global_bias) {
160
156
rhs_init = arma::Mat<T>(&global_bias_base[0 ], rank - (int )with_biases, 1 , false , true );
161
157
}
162
158
163
159
164
160
double loss = 0 ;
165
161
size_t nc = Conf.n_cols ;
166
162
#ifdef _OPENMP
167
- #pragma omp parallel for num_threads(n_threads) schedule(dynamic, GRAIN_SIZE) reduction(+:loss)
163
+ #pragma omp parallel num_threads(n_threads)
164
+ #endif
165
+ {
166
+ arma::Mat<T> X_nnz;
167
+ arma::Mat<T> X_nnz_t;
168
+ arma::Col<T> init;
169
+ arma::Col<T> Y_new;
170
+ arma::Mat<T> rhs;
171
+
172
+ #ifdef _OPENMP
173
+ #pragma omp for schedule(dynamic) reduction(+:loss)
168
174
#endif
169
175
for (size_t i = 0 ; i < nc; i++) {
170
176
arma::uword p1 = Conf.col_ptrs [i];
@@ -175,32 +181,32 @@ T als_implicit(const dMappedCSC& Conf, arma::Mat<T>& X, arma::Mat<T>& Y,
175
181
const arma::uvec idx = arma::uvec (&Conf.row_indices [p1], p2 - p1, false , true );
176
182
arma::Col<T> confidence =
177
183
arma::conv_to<arma::Col<T> >::from (arma::vec (&Conf.values [p1], p2 - p1));
178
- arma::Mat<T> X_nnz = X.cols (idx);
179
- arma::Col<T> init = Y.col (i);
184
+ X_nnz = X.cols (idx);
180
185
// if is_x_bias_last_row == true
181
186
// X_nnz = [1, ...]
182
187
// if is_x_bias_last_row == false
183
188
// X_nnz = [..., 1]
184
189
if (with_biases) {
185
190
X_nnz = drop_row<T>(X_nnz, is_x_bias_last_row);
186
- init = drop_row<T>(init, !is_x_bias_last_row);
191
+ // init = drop_row<T>(init, !is_x_bias_last_row);
187
192
}
188
- arma::Col<T> Y_new;
189
193
190
194
if (solver == CONJUGATE_GRADIENT) {
195
+ init = Y.col (i);
191
196
if (!with_biases && !global_bias)
192
197
Y_new = cg_solver_implicit<T>(X_nnz, confidence, init, cg_steps, XtX);
193
- else if (with_biases)
198
+ else if (with_biases) {
199
+ init = drop_row<T>(init, !is_x_bias_last_row);
194
200
Y_new = cg_solver_implicit_user_item_bias<T>(X_nnz, confidence, init, cg_steps, XtX,
195
201
rhs_init, x_biases (idx), global_bias);
196
- else
202
+ } else {
197
203
Y_new = cg_solver_implicit_global_bias<T>(X_nnz, confidence, init, cg_steps, XtX,
198
204
rhs_init, global_bias);
199
-
205
+ }
200
206
} else {
201
207
const arma::Mat<T> lhs =
202
- XtX + X_nnz.each_row () % (confidence.t () - 1 ) * X_nnz.t ();
203
- arma::Mat<T> rhs;
208
+ XtX + X_nnz.each_row () % (confidence.t () - 1 ) * X_nnz.t ();
209
+
204
210
if (with_biases) {
205
211
// now we need to update rhs with rhs_init and take into account
206
212
// items with interactions (p=1)
@@ -227,7 +233,7 @@ T als_implicit(const dMappedCSC& Conf, arma::Mat<T>& X, arma::Mat<T>& Y,
227
233
if (solver == SEQ_COORDINATE_WISE_NNLS) {
228
234
Y_new = c_nnls<T>(lhs, rhs, init, SCD_MAX_ITER, SCD_TOL);
229
235
} else { // CHOLESKY
230
- Y_new = solve (lhs, rhs, arma::solve_opts::fast);
236
+ Y_new = solve (lhs, rhs, arma::solve_opts::fast + arma::solve_opts::likely_sympd );
231
237
}
232
238
}
233
239
@@ -276,7 +282,7 @@ T als_implicit(const dMappedCSC& Conf, arma::Mat<T>& X, arma::Mat<T>& Y,
276
282
}
277
283
}
278
284
}
279
-
285
+ }
280
286
if (lambda > 0 ) {
281
287
if (with_biases) {
282
288
// lambda applied to all learned parameters:
0 commit comments