public void score(long user, @Nonnull MutableSparseVector scores) {
UserHistory<Rating> history = dao.getEventsForUser(user, Rating.class);
if (history == null) {
history = History.forUser(user);
}
SparseVector ratings = Ratings.userRatingVector(history);
AVector uprefs = model.getUserVector(user);
if (uprefs == null) {
if (ratings.isEmpty()) {
// no real work to do.
return;
}
uprefs = model.getAverageUserVector();
}
MutableSparseVector estimates = initialEstimates(user, ratings, scores.keyDomain());
// propagate estimates to the output scores
scores.set(estimates);
if (!ratings.isEmpty() && rule != null) {
AVector updated = Vector.create(uprefs);
for (int f = 0; f < featureCount; f++) {
trainUserFeature(user, updated, ratings, estimates, f);
}
uprefs = updated;