예제 #1
0
	    public void TestItemLoad() 
	    {
		    DataModel model = CreateModel();
            ItemCorrelation itemCorrelation = new PearsonCorrelation(model);
            var recommender = new CachingRecommender(new GenericItemBasedRecommender(model, itemCorrelation));
		    DoTestLoad(recommender, 60);
	    }
예제 #2
0
 public void TestFullCorrelation1()
 {
     User user1 = GetUser("test1", 3.0, -2.0);
     User user2 = GetUser("test2", 3.0, -2.0);
     DataModel dataModel = GetDataModel(user1, user2);
     double correlation = new PearsonCorrelation(dataModel).GetUserCorrelation(user1, user2);
     AssertCorrelationEquals(1.0, correlation);
 }
예제 #3
0
 public void testNoCorrelation1Weighted()
 {
     User user1 = GetUser("test1", 3.0, -2.0);
     User user2 = GetUser("test2", -3.0, 2.0);
     DataModel dataModel = GetDataModel(user1, user2);
     double correlation = new PearsonCorrelation(dataModel, true).GetUserCorrelation(user1, user2);
     AssertCorrelationEquals(-1.0, correlation);
 }
예제 #4
0
 public void TestFullCorrelation2()
 {
     User user1 = GetUser("test1", 3.0, 3.0);
     User user2 = GetUser("test2", 3.0, 3.0);
     DataModel dataModel = GetDataModel(user1, user2);
     double correlation = new PearsonCorrelation(dataModel).GetUserCorrelation(user1, user2);
     // Yeah, undefined in this case
     Assert.IsTrue(Double.IsNaN(correlation));
 }
예제 #5
0
	    public void TestUserLoad() 
	    {
		    DataModel model = CreateModel();
		    UserCorrelation userCorrelation = new PearsonCorrelation(model);
		    userCorrelation.PreferenceInferrer = new AveragingPreferenceInferrer(model);
		    UserNeighborhood neighborhood = new NearestNUserNeighborhood(10, userCorrelation, model);
            var recommender =
			    new CachingRecommender(new GenericUserBasedRecommender(model, neighborhood, userCorrelation));
		    DoTestLoad(recommender, 20);
	    }
	    public void TestNoRecommendations() 
	    {
            List<User> users = new List<User>(3);
		    users.Add(GetUser("test1", 0.1));
		    users.Add(GetUser("test2", 0.2, 0.6));
		    users.Add(GetUser("test3", 0.4, 0.9));
		    DataModel dataModel = new GenericDataModel(users);
		    UserCorrelation correlation = new PearsonCorrelation(dataModel);
		    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
		    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
		    IList<RecommendedItem> recommended = recommender.Recommend("test1", 1);		
		    Assert.IsNotNull(recommended);
		    Assert.AreEqual(0, recommended.Count);
	    }
	    public void testHowMany()
	    {
            List<User> users = new List<User>(3);
		    users.Add(GetUser("test1", 0.1, 0.2));
		    users.Add(GetUser("test2", 0.2, 0.3, 0.3, 0.6));
		    users.Add(GetUser("test3", 0.4, 0.4, 0.5, 0.9));
		    users.Add(GetUser("test4", 0.1, 0.4, 0.5, 0.8, 0.9, 1.0));
		    users.Add(GetUser("test5", 0.2, 0.3, 0.6, 0.7, 0.1, 0.2));
            DataModel dataModel = new GenericDataModel(users);
            UserCorrelation correlation = new PearsonCorrelation(dataModel);
            ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
            Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
            IList<RecommendedItem> fewRecommended = recommender.Recommend("test1", 2);
            IList<RecommendedItem> moreRecommended = recommender.Recommend("test1", 4);
		    for (int i = 0; i < fewRecommended.Count; i++) 
            {
			    Assert.AreEqual(fewRecommended[i].Item, moreRecommended[i].Item);
		    }
	    }
 public void TestHowMany()
 {
     List<User> users = new List<User>(3);
     users.Add(GetUser("test1", 0.1, 0.2));
     users.Add(GetUser("test2", 0.2, 0.3, 0.3, 0.6));
     users.Add(GetUser("test3", 0.4, 0.4, 0.5, 0.9));
     users.Add(GetUser("test4", 0.1, 0.4, 0.5, 0.8, 0.9, 1.0));
     users.Add(GetUser("test5", 0.2, 0.3, 0.6, 0.7, 0.1, 0.2));
     DataModel dataModel = new GenericDataModel(users);
     UserCorrelation correlation = new PearsonCorrelation(dataModel);
     UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, correlation, dataModel);
     Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, correlation);
     IList<RecommendedItem> fewRecommended = recommender.Recommend("test1", 2);
     IList<RecommendedItem> moreRecommended = recommender.Recommend("test1", 4);
     for (int i = 0; i < fewRecommended.Count; i++)
     {
         Assert.AreEqual(fewRecommended[i].Item, moreRecommended[i].Item);
     }
 }
	    public void TestRescorer()
	    {
		    List<User> users = new List<User>(3);
		    users.Add(GetUser("test1", 0.1, 0.2));
		    users.Add(GetUser("test2", 0.2, 0.3, 0.3, 0.6));
		    users.Add(GetUser("test3", 0.4, 0.4, 0.5, 0.9));
		    DataModel dataModel = new GenericDataModel(users);
		    UserCorrelation correlation = new PearsonCorrelation(dataModel);
		    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
		    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
		    IList<RecommendedItem> originalRecommended = recommender.Recommend("test1", 2);
		    IList<RecommendedItem> rescoredRecommended =
			    recommender.Recommend("test1", 2, new ReversingRescorer<Item>());
		    Assert.IsNotNull(originalRecommended);
		    Assert.IsNotNull(rescoredRecommended);
		    Assert.AreEqual(2, originalRecommended.Count);
		    Assert.AreEqual(2, rescoredRecommended.Count);
		    Assert.AreEqual(originalRecommended[0].Item, rescoredRecommended[1].Item);
		    Assert.AreEqual(originalRecommended[1].Item, rescoredRecommended[0].Item);
	    }
 public void TestRescorer()
 {
     List<User> users = new List<User>(3);
     users.Add(GetUser("test1", 0.1, 0.2));
     users.Add(GetUser("test2", 0.2, 0.3, 0.3, 0.6));
     users.Add(GetUser("test3", 0.4, 0.4, 0.5, 0.9));
     DataModel dataModel = new GenericDataModel(users);
     UserCorrelation correlation = new PearsonCorrelation(dataModel);
     UserNeighborhood neighborhood = new NearestNUserNeighborhood(1, correlation, dataModel);
     Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, correlation);
     IList<RecommendedItem> originalRecommended = recommender.Recommend("test1", 2);
     IList<RecommendedItem> rescoredRecommended =
        recommender.Recommend("test1", 2, new ReversingRescorer<Item>());
     Assert.IsNotNull(originalRecommended);
     Assert.IsNotNull(rescoredRecommended);
     Assert.AreEqual(2, originalRecommended.Count);
     Assert.AreEqual(2, rescoredRecommended.Count);
     Assert.AreEqual(originalRecommended[0].Item, rescoredRecommended[1].Item);
     Assert.AreEqual(originalRecommended[1].Item, rescoredRecommended[0].Item);
 }
예제 #11
0
 public void TestSimple()
 {
     User user1 = GetUser("test1", 1.0, 2.0, 3.0);
     User user2 = GetUser("test2", 2.0, 5.0, 6.0);
     DataModel dataModel = GetDataModel(user1, user2);
     double correlation = new PearsonCorrelation(dataModel).GetUserCorrelation(user1, user2);
     AssertCorrelationEquals(0.9607689228305227, correlation);
 }
 public void TestIsolatedUser()
 {
     List<User> users = new List<User>(3);
     users.Add(GetUser("test1", 0.1, 0.2));
     users.Add(GetUser("test2", 0.2, 0.3, 0.3, 0.6));
     users.Add(GetUser("test3", 0.4, 0.4, 0.5, 0.9));
     users.Add(GetUser("test4"));
     DataModel dataModel = new GenericDataModel(users);
     UserCorrelation correlation = new PearsonCorrelation(dataModel);
     UserNeighborhood neighborhood = new NearestNUserNeighborhood(3, correlation, dataModel);
     UserBasedRecommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, correlation);
     ICollection<User> mostSimilar = recommender.MostSimilarUsers("test4", 3);
     Assert.IsNotNull(mostSimilar);
     Assert.AreEqual(0, mostSimilar.Count);
 }
	    public void TestEstimatePref() 
        {
		    List<User> users = new List<User>(4);
		    users.Add(GetUser("test1", 0.1, 0.3));
		    users.Add(GetUser("test2", 0.2, 0.3, 0.3));
		    users.Add(GetUser("test3", 0.4, 0.3, 0.5));
		    users.Add(GetUser("test4", 0.7, 0.3, 0.8, 0.9));
            DataModel dataModel = new GenericDataModel(users);
            UserCorrelation correlation = new PearsonCorrelation(dataModel);
            ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
            Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
		    Assert.AreEqual(0.9, recommender.EstimatePreference("test3", "3"));
	    }
예제 #14
0
 public void TestSimpleItem()
 {
     User user1 = GetUser("test1", 1.0, 2.0);
     User user2 = GetUser("test2", 2.0, 5.0);
     User user3 = GetUser("test3", 3.0, 6.0);
     DataModel dataModel = GetDataModel(user1, user2, user3);
     double correlation =
        new PearsonCorrelation(dataModel).GetItemCorrelation(dataModel.GetItem("0"), dataModel.GetItem("1"));
     AssertCorrelationEquals(0.9607689228305227, correlation);
 }
예제 #15
0
 public void TestSimpleItemWeighted()
 {
     User user1 = GetUser("test1", 1.0, 2.0);
     User user2 = GetUser("test2", 2.0, 5.0);
     User user3 = GetUser("test3", 3.0, 6.0);
     DataModel dataModel = GetDataModel(user1, user2, user3);
     ItemCorrelation itemCorrelation = new PearsonCorrelation(dataModel, true);
     double correlation = itemCorrelation.GetItemCorrelation(dataModel.GetItem("0"), dataModel.GetItem("1"));
     AssertCorrelationEquals(0.9901922307076306, correlation);
 }
예제 #16
0
 public void TestNoItemCorrelation3()
 {
     User user1 = GetUser("test1", 90.0, 70.0);
     User user2 = GetUser("test2", 80.0, 80.0);
     User user3 = GetUser("test3", 70.0, 90.0);
     DataModel dataModel = GetDataModel(user1, user2, user3);
     double correlation =
        new PearsonCorrelation(dataModel).GetItemCorrelation(dataModel.GetItem("0"), dataModel.GetItem("1"));
     AssertCorrelationEquals(-1.0, correlation);
 }
예제 #17
0
 public void TestNoItemCorrelation1()
 {
     User user1 = GetUser("test1", 3.0, -3.0);
     User user2 = GetUser("test2", -2.0, 2.0);
     DataModel dataModel = GetDataModel(user1, user2);
     double correlation =
        new PearsonCorrelation(dataModel).GetItemCorrelation(dataModel.GetItem("0"), dataModel.GetItem("1"));
     AssertCorrelationEquals(-1.0, correlation);
 }
예제 #18
0
 public void TestSimpleWeighted()
 {
     User user1 = GetUser("test1", 1.0, 2.0, 3.0);
     User user2 = GetUser("test2", 2.0, 5.0, 6.0);
     DataModel dataModel = GetDataModel(user1, user2);
     double correlation = new PearsonCorrelation(dataModel, true).GetUserCorrelation(user1, user2);
     AssertCorrelationEquals(0.9901922307076306, correlation);
 }
 private static UserBasedRecommender buildRecommender()
 {
     DataModel dataModel = new GenericDataModel(GetMockUsers());
     UserCorrelation correlation = new PearsonCorrelation(dataModel);
     UserNeighborhood neighborhood = new NearestNUserNeighborhood(1, correlation, dataModel);
     return new GenericUserBasedRecommender(dataModel, neighborhood, correlation);
 }
예제 #20
0
 public void testNoCorrelation2()
 {
     Preference pref1 = new GenericPreference(null, new GenericItem<String>("1"), 1.0);
     GenericUser<String> user1 = new GenericUser<String>("test1", ScalarToList<Preference>(pref1));
     Preference pref2 = new GenericPreference(null, new GenericItem<String>("2"), 1.0);
     GenericUser<String> user2 = new GenericUser<String>("test2", ScalarToList<Preference>(pref2));
     DataModel dataModel = GetDataModel(user1, user2);
     double correlation = new PearsonCorrelation(dataModel).GetUserCorrelation(user1, user2);
     Assert.IsTrue(Double.IsNaN(correlation));
 }
예제 #21
0
 public void testNoCorrelation3()
 {
     User user1 = GetUser("test1", 90.0, 80.0, 70.0);
     User user2 = GetUser("test2", 70.0, 80.0, 90.0);
     DataModel dataModel = GetDataModel(user1, user2);
     double correlation = new PearsonCorrelation(dataModel).GetUserCorrelation(user1, user2);
     AssertCorrelationEquals(-1.0, correlation);
 }
	    public void TestBestRating()
	    {
		    List<User> users = new List<User>(4);
		    users.Add(GetUser("test1", 0.1, 0.3));
		    users.Add(GetUser("test2", 0.2, 0.3, 0.3));
		    users.Add(GetUser("test3", 0.4, 0.3, 0.5));
		    users.Add(GetUser("test4", 0.7, 0.3, 0.8));
		    DataModel dataModel = new GenericDataModel(users);
		    UserCorrelation correlation = new PearsonCorrelation(dataModel);
		    ClusterSimilarity similarity = new FarthestNeighborClusterSimilarity(correlation);
		    Recommender recommender = new TreeClusteringRecommender(dataModel, similarity, 2);
		    IList<RecommendedItem> recommended = recommender.Recommend("test1", 1);
		    Assert.IsNotNull(recommended);
		    Assert.AreEqual(1, recommended.Count);
		    RecommendedItem firstRecommended = recommended[0];
		    // item one should be recommended because it has a greater rating/score
		    Assert.AreEqual(new GenericItem<String>("2"), firstRecommended.Item);
		    Assert.AreEqual(0.3, firstRecommended.Value, EPSILON);
	    }