@Override public ResultList recommendRelatedItemsWithDetails(Set<Long> basket, int n, @Nullable Set<Long> candidates, @Nullable Set<Long> exclude) { return recommendRelatedItems(basket, n, candidates, exclude) .stream() .map(i -> Results.create(i, statistics.getInteractionCount(i))) .collect(Results.listCollector()); }
@Override protected ResultList recommendWithDetails(long user, int n, @Nullable LongSet candidates, @Nullable LongSet exclude) { return recommend(user, n, candidates, exclude) .stream() .map(i -> Results.create(i, statistics.getInteractionCount(i))) .collect(Results.listCollector()); } }
@Inject public PopularityRankItemScorer(final InteractionStatistics stats) { statistics = stats; long[] items = stats.getKnownItems().toLongArray(); LongArrays.quickSort(items, (l1, l2) -> Integer.compare(stats.getInteractionCount(l2), stats.getInteractionCount(l1))); Long2IntMap ranks = LongUtils.itemRanks(LongArrayList.wrap(items)); SortedKeyIndex keys = SortedKeyIndex.fromCollection(ranks.keySet()); int n = keys.size(); double[] values = new double[n]; for (int i = 0; i < n; i++) { values[i] = 1.0 - ranks.get(keys.getKey(i)) / ((double) n); } rankScores = Long2DoubleSortedArrayMap.wrap(keys, values); }
@Override public int compare(long l1, long l2) { return Integer.compare(stats.getInteractionCount(l2), stats.getInteractionCount(l1)); } });
@Override public ResultList recommendRelatedItemsWithDetails(Set<Long> basket, int n, @Nullable Set<Long> candidates, @Nullable Set<Long> exclude) { return recommendRelatedItems(basket, n, candidates, exclude) .stream() .map(i -> Results.create(i, statistics.getInteractionCount(i))) .collect(Results.listCollector()); }
@Override protected ResultList recommendWithDetails(long user, int n, @Nullable LongSet candidates, @Nullable LongSet exclude) { return recommend(user, n, candidates, exclude) .stream() .map(i -> Results.create(i, statistics.getInteractionCount(i))) .collect(Results.listCollector()); } }