From 66df48a72d1f6105f41f0d54088b5538d0217418 Mon Sep 17 00:00:00 2001 From: david-cortes Date: Wed, 26 May 2021 09:06:13 +0300 Subject: [PATCH] Correction for cases of no observations + biases (#67) --- inst/include/wrmf_implicit.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/inst/include/wrmf_implicit.hpp b/inst/include/wrmf_implicit.hpp index 35b5680..f2841b0 100644 --- a/inst/include/wrmf_implicit.hpp +++ b/inst/include/wrmf_implicit.hpp @@ -171,7 +171,7 @@ T als_implicit(const dMappedCSC& Conf, arma::Mat& X, arma::Mat& Y, arma::uword p2 = Conf.col_ptrs[i + 1]; // catch situation when some columns in matrix are empty, so p1 becomes equal to p2 or // greater than number of columns - if (p1 < p2) { + if (with_biases || global_bias || p1 < p2) { const arma::uvec idx = arma::uvec(&Conf.row_indices[p1], p2 - p1, false, true); arma::Col confidence = arma::conv_to >::from(arma::vec(&Conf.values[p1], p2 - p1)); @@ -248,7 +248,9 @@ T als_implicit(const dMappedCSC& Conf, arma::Mat& X, arma::Mat& Y, Y.unsafe_col(i) = Y_new; } - if (!global_bias && !with_biases) + if (p1 == p2) + loss += lambda * arma::dot(Y_new, Y_new); + else if (!global_bias && !with_biases) loss += dot(square(1 - (Y_new.t() * X_nnz)), confidence) + lambda * arma::dot(Y_new, Y_new); else if (global_bias && !with_biases)