예제 #1
0
    def test_undirected(self):
        adjacency = test_graph()
        n = adjacency.shape[0]

        method = Spring()
        embedding = method.fit_transform(adjacency)
        self.assertEqual(embedding.shape, (n, 2))
        pred1 = method.predict(adjacency[0])
        pred2 = method.predict(adjacency[0].toarray())
        self.assertEqual(pred1.shape, (2, ))
        self.assertAlmostEqual(np.linalg.norm(pred1 - pred2), 0)

        pred1 = method.predict(adjacency)
        pred2 = method.predict(adjacency.toarray())
        self.assertTupleEqual(pred1.shape, (n, 2))
        self.assertAlmostEqual(np.linalg.norm(pred1 - pred2), 0)
예제 #2
0
    def test_undirected(self):
        adjacency = test_graph()
        n = adjacency.shape[0]

        for method in self.methods:
            with self.assertRaises(ValueError):
                method.predict(adjacency[0])

            embedding = method.fit_transform(adjacency)

            self.assertEqual(embedding.shape, (n, 2))

            ref = embedding[0]
            pred1 = method.predict(adjacency[0])
            pred2 = method.predict(adjacency[0].toarray())

            self.assertEqual(pred1.shape, (2, ))
            self.assertAlmostEqual(np.linalg.norm(pred1 - pred2), 0)
            self.assertAlmostEqual(np.linalg.norm(pred1 - ref), 0)

            pred1 = method.predict(adjacency)
            pred2 = method.predict(adjacency.toarray())

            self.assertTupleEqual(pred1.shape, (n, 2))
            self.assertAlmostEqual(np.linalg.norm(pred1 - pred2), 0)
            self.assertAlmostEqual(np.linalg.norm(pred1 - embedding), 0)

        method = Spring()
        embedding = method.fit_transform(adjacency)
        self.assertEqual(embedding.shape, (n, 2))
        pred1 = method.predict(adjacency[0])
        pred2 = method.predict(adjacency[0].toarray())
        self.assertEqual(pred1.shape, (2, ))
        self.assertAlmostEqual(np.linalg.norm(pred1 - pred2), 0)

        pred1 = method.predict(adjacency)
        pred2 = method.predict(adjacency.toarray())
        self.assertTupleEqual(pred1.shape, (n, 2))
        self.assertAlmostEqual(np.linalg.norm(pred1 - pred2), 0)