Example #1
0
        public void testRecommender()
        {
            IRecommender             recommender = buildRecommender();
            IList <IRecommendedItem> recommended = recommender.Recommend(1, 1);

            Assert.NotNull(recommended);
            Assert.AreEqual(1, recommended.Count);
            IRecommendedItem firstRecommended = recommended[0];

            Assert.AreEqual(2, firstRecommended.GetItemID());
            Assert.AreEqual(0.1f, firstRecommended.GetValue(), EPSILON);
            recommender.Refresh(null);
            Assert.AreEqual(2, firstRecommended.GetItemID());
            Assert.AreEqual(0.1f, firstRecommended.GetValue(), EPSILON);
        }
Example #2
0
        public void testRecommender()
        {
            IRecommender             recommender = new ItemAverageRecommender(getDataModel());
            IList <IRecommendedItem> recommended = recommender.Recommend(1, 1);

            Assert.NotNull(recommended);
            Assert.AreEqual(1, recommended.Count);
            IRecommendedItem firstRecommended = recommended[0];

            Assert.AreEqual(2, firstRecommended.GetItemID());
            Assert.AreEqual(0.53333336f, firstRecommended.GetValue(), EPSILON);
            recommender.Refresh(null);
            Assert.AreEqual(2, firstRecommended.GetItemID());
            Assert.AreEqual(0.53333336f, firstRecommended.GetValue(), EPSILON);
        }
Example #3
0
        public override bool Equals(object o)
        {
            if (!(o is GenericRecommendedItem))
            {
                return(false);
            }
            IRecommendedItem other = (IRecommendedItem)o;

            return(itemID == other.GetItemID() && value == other.GetValue());
        }
        public void testMostSimilarToMultipleExcludeIfNotSimilarToAll()
        {
            IItemBasedRecommender   recommender = buildRecommender2();
            List <IRecommendedItem> similar     = recommender.MostSimilarItems(new long[] { 3, 4 }, 2);

            Assert.NotNull(similar);
            Assert.AreEqual(1, similar.Count);
            IRecommendedItem first = similar[0];

            Assert.AreEqual(0, first.GetItemID());
            Assert.AreEqual(0.2f, first.GetValue(), EPSILON);
        }
Example #5
0
        public void testBestRating()
        {
            IRecommender             recommender = buildRecommender();
            IList <IRecommendedItem> recommended = recommender.Recommend(1, 1);

            Assert.NotNull(recommended);
            Assert.AreEqual(1, recommended.Count);
            IRecommendedItem firstRecommended = recommended[0];

            // item one should be recommended because it has a greater rating/score
            Assert.AreEqual(2, firstRecommended.GetItemID());
            Assert.AreEqual(0.1f, firstRecommended.GetValue(), EPSILON);
        }
        public void testMostSimilarToMultipleDontExcludeIfNotSimilarToAll()
        {
            IItemBasedRecommender   recommender = buildRecommender2();
            List <IRecommendedItem> similar     = recommender.MostSimilarItems(new long[] { 1, 2, 4 }, 10, false);

            Assert.NotNull(similar);
            Assert.AreEqual(2, similar.Count);
            IRecommendedItem first  = similar[0];
            IRecommendedItem second = similar[1];

            Assert.AreEqual(0, first.GetItemID());
            Assert.AreEqual(0.933333333f, first.GetValue(), EPSILON);
            Assert.AreEqual(3, second.GetItemID());
            Assert.AreEqual(-0.2f, second.GetValue(), EPSILON);
        }
        public void testMostSimilarToMultiple()
        {
            IItemBasedRecommender   recommender = buildRecommender2();
            List <IRecommendedItem> similar     = recommender.MostSimilarItems(new long[] { 0, 1 }, 2);

            Assert.NotNull(similar);
            Assert.AreEqual(2, similar.Count);
            IRecommendedItem first  = similar[0];
            IRecommendedItem second = similar[1];

            Assert.AreEqual(2, first.GetItemID());
            Assert.AreEqual(0.85f, first.GetValue(), EPSILON);
            Assert.AreEqual(3, second.GetItemID());
            Assert.AreEqual(-0.3f, second.GetValue(), EPSILON);
        }
        public void testMostSimilar()
        {
            IItemBasedRecommender   recommender = buildRecommender();
            List <IRecommendedItem> similar     = recommender.MostSimilarItems(0, 2);

            Assert.NotNull(similar);
            Assert.AreEqual(2, similar.Count);
            IRecommendedItem first  = similar[0];
            IRecommendedItem second = similar[1];

            Assert.AreEqual(1, first.GetItemID());
            Assert.AreEqual(1.0f, first.GetValue(), EPSILON);
            Assert.AreEqual(2, second.GetItemID());
            Assert.AreEqual(0.5f, second.GetValue(), EPSILON);
        }
        public void testRecommendedBecause()
        {
            IItemBasedRecommender   recommender        = buildRecommender2();
            List <IRecommendedItem> recommendedBecause = recommender.RecommendedBecause(1, 4, 3);

            Assert.NotNull(recommendedBecause);
            Assert.AreEqual(3, recommendedBecause.Count);
            IRecommendedItem first  = recommendedBecause[0];
            IRecommendedItem second = recommendedBecause[1];
            IRecommendedItem third  = recommendedBecause[2];

            Assert.AreEqual(2, first.GetItemID());
            Assert.AreEqual(0.99f, first.GetValue(), EPSILON);
            Assert.AreEqual(3, second.GetItemID());
            Assert.AreEqual(0.4f, second.GetValue(), EPSILON);
            Assert.AreEqual(0, third.GetItemID());
            Assert.AreEqual(0.2f, third.GetValue(), EPSILON);
        }