SVDRecommender svdRecommender = new SVDRecommender(dataModel, factorizer);
RunningAverage avg = new FullRunningAverage();
Iterator<MatrixSlice> sliceIterator = preferences.iterateAll();
while (sliceIterator.hasNext()) {
MatrixSlice slice = sliceIterator.next();
for (Vector.Element e : slice.vector().all()) {
long userID = slice.index() + 1;
long itemID = e.index() + 1;
if (!Double.isNaN(e.get())) {
double pref = e.get();
double estimate = svdRecommender.estimatePreference(userID, itemID);
double confidence = 1 + alpha * observations.getQuick(slice.index(), e.index());
double err = confidence * (pref - estimate) * (pref - estimate);
avg.addDatum(err);
log.info("Comparing preference of user [{}] towards item [{}], was [{}] with confidence [{}] "
+ "estimate is [{}]", slice.index(), e.index(), pref, confidence, estimate);
}
}
}
double rmse = Math.sqrt(avg.getAverage());
log.info("RMSE: {}", rmse);