コード例 #1
0
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)
コード例 #2
0
    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)
コード例 #3
0
 def test_disconnected(self):
     adjacency = test_graph_disconnect()
     closeness = Closeness()
     with self.assertRaises(ValueError):
         closeness.fit(adjacency)
コード例 #4
0
 def test_params(self):
     with self.assertRaises(ValueError):
         adjacency = test_graph()
         Closeness(method='toto').fit(adjacency)
コード例 #5
0
 def test_connected(self):
     self.closeness = Closeness()
     adjacency = sparse.identity(2, format='csr')
     with self.assertRaises(ValueError):
         self.closeness.fit(adjacency)
コード例 #6
0
 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)