@Test public void testBestRating() throws Exception { Recommender recommender = buildRecommender(); List<RecommendedItem> recommended = recommender.recommend(1, 1); assertNotNull(recommended); assertEquals(1, recommended.size()); RecommendedItem firstRecommended = recommended.get(0); assertEquals(2, firstRecommended.getItemID()); assertEquals(0.1f, firstRecommended.getValue(), EPSILON); }
@Override public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems) throws TasteException { Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1"); log.debug("Recommending items for user ID '{}'", userID); long[] theNeighborhood = neighborhood.getUserNeighborhood(userID); if (theNeighborhood.length == 0) { return Collections.emptyList(); } FastIDSet allItemIDs = getAllOtherItems(theNeighborhood, userID, includeKnownItems); TopItems.Estimator<Long> estimator = new Estimator(userID, theNeighborhood); List<RecommendedItem> topItems = TopItems .getTopItems(howMany, allItemIDs.iterator(), rescorer, estimator); log.debug("Recommendations are: {}", topItems); return topItems; }
GenericUserBasedRecommender extends AbstractRecommender implements UserBasedRecommender { @Override public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems) throws TasteException { Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1"); log.debug("Recommending items for user ID '{}'", userID); long[] theNeighborhood = neighborhood.getUserNeighborhood(userID); if (theNeighborhood.length == 0) { return Collections.emptyList(); } FastIDSet allItemIDs = getAllOtherItems(theNeighborhood, userID, includeKnownItems); TopItems.Estimator<Long> estimator = new Estimator(userID, theNeighborhood); List<RecommendedItem> topItems = TopItems .getTopItems(howMany, allItemIDs.iterator(), rescorer, estimator); log.debug("Recommendations are: {}", topItems); return topItems; } }
GenericUserBasedRecommender extends AbstractRecommender implements UserBasedRecommender { @Override public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems) throws TasteException { Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1"); log.debug("Recommending items for user ID '{}'", userID); long[] theNeighborhood = neighborhood.getUserNeighborhood(userID); if (theNeighborhood.length == 0) { return Collections.emptyList(); } FastIDSet allItemIDs = getAllOtherItems(theNeighborhood, userID, includeKnownItems); TopItems.Estimator<Long> estimator = new Estimator(userID, theNeighborhood); List<RecommendedItem> topItems = TopItems .getTopItems(howMany, allItemIDs.iterator(), rescorer, estimator); log.debug("Recommendations are: {}", topItems); return topItems; } GenericUserBasedRecommender(DataModel dataModel,
                                     UserNeighborhood neighborhood,
                                     UserSimilarity similarity); }
GenericUserBasedRecommender extends AbstractRecommender implements UserBasedRecommender { @Override public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems) throws TasteException { Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1"); log.debug("Recommending items for user ID '{}'", userID); long[] theNeighborhood = neighborhood.getUserNeighborhood(userID); if (theNeighborhood.length == 0) { return Collections.emptyList(); } FastIDSet allItemIDs = getAllOtherItems(theNeighborhood, userID, includeKnownItems); TopItems.Estimator<Long> estimator = new Estimator(userID, theNeighborhood); List<RecommendedItem> topItems = TopItems .getTopItems(howMany, allItemIDs.iterator(), rescorer, estimator); log.debug("Recommendations are: {}", topItems); return topItems; } GenericUserBasedRecommender(DataModel dataModel,
                                     UserNeighborhood neighborhood,
                                     UserSimilarity similarity); UserSimilarity getSimilarity(); @Override List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems); @Override float estimatePreference(long userID, long itemID); @Override long[] mostSimilarUserIDs(long userID, int howMany); @Override long[] mostSimilarUserIDs(long userID, int howMany, Rescorer<LongPair> rescorer); @Override void refresh(Collection<Refreshable> alreadyRefreshed); @Override String toString(); }
GenericUserBasedRecommender extends AbstractRecommender implements UserBasedRecommender { @Override public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems) throws TasteException { Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1"); log.debug("Recommending items for user ID '{}'", userID); long[] theNeighborhood = neighborhood.getUserNeighborhood(userID); if (theNeighborhood.length == 0) { return Collections.emptyList(); } FastIDSet allItemIDs = getAllOtherItems(theNeighborhood, userID, includeKnownItems); TopItems.Estimator<Long> estimator = new Estimator(userID, theNeighborhood); List<RecommendedItem> topItems = TopItems .getTopItems(howMany, allItemIDs.iterator(), rescorer, estimator); log.debug("Recommendations are: {}", topItems); return topItems; } GenericUserBasedRecommender(DataModel dataModel,
                                     UserNeighborhood neighborhood,
                                     UserSimilarity similarity); UserSimilarity getSimilarity(); @Override List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems); @Override float estimatePreference(long userID, long itemID); @Override long[] mostSimilarUserIDs(long userID, int howMany); @Override long[] mostSimilarUserIDs(long userID, int howMany, Rescorer<LongPair> rescorer); @Override void refresh(Collection<Refreshable> alreadyRefreshed); @Override String toString();  }