private List <IRecommendedItem> doMostSimilarItems(long[] itemIDs, int howMany, TopItems.IEstimator <long> estimator) { FastIDSet possibleItemIDs = mostSimilarItemsCandidateItemsStrategy.GetCandidateItems(itemIDs, GetDataModel()); return(TopItems.GetTopItems(howMany, possibleItemIDs.GetEnumerator(), null, estimator)); }
public override IList <IRecommendedItem> Recommend(long userID, int howMany, IDRescorer rescorer) { //Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1"); log.Debug("Recommending items for user ID '{}'", userID); IPreferenceArray preferencesFromUser = GetDataModel().GetPreferencesFromUser(userID); FastIDSet possibleItemIDs = GetAllOtherItems(userID, preferencesFromUser); TopItems.IEstimator <long> estimator = new Estimator(this, userID); List <IRecommendedItem> topItems = TopItems.GetTopItems(howMany, possibleItemIDs.GetEnumerator(), rescorer, estimator); log.Debug("Recommendations are: {}", topItems); return(topItems); }
public void testTopItems() { long[] ids = new long[100]; for (int i = 0; i < 100; i++) { ids[i] = i; } var possibleItemIds = ((IEnumerable <long>)ids).GetEnumerator(); TopItems.IEstimator <long> estimator = new TestTopItemsEstimator(); List <IRecommendedItem> topItems = TopItems.GetTopItems(10, possibleItemIds, null, estimator); int gold = 99; foreach (IRecommendedItem topItem in topItems) { Assert.AreEqual(gold, topItem.GetItemID()); Assert.AreEqual(gold--, topItem.GetValue(), 0.01); } }
public List <IRecommendedItem> RecommendedBecause(long userID, long itemID, int howMany) { //Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1"); IDataModel model = GetDataModel(); TopItems.IEstimator <long> estimator = new RecommendedBecauseEstimator(this, userID, itemID); IPreferenceArray prefs = model.GetPreferencesFromUser(userID); int size = prefs.Length(); FastIDSet allUserItems = new FastIDSet(size); for (int i = 0; i < size; i++) { allUserItems.Add(prefs.GetItemID(i)); } allUserItems.Remove(itemID); return(TopItems.GetTopItems(howMany, allUserItems.GetEnumerator(), null, estimator)); }
public void testTopItemsRandom() { long[] ids = new long[100]; for (int i = 0; i < 100; i++) { ids[i] = i; } var possibleItemIds = ((IEnumerable <long>)ids).GetEnumerator(); TopItems.IEstimator <long> estimator = new TestRndTopItemsEstimator(); List <IRecommendedItem> topItems = TopItems.GetTopItems(10, possibleItemIds, null, estimator); Assert.AreEqual(10, topItems.Count); double last = 2.0; foreach (IRecommendedItem topItem in topItems) { Assert.True(topItem.GetValue() <= last); last = topItem.GetItemID(); } }
public override IList <IRecommendedItem> Recommend(long userID, int howMany, IDRescorer rescorer) { //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(new List <IRecommendedItem>()); } FastIDSet allItemIDs = getAllOtherItems(theNeighborhood, userID); TopItems.IEstimator <long> estimator = new Estimator(this, userID, theNeighborhood); List <IRecommendedItem> topItems = TopItems .GetTopItems(howMany, allItemIDs.GetEnumerator(), rescorer, estimator); log.Debug("Recommendations are: {}", topItems); return(topItems); }