Esempio n. 1
0
        public void TestFromCorrelation()
        {
            User            user1            = GetUser("test1", 1.0, 2.0);
            User            user2            = GetUser("test2", 2.0, 5.0);
            User            user3            = GetUser("test3", 3.0, 6.0);
            DataModel       dataModel        = GetDataModel(user1, user2, user3);
            ItemCorrelation otherCorrelation = new PearsonCorrelation(dataModel);
            ItemCorrelation itemCorrelation  = new GenericItemCorrelation(otherCorrelation, dataModel);

            AssertCorrelationEquals(1.0,
                                    itemCorrelation.GetItemCorrelation(dataModel.GetItem("0"), dataModel.GetItem("0")));
            AssertCorrelationEquals(0.960768922830523,
                                    itemCorrelation.GetItemCorrelation(dataModel.GetItem("0"), dataModel.GetItem("1")));
        }
Esempio n. 2
0
        public void TestSimple()
        {
            Item item1 = new GenericItem <String>("1");
            Item item2 = new GenericItem <String>("2");
            Item item3 = new GenericItem <String>("3");
            Item item4 = new GenericItem <String>("4");
            List <GenericItemCorrelation.ItemItemCorrelation> correlations =
                new List <GenericItemCorrelation.ItemItemCorrelation>(4);

            correlations.Add(new GenericItemCorrelation.ItemItemCorrelation(item1, item2, 0.5));
            correlations.Add(new GenericItemCorrelation.ItemItemCorrelation(item2, item1, 0.6));
            correlations.Add(new GenericItemCorrelation.ItemItemCorrelation(item1, item1, 0.5));
            correlations.Add(new GenericItemCorrelation.ItemItemCorrelation(item1, item3, 0.3));
            GenericItemCorrelation itemCorrelation = new GenericItemCorrelation(correlations);

            Assert.AreEqual(1.0, itemCorrelation.GetItemCorrelation(item1, item1));
            Assert.AreEqual(0.6, itemCorrelation.GetItemCorrelation(item1, item2));
            Assert.AreEqual(0.6, itemCorrelation.GetItemCorrelation(item2, item1));
            Assert.AreEqual(0.3, itemCorrelation.GetItemCorrelation(item1, item3));
            Assert.IsTrue(Double.IsNaN(itemCorrelation.GetItemCorrelation(item3, item4)));
        }