Example #1
0
    def test_preferences(self):
        d = PreferenceDict()
        a, b = (0, 1, 2), (3, 4, 5)
        d[a, b] = 1

        e, f = (9, 9), (1, 1)
        d[e, f] = -1

        self.assertEqual(sorted(d.preferences()), [(0, 1, 2), (1, 1),
                                                   (3, 4, 5), (9, 9)])
Example #2
0
    def test_fit_simple_logit(self):
        with self.test_session():
            data = PreferenceDict()
            a = (0,)
            b = (1,)
            c = (2,)
            d = (3,)

            data[a, b] = 1
            data[a, c] = 1
            data[c, b] = -1
            data[c, d] = 1

            m = BinaryPreferenceModel(
                n_iter=500,
                n_samples=20,
                link='logit'
            )
            X, y = preprocess_data(data)
            m.fit(X, y)
            mean = m.mean([
                (0,),
                (1,),
                (2,),
                (3,),
            ])
            self.assertTrue(
                all(x > y for x, y in zip(mean, mean[1:]))
            )
Example #3
0
    def test_basic(self):
        d = PreferenceDict()
        a, b = (0, 1, 2), (3, 4, 5)
        d[a, b] = 1
        self.assertEqual(d[a, b], 1)
        self.assertEqual(d[b, a], -1)

        e, f = (9, 9), (1, 1)
        d[e, f] = -1
        self.assertEqual(d[e, f], -1)
        self.assertEqual(d[f, e], 1)

        self.assertEqual(len(d), 2)