public void testHowMany() { IDataModel dataModel = getDataModel( new long[] { 1, 2, 3, 4, 5 }, new Double?[][] { new double?[] { 0.1, 0.2 }, new double?[] { 0.2, 0.3, 0.3, 0.6 }, new double?[] { 0.4, 0.4, 0.5, 0.9 }, new double?[] { 0.1, 0.4, 0.5, 0.8, 0.9, 1.0 }, new double?[] { 0.2, 0.3, 0.6, 0.7, 0.1, 0.2 }, }); IUserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel); IUserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, dataModel); IRecommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity); IList <IRecommendedItem> fewRecommended = recommender.Recommend(1, 2); IList <IRecommendedItem> moreRecommended = recommender.Recommend(1, 4); for (int i = 0; i < fewRecommended.Count; i++) { Assert.AreEqual(fewRecommended[i].GetItemID(), moreRecommended[i].GetItemID()); } recommender.Refresh(null); for (int i = 0; i < fewRecommended.Count; i++) { Assert.AreEqual(fewRecommended[i].GetItemID(), moreRecommended[i].GetItemID()); } }
public void testRescorer() { IDataModel dataModel = getDataModel( new long[] { 1, 2, 3 }, new Double?[][] { new double?[] { 0.1, 0.2 }, new double?[] { 0.2, 0.3, 0.3, 0.6 }, new double?[] { 0.4, 0.5, 0.5, 0.9 }, }); IUserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel); IUserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, dataModel); IRecommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity); IList <IRecommendedItem> originalRecommended = recommender.Recommend(1, 2); IList <IRecommendedItem> rescoredRecommended = recommender.Recommend(1, 2, new ReversingRescorer <long>()); Assert.NotNull(originalRecommended); Assert.NotNull(rescoredRecommended); Assert.AreEqual(2, originalRecommended.Count); Assert.AreEqual(2, rescoredRecommended.Count); Assert.AreEqual(originalRecommended[0].GetItemID(), rescoredRecommended[1].GetItemID()); Assert.AreEqual(originalRecommended[1].GetItemID(), rescoredRecommended[0].GetItemID()); }