89 const std::vector<std::vector<
Matrix<T>>>& R) {
90 if (lambda.empty())
throw InputError(
"cache_gamma_lp: no user streams");
91 const std::size_t u = lambda.size();
92 const std::size_t n = lambda[0].rows();
93 if (lambda[0].cols() == 0)
throw InputError(
"cache_gamma_lp: empty lambda");
94 const std::size_t h = lambda[0].cols() - 1;
95 if (R.size() != u)
throw InputError(
"cache_gamma_lp: R and lambda disagree on the user count");
96 for (std::size_t v = 0; v < u; ++v)
98 throw InputError(
"cache_gamma_lp: R and lambda disagree on the item count");
104 for (std::size_t i = 0; i < n; ++i) {
107 Matrix<T> Rvi(R[0][i].rows(), R[0][i].cols(), zero);
108 for (std::size_t v = 0; v < u; ++v)
109 for (std::size_t a = 0; a < Rvi.
rows(); ++a)
110 for (std::size_t b = 0; b < Rvi.
cols(); ++b) Rvi(a, b) += R[v][i](a, b);
112 for (std::size_t l = 0; l < h; ++l) {
113 std::vector<std::size_t> path;
114 path.push_back(l + 1);
115 int pr = detail::cache_parent(Rvi, l + 1);
117 path.insert(path.begin(),
static_cast<std::size_t
>(pr));
118 pr = detail::cache_parent(Rvi,
static_cast<std::size_t
>(pr));
122 for (std::size_t li = 1; li < path.size(); ++li) {
123 const std::size_t a = path[li - 1];
124 const std::size_t b = path[li];
126 for (std::size_t v = 0; v < u; ++v)
127 for (std::size_t t = 0; t <= a; ++t) y += lambda[v](i, t) * R[v][i](t, b);
136 Matrix<T> Rtot(R[0][0].rows(), R[0][0].cols(), zero);
137 for (std::size_t v = 0; v < u; ++v)
138 for (std::size_t a = 0; a < Rtot.
rows(); ++a)
139 for (std::size_t b = 0; b < Rtot.
cols(); ++b) Rtot(a, b) += R[v][0](a, b);
140 std::vector<int> parent(h, -1);
141 for (std::size_t l = 0; l < h; ++l) {
142 const int pr = detail::cache_parent(Rtot, l + 1);
143 parent[l] = (pr < 0) ? -1 : (pr - 1);