Ejemplo n.º 1
0
    def test_small_graph(self):
        graph = nx.Graph()
        newman = NewmanGreedy(graph)
        self.assertEqual(list(newman.get_clusters()), [])

        graph.add_node(1)
        newman = NewmanGreedy(graph)
        self.assertEqual(list(newman.get_clusters(1)[0]), [1])
        self.assertEqual(list(newman.get_clusters()[0]), [1])
Ejemplo n.º 2
0
    def test_orphans(self):
        graph = nx.Graph()
        graph.add_nodes_from(range(10))
        graph.add_edges_from([[0, 1], [1, 2], [0, 2]])
        newman = NewmanGreedy(graph)

        clusters = newman.get_clusters()
        self.assertIn(set([0, 1, 2]), clusters)
        for node in range(3, 10):
            self.assertIn(set([node]), clusters)
Ejemplo n.º 3
0
def compute_greedy_newman(n_vertex, edge_list):
    from agglomcluster import NewmanGreedy

    graph = tf.compute_networkx_form(n_vertex, edge_list)

    t = time.time()
    clst = NewmanGreedy(graph)
    clusters = clst.get_clusters()
    exectime = time.time() - t

    labels = tf.compute_labels_from_clusters(n_vertex, clusters)

    return labels, clusters, exectime