@Override
public Result doMeasureUser(TestUser user, Context context) {
int tp = 0;
int fp = 0;
LongSet items = queryItems.select(user);
List<ScoredId> recs = user.getRecommendations(listSize, candidates, exclude);
if (recs == null) {
return null;
}
for(ScoredId s : recs) {
if(items.contains(s.getId())) {
tp += 1;
} else {
fp += 1;
}
}
int fn = items.size() - tp;
if (items.size() > 0 && recs.size() > 0) {
// if both the items set and recommendations are non-empty (no division by 0).
double precision = (double) tp/(tp+fp);
double recall = (double) tp/(tp+fn);
context.addUser(precision, recall);
return new Result(precision, recall);