public void testFullCorrelation2()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2},
     new Double?[][] {
             new double?[]{1.0, 2.0, 3.0},
             new double?[]{1.0},
     });
     double correlation = new TanimotoCoefficientSimilarity(dataModel).UserSimilarity(1, 2);
     assertCorrelationEquals(0.3333333333333333, correlation);
 }
 public void testCorrelation2()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2},
     new Double?[][] {
             new double?[]{null, 2.0, 3.0, 1.0},
             new double?[]{1.0, 1.0, null, 0.0},
     });
     double correlation = new TanimotoCoefficientSimilarity(dataModel).UserSimilarity(1, 2);
     Assert.AreEqual(0.5, correlation, EPSILON);
 }
        public void testCorrelation2()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { null, 2.0, 3.0, 1.0 },
                new double?[] { 1.0, 1.0, null, 0.0 },
            });
            double correlation = new TanimotoCoefficientSimilarity(dataModel).UserSimilarity(1, 2);

            Assert.AreEqual(0.5, correlation, EPSILON);
        }
        public void testFullCorrelation2()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { 1.0, 2.0, 3.0 },
                new double?[] { 1.0 },
            });
            double correlation = new TanimotoCoefficientSimilarity(dataModel).UserSimilarity(1, 2);

            assertCorrelationEquals(0.3333333333333333, correlation);
        }
        public void testReturnNaNDoubleWhenNoSimilaritiesForTwoItems()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { null, null, 3.0 },
                new double?[] { 1.0, 1.0, null },
            });
            Double similarity = new TanimotoCoefficientSimilarity(dataModel).ItemSimilarity(1, 2);

            Assert.AreEqual(Double.NaN, similarity, EPSILON);
        }
Пример #6
0
        public Result RecommendTanimotoSimilarity(int userId, int movieId)
        {
            Result result = new Result();
            dataModel = new FileDataModel(PathToDataFile, false, FileDataModel.DEFAULT_MIN_RELOAD_INTERVAL_MS, false, ",", userId, movieId);
            var removedPrefs = GenericDataModel.preferenceFromUsersRemoved.Values;
            var valueToCompare = removedPrefs.FirstOrDefault(i => i.GetItemID() == movieId).GetValue();
            var similarity = new TanimotoCoefficientSimilarity(dataModel);
            var recommender = new GenericItemBasedRecommender(dataModel, similarity);
            var preferences = recommender.EstimatePreference(userId, movieId);

            result.PredictedValue = preferences;
            result.RealValue = removedPrefs.First().GetValue();
            return result;
        }
        public void testItemsSimilarities()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { 2.0, null, 2.0 },
                new double?[] { 1.0, 1.0, 1.0 },
            });
            TanimotoCoefficientSimilarity tCS = new TanimotoCoefficientSimilarity(dataModel);

            Assert.AreEqual(0.5, tCS.ItemSimilarity(0, 1), EPSILON);
            Assert.AreEqual(1, tCS.ItemSimilarity(0, 2), EPSILON);

            double[] similarities = tCS.ItemSimilarities(0, new long [] { 1, 2 });
            Assert.AreEqual(0.5, similarities[0], EPSILON);
            Assert.AreEqual(1, similarities[1], EPSILON);
        }
        public void testItemsSimilarities()
        {
            IDataModel dataModel = getDataModel(
                new long[] {1, 2},
                new Double?[][] {
                        new double?[]{2.0, null, 2.0},
                        new double?[]{1.0, 1.0, 1.0},
                });
              TanimotoCoefficientSimilarity tCS = new TanimotoCoefficientSimilarity(dataModel);
              Assert.AreEqual(0.5, tCS.ItemSimilarity(0, 1), EPSILON);
              Assert.AreEqual(1, tCS.ItemSimilarity(0, 2), EPSILON);

              double[] similarities = tCS.ItemSimilarities(0, new long [] {1, 2});
              Assert.AreEqual(0.5, similarities[0], EPSILON);
              Assert.AreEqual(1, similarities[1], EPSILON);
        }
 public void testReturnNaNDoubleWhenNoSimilaritiesForTwoItems()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2},
     new Double?[][] {
             new double?[]{null, null, 3.0},
             new double?[]{1.0, 1.0, null},
     });
       Double similarity = new TanimotoCoefficientSimilarity(dataModel).ItemSimilarity(1, 2);
       Assert.AreEqual(Double.NaN, similarity, EPSILON);
 }