def test_biclustering(self): self.directed: sparse.csr_matrix = painters() bispectral_clustering = BiSpectralClustering(embedding_dimension=3, co_clustering=False) bispectral_clustering.fit(self.directed) self.assertEqual(bispectral_clustering.labels_.shape[0], self.directed.shape[0]) self.assertTrue(bispectral_clustering.col_labels_ is None)
def test_maxrdiff(self): adjacency: sparse.csr_matrix = painters() adj_array_seeds = -np.ones(adjacency.shape[0]) adj_array_seeds[:2] = np.arange(2) adj_dict_seeds = {0: 0, 1: 1} md = MaxDiff() labels1 = md.fit_transform(adjacency, adj_array_seeds) labels2 = md.fit_transform(adjacency, adj_dict_seeds) self.assertTrue(np.allclose(labels1, labels2)) self.assertEqual(labels2.shape[0], adjacency.shape[0])
def test_multidiff(self): adjacency: sparse.csr_matrix = painters() adj_array_seeds = -np.ones(adjacency.shape[0]) adj_array_seeds[:2] = np.arange(2) adj_dict_seeds = {0: 0, 1: 1} md = MultiDiff() membership1 = md.fit_transform(adjacency, adj_array_seeds) membership2 = md.fit_transform(adjacency, adj_dict_seeds) self.assertTrue(np.allclose(membership1, membership2)) self.assertEqual(membership2.shape, (adjacency.shape[0], 2))
def test_directed(self): self.painters = painters(return_labels=False) self.louvain.fit(self.painters) labels = self.louvain.labels_ self.assertEqual(labels.shape, (14, )) self.assertAlmostEqual(modularity(self.painters, labels), 0.32, 2) self.bilouvain.fit(self.painters) n1, n2 = self.painters.shape row_labels = self.bilouvain.row_labels_ col_labels = self.bilouvain.col_labels_ self.assertEqual(row_labels.shape, (n1, )) self.assertEqual(col_labels.shape, (n2, ))
def test_directed(self): self.painters = painters(return_labels=False) adjacency: sparse.csr_matrix = self.painters self.diffusion.fit(adjacency, {0: 0, 1: 1, 2: 0.5}) score = self.diffusion.scores_ self.assertTrue(np.all(score <= 1 + self.tol) and np.all(score >= 0 - self.tol))
def setUp(self): self.undirected: sparse.csr_matrix = karate_club() self.directed: sparse.csr_matrix = painters() self.bipartite: sparse.csr_matrix = movie_actor()