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:])) )
def test_preprocess_data(self): pd = UniformPreferenceDict(2) a = (0, 1) b = (2, 3) c = (4, 5) d = (6, 7) e = (8, 9) pd[a, b] = 1 pd[a, c] = 1 pd[a, d] = 1 pd[c, b] = -1 pd[d, e] = 0 X, y = preprocess_data(pd) A = np.array([ [0, 1], [2, 3], [4, 5], [6, 7], [8, 9], ]) self.assertTrue(np.allclose(A, X)) b = { (0, 1): 1, (0, 2): 1, (0, 3): 1, (1, 2): 1, (3, 4): 0, } self.assertEqual(y, b)