public void testFullCorrelation1Weighted()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2},
     new Double?[][] {
             new double?[]{3.0, -2.0},
             new double?[]{3.0, -2.0},
     });
     double correlation = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED).UserSimilarity(1, 2);
     assertCorrelationEquals(1.0, correlation);
 }
 public void testFullCorrelation2()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2},
     new Double?[][] {
             new double?[]{3.0, 3.0},
             new double?[]{3.0, 3.0},
     });
     double correlation = new EuclideanDistanceSimilarity(dataModel).UserSimilarity(1, 2);
     Assert.AreEqual(1.0, correlation, EPSILON);
 }
Ejemplo n.º 3
0
        public void testNoCorrelation2()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { null, 1.0, null },
                new double?[] { null, null, 1.0 },
            });
            double correlation = new EuclideanDistanceSimilarity(dataModel).UserSimilarity(1, 2);

            Assert.True(Double.IsNaN(correlation));
        }
Ejemplo n.º 4
0
        public void testNoCorrelation1Weighted()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { 3.0, -2.0 },
                new double?[] { -3.0, 2.0 },
            });
            double correlation = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED).UserSimilarity(1, 2);

            assertCorrelationEquals(0.7213202601812372, correlation);
        }
Ejemplo n.º 5
0
        public void testNoCorrelation1()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { 3.0, -2.0 },
                new double?[] { -3.0, 2.0 },
            });
            double correlation = new EuclideanDistanceSimilarity(dataModel).UserSimilarity(1, 2);

            assertCorrelationEquals(0.1639607805437114, correlation);
        }
Ejemplo n.º 6
0
        public void testFullCorrelation2()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { 3.0, 3.0 },
                new double?[] { 3.0, 3.0 },
            });
            double correlation = new EuclideanDistanceSimilarity(dataModel).UserSimilarity(1, 2);

            Assert.AreEqual(1.0, correlation, EPSILON);
        }
Ejemplo n.º 7
0
        public void testSimpleWeighted()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { 1.0, 2.0, 3.0 },
                new double?[] { 2.0, 5.0, 6.0 },
            });
            double correlation = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED).UserSimilarity(1, 2);

            assertCorrelationEquals(0.8210911630511055, correlation);
        }
Ejemplo n.º 8
0
        public void testSimple()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { 1.0, 2.0, 3.0 },
                new double?[] { 2.0, 5.0, 6.0 },
            });
            double correlation = new EuclideanDistanceSimilarity(dataModel).UserSimilarity(1, 2);

            assertCorrelationEquals(0.2843646522044218, correlation);
        }
 public void testFullItemCorrelation1()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2},
     new Double?[][] {
             new double?[]{3.0, 3.0},
             new double?[]{-2.0, -2.0},
     });
     double correlation =
     new EuclideanDistanceSimilarity(dataModel).ItemSimilarity(0, 1);
     assertCorrelationEquals(1.0, correlation);
 }
Ejemplo n.º 10
0
        public void testNoCorrelation3()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { 90.0, 80.0, 70.0 },
                new double?[] { 70.0, 80.0, 90.0 },
            });
            double correlation = new EuclideanDistanceSimilarity(dataModel).UserSimilarity(1, 2);

            assertCorrelationEquals(0.05770363219029305, correlation);
        }
Ejemplo n.º 11
0
        public void testFullItemCorrelation1()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2 },
                new Double?[][] {
                new double?[] { 3.0, 3.0 },
                new double?[] { -2.0, -2.0 },
            });
            double correlation =
                new EuclideanDistanceSimilarity(dataModel).ItemSimilarity(0, 1);

            assertCorrelationEquals(1.0, correlation);
        }
Ejemplo n.º 12
0
        public Result RecommendEuclideanDistanceSimilarity(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 EuclideanDistanceSimilarity(dataModel);
            var recommender = new GenericItemBasedRecommender(dataModel, similarity);
            var preferences = recommender.EstimatePreference(userId, movieId);

            result.PredictedValue = preferences;
            result.RealValue = removedPrefs.First().GetValue();
            return result;
        }
Ejemplo n.º 13
0
        public void testSimpleItemWeighted()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2, 3 },
                new Double?[][] {
                new double?[] { 1.0, 2.0 },
                new double?[] { 2.0, 5.0 },
                new double?[] { 3.0, 6.0 },
            });
            IItemSimilarity itemSimilarity = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED);
            double          correlation    = itemSimilarity.ItemSimilarity(0, 1);

            assertCorrelationEquals(0.8210911630511055, correlation);
        }
 public void testSimpleWeighted()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2},
     new Double?[][] {
             new double?[]{1.0, 2.0, 3.0},
             new double?[]{2.0, 5.0, 6.0},
     });
     double correlation = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED).UserSimilarity(1, 2);
     assertCorrelationEquals(0.8210911630511055, correlation);
 }
 public void testSimpleItemWeighted()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2, 3},
     new Double?[][] {
             new double?[]{1.0, 2.0},
             new double?[]{2.0, 5.0},
             new double?[]{3.0, 6.0},
     });
     IItemSimilarity itemSimilarity = new EuclideanDistanceSimilarity(dataModel, Weighting.WEIGHTED);
     double correlation = itemSimilarity.ItemSimilarity(0, 1);
     assertCorrelationEquals(0.8210911630511055, correlation);
 }
 public void testSimpleItem()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2, 3},
     new Double?[][] {
             new double?[]{1.0, 2.0},
             new double?[]{2.0, 5.0},
             new double?[]{3.0, 6.0},
     });
     double correlation =
     new EuclideanDistanceSimilarity(dataModel).ItemSimilarity(0, 1);
     assertCorrelationEquals(0.2843646522044218, correlation);
 }
 public void testNoItemCorrelation3()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2, 3},
     new Double?[][] {
             new double?[]{90.0, 70.0},
             new double?[]{80.0, 80.0},
             new double?[]{70.0, 90.0},
     });
     double correlation =
     new EuclideanDistanceSimilarity(dataModel).ItemSimilarity(0, 1);
     assertCorrelationEquals(0.05770363219029305, correlation);
 }
 public void testNoItemCorrelation2()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2},
     new Double?[][] {
             new double?[]{null, 1.0, null},
             new double?[]{null, null, 1.0},
     });
     double correlation = new EuclideanDistanceSimilarity(dataModel).ItemSimilarity(1, 2);
     Assert.True(Double.IsNaN(correlation));
 }
 public void testNoItemCorrelation1()
 {
     IDataModel dataModel = getDataModel(
     new long[] {1, 2},
     new Double?[][] {
             new double?[]{3.0, -3.0},
             new double?[]{-2.0, 2.0},
     });
     double correlation =
     new EuclideanDistanceSimilarity(dataModel).ItemSimilarity(0, 1);
     assertCorrelationEquals(0.1639607805437114, correlation);
 }