class TestDiffusion(unittest.TestCase): def test_approximate(self): self.closeness = Closeness(method='approximate', n_jobs=-1) scores = self.closeness.fit_transform(house()) self.assertEqual((np.round(scores, 2) == [0.67, 0.8, 0.67, 0.67, 0.8]).sum(), 5) def test_connected(self): self.closeness = Closeness() adjacency = sparse.identity(2, format='csr') with self.assertRaises(ValueError): self.closeness.fit(adjacency)
def test_parallel(self): adjacency = test_graph() n = adjacency.shape[0] closeness = Closeness(method='approximate') scores1 = closeness.fit_transform(adjacency) closeness = Closeness(method='approximate', n_jobs=-1) scores2 = closeness.fit_transform(adjacency) self.assertEqual(scores1.shape, (n,)) self.assertAlmostEqual(np.linalg.norm(scores1 - scores2), 0)
def test_disconnected(self): adjacency = test_graph_disconnect() closeness = Closeness() with self.assertRaises(ValueError): closeness.fit(adjacency)
def test_params(self): with self.assertRaises(ValueError): adjacency = test_graph() Closeness(method='toto').fit(adjacency)
def test_connected(self): self.closeness = Closeness() adjacency = sparse.identity(2, format='csr') with self.assertRaises(ValueError): self.closeness.fit(adjacency)
def test_approximate(self): self.closeness = Closeness(method='approximate', n_jobs=-1) scores = self.closeness.fit_transform(house()) self.assertEqual((np.round(scores, 2) == [0.67, 0.8, 0.67, 0.67, 0.8]).sum(), 5)