Пример #1
0
        public void testCorrelation()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2, 3, 4, 5 },
                new Double?[][] {
                new double?[] { 1.0, 1.0 },
                new double?[] { 1.0, null, 1.0 },
                new double?[] { null, null, 1.0, 1.0, 1.0 },
                new double?[] { 1.0, 1.0, 1.0, 1.0, 1.0 },
                new double?[] { null, 1.0, 1.0, 1.0, 1.0 },
            });

            LogLikelihoodSimilarity similarity = new LogLikelihoodSimilarity(dataModel);

            assertCorrelationEquals(0.12160727029227925, similarity.ItemSimilarity(1, 0));
            assertCorrelationEquals(0.12160727029227925, similarity.ItemSimilarity(0, 1));

            assertCorrelationEquals(0.5423213660693732, similarity.ItemSimilarity(1, 2));
            assertCorrelationEquals(0.5423213660693732, similarity.ItemSimilarity(2, 1));

            assertCorrelationEquals(0.6905400104897509, similarity.ItemSimilarity(2, 3));
            assertCorrelationEquals(0.6905400104897509, similarity.ItemSimilarity(3, 2));

            assertCorrelationEquals(0.8706358464330881, similarity.ItemSimilarity(3, 4));
            assertCorrelationEquals(0.8706358464330881, similarity.ItemSimilarity(4, 3));
        }
        public void testCorrelation()
        {
            IDataModel dataModel = getDataModel(
            new long[] {1, 2, 3, 4, 5},
            new Double?[][] {
                    new double?[]{1.0, 1.0},
                    new double?[]{1.0, null, 1.0},
                    new double?[]{null, null, 1.0, 1.0, 1.0},
                    new double?[]{1.0, 1.0, 1.0, 1.0, 1.0},
                    new double?[]{null, 1.0, 1.0, 1.0, 1.0},
            });

            LogLikelihoodSimilarity similarity = new LogLikelihoodSimilarity(dataModel);

            assertCorrelationEquals(0.12160727029227925, similarity.ItemSimilarity(1, 0));
            assertCorrelationEquals(0.12160727029227925, similarity.ItemSimilarity(0, 1));

            assertCorrelationEquals(0.5423213660693732, similarity.ItemSimilarity(1, 2));
            assertCorrelationEquals(0.5423213660693732, similarity.ItemSimilarity(2, 1));

            assertCorrelationEquals(0.6905400104897509, similarity.ItemSimilarity(2, 3));
            assertCorrelationEquals(0.6905400104897509, similarity.ItemSimilarity(3, 2));

            assertCorrelationEquals(0.8706358464330881, similarity.ItemSimilarity(3, 4));
            assertCorrelationEquals(0.8706358464330881, similarity.ItemSimilarity(4, 3));
        }
Пример #3
0
        public void testNoSimilarity()
        {
            IDataModel dataModel = getDataModel(
                new long[] { 1, 2, 3, 4 },
                new Double?[][] {
                new double?[] { 1.0, null, 1.0, 1.0 },
                new double?[] { 1.0, null, 1.0, 1.0 },
                new double?[] { null, 1.0, 1.0, 1.0 },
                new double?[] { null, 1.0, 1.0, 1.0 },
            });

            LogLikelihoodSimilarity similarity = new LogLikelihoodSimilarity(dataModel);

            assertCorrelationEquals(Double.NaN, similarity.ItemSimilarity(1, 0));
            assertCorrelationEquals(Double.NaN, similarity.ItemSimilarity(0, 1));

            assertCorrelationEquals(0.0, similarity.ItemSimilarity(2, 3));
            assertCorrelationEquals(0.0, similarity.ItemSimilarity(3, 2));
        }
        public void testNoSimilarity()
        {
            IDataModel dataModel = getDataModel(
            new long[] {1, 2, 3, 4},
            new Double?[][] {
                new double?[]{1.0, null, 1.0, 1.0},
                new double?[]{1.0, null, 1.0, 1.0},
                new double?[]{null, 1.0, 1.0, 1.0},
                new double?[]{null, 1.0, 1.0, 1.0},
            });

            LogLikelihoodSimilarity similarity = new LogLikelihoodSimilarity(dataModel);

            assertCorrelationEquals(Double.NaN, similarity.ItemSimilarity(1, 0));
            assertCorrelationEquals(Double.NaN, similarity.ItemSimilarity(0, 1));

            assertCorrelationEquals(0.0, similarity.ItemSimilarity(2, 3));
            assertCorrelationEquals(0.0, similarity.ItemSimilarity(3, 2));
        }