@Test public void estimatePreference() throws Exception { DataModel dataModel = EasyMock.createMock(DataModel.class); Factorizer factorizer = EasyMock.createMock(Factorizer.class); Factorization factorization = EasyMock.createMock(Factorization.class); EasyMock.expect(factorizer.factorize()).andReturn(factorization); EasyMock.expect(factorization.getUserFeatures(1L)).andReturn(new double[] { 0.4, 2 }); EasyMock.expect(factorization.getItemFeatures(5L)).andReturn(new double[] { 1, 0.3 }); EasyMock.replay(dataModel, factorizer, factorization); SVDRecommender svdRecommender = new SVDRecommender(dataModel, factorizer); float estimate = svdRecommender.estimatePreference(1L, 5L); assertEquals(1, estimate, EPSILON); EasyMock.verify(dataModel, factorizer, factorization); }
@Override public float estimatePreference(long userID, long itemID) throws TasteException { double[] userFeatures = factorization.getUserFeatures(userID); double[] itemFeatures = factorization.getItemFeatures(itemID); double estimate = 0; for (int feature = 0; feature < userFeatures.length; feature++) { estimate += userFeatures[feature] * itemFeatures[feature]; } return (float) estimate; }
SVDRecommender extends AbstractRecommender { @Override public float estimatePreference(long userID, long itemID) throws TasteException { double[] userFeatures = factorization.getUserFeatures(userID); double[] itemFeatures = factorization.getItemFeatures(itemID); double estimate = 0; for (int feature = 0; feature < userFeatures.length; feature++) { estimate += userFeatures[feature] * itemFeatures[feature]; } return (float) estimate; } }
SVDRecommender extends AbstractRecommender { @Override public float estimatePreference(long userID, long itemID) throws TasteException { double[] userFeatures = factorization.getUserFeatures(userID); double[] itemFeatures = factorization.getItemFeatures(itemID); double estimate = 0; for (int feature = 0; feature < userFeatures.length; feature++) { estimate += userFeatures[feature] * itemFeatures[feature]; } return (float) estimate; } 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); }
SVDRecommender extends AbstractRecommender { @Override public float estimatePreference(long userID, long itemID) throws TasteException { double[] userFeatures = factorization.getUserFeatures(userID); double[] itemFeatures = factorization.getItemFeatures(itemID); double estimate = 0; for (int feature = 0; feature < userFeatures.length; feature++) { estimate += userFeatures[feature] * itemFeatures[feature]; } return (float) estimate; } 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); }
SVDRecommender extends AbstractRecommender { @Override public float estimatePreference(long userID, long itemID) throws TasteException { double[] userFeatures = factorization.getUserFeatures(userID); double[] itemFeatures = factorization.getItemFeatures(itemID); double estimate = 0; for (int feature = 0; feature < userFeatures.length; feature++) { estimate += userFeatures[feature] * itemFeatures[feature]; } return (float) estimate; } 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);  }