def test_bimodularity(self): self.star_wars_graph: sparse.csr_matrix = star_wars_villains() self.villain_labels = np.array([0, 0, 1, 1]) self.movie_labels = np.array([0, 1, 0]) self.assertEqual( bimodularity(self.star_wars_graph, self.villain_labels, self.movie_labels), 0.1875)
def test_bipartite(self): star_wars_graph = star_wars_villains() self.biparis.fit(star_wars_graph) dendrogram = self.biparis.dendrogram_ self.assertEqual(dendrogram.shape, (6, 4)) if is_numba_available: self.biparis_numba.fit(star_wars_graph) dendrogram = self.biparis_numba.dendrogram_ self.assertEqual(dendrogram.shape, (6, 4))
def test_bidiffusion(self): bidiffusion = BiDiffusion() self.star_wars: sparse.csr_matrix = star_wars_villains(return_labels=False) bidiffusion.fit(self.star_wars, {0: 1}) score = bidiffusion.scores_ self.assertTrue(np.all(score <= 1) and np.all(score >= 0)) naive_bidiff = BiDiffusion(n_iter=10) score = naive_bidiff.fit_transform(self.star_wars, {0: 1}) self.assertTrue(np.all(score <= 1) and np.all(score >= 0))
def test_bipartite(self): star_wars_graph = star_wars_villains() self.bilouvain.fit(star_wars_graph) row_labels = self.bilouvain.row_labels_ col_labels = self.bilouvain.col_labels_ self.assertEqual(row_labels.shape, (4, )) self.assertEqual(col_labels.shape, (3, )) if is_numba_available: self.bilouvain_numba.fit(star_wars_graph) row_labels = self.bilouvain_numba.row_labels_ col_labels = self.bilouvain_numba.col_labels_ self.assertEqual(row_labels.shape, (4, )) self.assertEqual(col_labels.shape, (3, ))
def test_cosine_modularity(self): self.graph = sparse.csr_matrix( np.array([[0, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 1], [1, 0, 1, 0]])) self.bipartite: sparse.csr_matrix = star_wars_villains() self.embedding = np.ones((4, 2)) self.features = np.ones((3, 2)) self.assertAlmostEqual(cosine_modularity(self.graph, self.embedding), 0.) fit, div, modularity = cosine_modularity(self.graph, self.embedding, return_all=True) self.assertAlmostEqual(fit, 1.) self.assertAlmostEqual(div, 1.) self.assertAlmostEqual( cosine_modularity(self.bipartite, self.embedding, self.features), 0.) fit, div, modularity = cosine_modularity(self.bipartite, self.embedding, self.features, return_all=True) self.assertAlmostEqual(fit, 1.) self.assertAlmostEqual(div, 1.)
def setUp(self): self.biadjacency = star_wars_villains(return_labels=False)
def setUp(self): self.undirected = SparseLR(house(), [(np.ones(5), np.ones(5))]) self.bipartite = SparseLR(star_wars_villains(), [(np.ones(4), np.ones(3))])
def setUp(self): self.biadjacency = star_wars_villains()