Example #1
0
def test_inter_community_edges_with_digraphs():
    G = nx.complete_graph(2, create_using=nx.DiGraph())
    partition = [set([0]), set([1])]
    assert_equal(inter_community_edges(G, partition), 2)

    G = nx.complete_graph(10, create_using=nx.DiGraph())
    partition = [set([0]), set([1, 2]), set([3, 4, 5]), set([6, 7, 8, 9])]
    assert_equal(inter_community_edges(G, partition), 70)

    G = nx.cycle_graph(4, create_using=nx.DiGraph())
    partition = [set([0, 1]), set([2, 3])]
    assert_equal(inter_community_edges(G, partition), 2)
Example #2
0
def test_inter_community_edges_with_digraphs():
    G = nx.complete_graph(2, create_using = nx.DiGraph())
    partition = [{0}, {1}]
    assert_equal(inter_community_edges(G, partition), 2)

    G = nx.complete_graph(10, create_using = nx.DiGraph())
    partition = [{0}, {1, 2}, {3, 4, 5}, {6, 7, 8, 9}]
    assert_equal(inter_community_edges(G, partition), 70)

    G = nx.cycle_graph(4, create_using = nx.DiGraph())
    partition = [{0, 1}, {2, 3}]
    assert_equal(inter_community_edges(G, partition), 2)
Example #3
0
def test_inter_community_edges_with_digraphs():
    G = nx.complete_graph(2, create_using=nx.DiGraph())
    partition = [{0}, {1}]
    assert inter_community_edges(G, partition) == 2

    G = nx.complete_graph(10, create_using=nx.DiGraph())
    partition = [{0}, {1, 2}, {3, 4, 5}, {6, 7, 8, 9}]
    assert inter_community_edges(G, partition) == 70

    G = nx.cycle_graph(4, create_using=nx.DiGraph())
    partition = [{0, 1}, {2, 3}]
    assert inter_community_edges(G, partition) == 2
Example #4
0
    def clustering_statistics(self, community_partition, feat_name, feat_desc,
                              feat_interpret):
        """Compute quality of the community partitions."""
        compl_desc = " of the partition of " + feat_desc

        self.add_feature(
            feat_name + "_modularity",
            lambda graph: quality.modularity(graph, community_partition),
            "Modularity" + compl_desc,
            feat_interpret,
        )

        self.add_feature(
            feat_name + "_coverage",
            lambda graph: quality.coverage(graph, community_partition),
            "Coverage" + compl_desc,
            feat_interpret,
        )
        self.add_feature(
            feat_name + "_performance",
            lambda graph: quality.performance(graph, community_partition),
            "Performance" + compl_desc,
            feat_interpret,
        )
        self.add_feature(
            feat_name + "_inter_community_edges",
            lambda graph: quality.inter_community_edges(
                graph, community_partition),
            "Inter community edges" + compl_desc,
            feat_interpret,
        )
        self.add_feature(
            feat_name + "_inter_community_non_edges",
            lambda graph: quality.inter_community_non_edges(
                graph, community_partition),
            "Inter community non edges" + compl_desc,
            feat_interpret,
        )
        self.add_feature(
            feat_name + "_intra_community_edges",
            lambda graph: quality.intra_community_edges(
                graph, community_partition),
            "Intra community edges" + compl_desc,
            feat_interpret,
        )