@Nonnull private Long2DoubleAccumulator newAccumulator() { Long2DoubleAccumulator accum; if (modelSize <= 0) { accum = new UnlimitedLong2DoubleAccumulator(); } else { accum = new TopNLong2DoubleAccumulator(modelSize); } return accum; }
@Before public void createAccumulator() { accum = new UnlimitedLong2DoubleAccumulator(); }
/** * Implement recommendation by calling {@link ItemScorer#score(long, Collection)} and sorting * the results by score. This method uses {@link #getDefaultExcludes(long)} to get the default * exclude set for the user, if none is provided. */ @Override protected List<Long> recommend(long user, int n, LongSet candidates, LongSet exclude) { candidates = getEffectiveCandidates(user, candidates, exclude); logger.debug("Computing {} recommendations for user {} from {} candidates", n, user, candidates.size()); Map<Long, Double> scores = scorer.score(user, candidates); Long2DoubleAccumulator accum; if (n >= 0) { accum = new TopNLong2DoubleAccumulator(n); } else { accum = new UnlimitedLong2DoubleAccumulator(); } Long2DoubleMap map = LongUtils.asLong2DoubleMap(scores); for (Long2DoubleMap.Entry e: Vectors.fastEntries(map)) { accum.put(e.getLongKey(), e.getDoubleValue()); } return accum.finishList(); }
/** * Score a single item into an accumulator. * @param scores The reference scores. * @param item The item to score. * @param accum The accumulator. */ protected void scoreItem(Long2DoubleMap scores, long item, ItemItemScoreAccumulator accum) { Long2DoubleMap allNeighbors = model.getNeighbors(item); Long2DoubleAccumulator acc; if (neighborhoodSize > 0) { // FIXME Abstract accumulator selection logic acc = new TopNLong2DoubleAccumulator(neighborhoodSize); } else { acc = new UnlimitedLong2DoubleAccumulator(); } for (Long2DoubleMap.Entry nbr: allNeighbors.long2DoubleEntrySet()) { if (scores.containsKey(nbr.getLongKey())) { acc.put(nbr.getLongKey(), nbr.getDoubleValue()); } } Long2DoubleMap neighborhood = acc.finishMap(); scorer.score(item, neighborhood, scores, accum); } }
@Nonnull private Long2DoubleAccumulator newAccumulator() { Long2DoubleAccumulator accum; if (modelSize <= 0) { accum = new UnlimitedLong2DoubleAccumulator(); } else { accum = new TopNLong2DoubleAccumulator(modelSize); } return accum; }
/** * Implement recommendation by calling {@link ItemScorer#score(long, Collection)} and sorting * the results by score. This method uses {@link #getDefaultExcludes(long)} to get the default * exclude set for the user, if none is provided. */ @Override protected List<Long> recommend(long user, int n, LongSet candidates, LongSet exclude) { candidates = getEffectiveCandidates(user, candidates, exclude); logger.debug("Computing {} recommendations for user {} from {} candidates", n, user, candidates.size()); Map<Long, Double> scores = scorer.score(user, candidates); Long2DoubleAccumulator accum; if (n >= 0) { accum = new TopNLong2DoubleAccumulator(n); } else { accum = new UnlimitedLong2DoubleAccumulator(); } Long2DoubleMap map = LongUtils.asLong2DoubleMap(scores); for (Long2DoubleMap.Entry e: Vectors.fastEntries(map)) { accum.put(e.getLongKey(), e.getDoubleValue()); } return accum.finishList(); }
/** * Score a single item into an accumulator. * @param scores The reference scores. * @param item The item to score. * @param accum The accumulator. */ protected void scoreItem(Long2DoubleMap scores, long item, ItemItemScoreAccumulator accum) { Long2DoubleMap allNeighbors = model.getNeighbors(item); Long2DoubleAccumulator acc; if (neighborhoodSize > 0) { // FIXME Abstract accumulator selection logic acc = new TopNLong2DoubleAccumulator(neighborhoodSize); } else { acc = new UnlimitedLong2DoubleAccumulator(); } for (Long2DoubleMap.Entry nbr: allNeighbors.long2DoubleEntrySet()) { if (scores.containsKey(nbr.getLongKey())) { acc.put(nbr.getLongKey(), nbr.getDoubleValue()); } } Long2DoubleMap neighborhood = acc.finishMap(); scorer.score(item, neighborhood, scores, accum); } }