Beispiel #1
0
        public void testFromCorrelation()
        {
            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 otherSimilarity = new PearsonCorrelationSimilarity(dataModel);
            IItemSimilarity itemSimilarity  = new GenericItemSimilarity(otherSimilarity, dataModel);

            assertCorrelationEquals(1.0, itemSimilarity.ItemSimilarity(0, 0));
            assertCorrelationEquals(0.960768922830523, itemSimilarity.ItemSimilarity(0, 1));
        }
Beispiel #2
0
        public void testSimple()
        {
            List <GenericItemSimilarity.ItemItemSimilarity> similarities = new List <GenericItemSimilarity.ItemItemSimilarity>();

            similarities.Add(new GenericItemSimilarity.ItemItemSimilarity(1, 2, 0.5));
            similarities.Add(new GenericItemSimilarity.ItemItemSimilarity(2, 1, 0.6));
            similarities.Add(new GenericItemSimilarity.ItemItemSimilarity(1, 1, 0.5));
            similarities.Add(new GenericItemSimilarity.ItemItemSimilarity(1, 3, 0.3));
            GenericItemSimilarity itemCorrelation = new GenericItemSimilarity(similarities);

            Assert.AreEqual(1.0, itemCorrelation.ItemSimilarity(1, 1), EPSILON);
            Assert.AreEqual(0.6, itemCorrelation.ItemSimilarity(1, 2), EPSILON);
            Assert.AreEqual(0.6, itemCorrelation.ItemSimilarity(2, 1), EPSILON);
            Assert.AreEqual(0.3, itemCorrelation.ItemSimilarity(1, 3), EPSILON);
            Assert.True(Double.IsNaN(itemCorrelation.ItemSimilarity(3, 4)));
        }
Beispiel #3
0
        public void testAllSimilaritiesWithIndex()
        {
            List <GenericItemSimilarity.ItemItemSimilarity> itemItemSimilarities =
                new List <GenericItemSimilarity.ItemItemSimilarity>()
            {
                new GenericItemSimilarity.ItemItemSimilarity(1L, 2L, 0.2),
                new GenericItemSimilarity.ItemItemSimilarity(1L, 3L, 0.2),
                new GenericItemSimilarity.ItemItemSimilarity(2L, 1L, 0.2),
                new GenericItemSimilarity.ItemItemSimilarity(3L, 5L, 0.2),
                new GenericItemSimilarity.ItemItemSimilarity(3L, 4L, 0.2)
            };

            IItemSimilarity similarity = new GenericItemSimilarity(itemItemSimilarities);

            Assert.True(containsExactly(similarity.AllSimilarItemIDs(1L), 2L, 3L));
            Assert.True(containsExactly(similarity.AllSimilarItemIDs(2L), 1L));
            Assert.True(containsExactly(similarity.AllSimilarItemIDs(3L), 1L, 5L, 4L));
            Assert.True(containsExactly(similarity.AllSimilarItemIDs(4L), 3L));
            Assert.True(containsExactly(similarity.AllSimilarItemIDs(5L), 3L));
        }