SVDRecommender extends AbstractRecommender { @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); PreferenceArray preferencesFromUser = getDataModel().getPreferencesFromUser(userID); FastIDSet possibleItemIDs = getAllOtherItems(userID, preferencesFromUser, includeKnownItems); List<RecommendedItem> topItems = TopItems.getTopItems(howMany, possibleItemIDs.iterator(), rescorer, new Estimator(userID)); log.debug("Recommendations are: {}", topItems); return topItems; } SVDRecommender(DataModel dataModel, Factorizer factorizer);  SVDRecommender(DataModel dataModel, Factorizer factorizer, CandidateItemsStrategy candidateItemsStrategy);  SVDRecommender(DataModel dataModel, Factorizer factorizer, PersistenceStrategy persistenceStrategy);  SVDRecommender(DataModel dataModel, Factorizer factorizer, CandidateItemsStrategy candidateItemsStrategy,
      PersistenceStrategy persistenceStrategy); @Override List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems); @Override float estimatePreference(long userID, long itemID); @Override void refresh(Collection<Refreshable> alreadyRefreshed);  }
@Test public void recommend() throws Exception { DataModel dataModel = EasyMock.createMock(DataModel.class); PreferenceArray preferencesFromUser = EasyMock.createMock(PreferenceArray.class); CandidateItemsStrategy candidateItemsStrategy = EasyMock.createMock(CandidateItemsStrategy.class); Factorizer factorizer = EasyMock.createMock(Factorizer.class); Factorization factorization = EasyMock.createMock(Factorization.class); FastIDSet candidateItems = new FastIDSet(); candidateItems.add(5L); candidateItems.add(3L); EasyMock.expect(factorizer.factorize()).andReturn(factorization); EasyMock.expect(dataModel.getPreferencesFromUser(1L)).andReturn(preferencesFromUser); EasyMock.expect(candidateItemsStrategy.getCandidateItems(1L, preferencesFromUser, dataModel, false)) .andReturn(candidateItems); EasyMock.expect(factorization.getUserFeatures(1L)).andReturn(new double[] { 0.4, 2 }); EasyMock.expect(factorization.getItemFeatures(5L)).andReturn(new double[] { 1, 0.3 }); EasyMock.expect(factorization.getUserFeatures(1L)).andReturn(new double[] { 0.4, 2 }); EasyMock.expect(factorization.getItemFeatures(3L)).andReturn(new double[] { 2, 0.6 }); EasyMock.replay(dataModel, candidateItemsStrategy, factorizer, factorization); SVDRecommender svdRecommender = new SVDRecommender(dataModel, factorizer, candidateItemsStrategy); List<RecommendedItem> recommendedItems = svdRecommender.recommend(1L, 5); assertEquals(2, recommendedItems.size()); assertEquals(3L, recommendedItems.get(0).getItemID()); assertEquals(2.0f, recommendedItems.get(0).getValue(), EPSILON); assertEquals(5L, recommendedItems.get(1).getItemID()); assertEquals(1.0f, recommendedItems.get(1).getValue(), EPSILON); EasyMock.verify(dataModel, candidateItemsStrategy, factorizer, factorization); }