예제 #1
0
    def test_plot_com_properties_relation(self):

        g = nx.karate_club_graph()
        coms = algorithms.louvain(g)
        coms2 = algorithms.label_propagation(g)

        viz.plot_com_properties_relation([coms, coms2], evaluation.size,
                                         evaluation.internal_edge_density)

        plt.savefig("cluster.pdf")
        os.remove("cluster.pdf")

        viz.plot_com_properties_relation(coms, evaluation.size,
                                         evaluation.internal_edge_density)

        plt.savefig("cluster.pdf")
        os.remove("cluster.pdf")
예제 #2
0
def draw_plot_map(list_of_communities, number):
    lmplot = viz.plot_com_properties_relation(list_of_communities,
                                              evaluation.size,
                                              evaluation.internal_edge_density)
    filename = "communities/size_vs_internal_density" + str(number) + ".png"

    lmplot = viz.plot_com_properties_relation(
        list_of_communities, evaluation.size,
        evaluation.triangle_participation_ratio)
    filename = "communities/size_vs_triangle_participation_ratio" + str(
        number) + ".png"
    plt.savefig(filename)

    lmplot = viz.plot_com_properties_relation(
        list_of_communities, evaluation.average_internal_degree,
        evaluation.fraction_over_median_degree)
    filename = "communities/internal_degree_vs_fraction_over_median_degree" + str(
        number) + ".png"
    plt.savefig(filename)

    lmplot = viz.plot_com_properties_relation(list_of_communities,
                                              evaluation.conductance,
                                              evaluation.expansion)
    filename = "communities/outside_vs_inside_edges" + str(number) + ".png"
    plt.savefig(filename)

    lmplot = viz.plot_com_properties_relation(list_of_communities,
                                              evaluation.edges_inside,
                                              evaluation.cut_ratio)
    filename = "communities/edges_inside_vs_cut_ratio" + str(number) + ".png"
    plt.savefig(filename)

    lmplot = viz.plot_com_properties_relation(list_of_communities,
                                              evaluation.internal_edge_density,
                                              evaluation.modularity_density)
    filename = "communities/internal_edge_density_vs_modularity_density" + str(
        number) + ".png"
    plt.savefig(filename)
예제 #3
0
    communities_set.add(frozenset(com_nodes))
# build the nodeclustering object
ground_truth_com = NodeClustering(communities=communities_set, graph=nx_g, method_name="ground_truth")

#%% define and plot ground truth
# define the positions here so all the cluster plots in the loop are the same structure
pos = nx.fruchterman_reingold_layout(nx_g)
#%%
# plot the original network with the ground truth communities
viz.plot_network_clusters(nx_g, ground_truth_com, pos, figsize=(5, 5))
#nx.draw_networkx_labels(nx_g, pos=pos)
plt.title(f'Ground Truth of {graph_name}')
plt.show()

#%% evaluate ground communitiy metrics
viz.plot_com_properties_relation(ground_truth_com, evaluation.size,
                                 evaluation.internal_edge_density)
plt.show()

#%%
viz.plot_com_stat(ground_truth_com, evaluation.conductance)
plt.show()
viz.plot_com_stat(ground_truth_com, evaluation.average_internal_degree)
plt.show()


algo_dict = {'louvain': algorithms.louvain,
             'leidan': algorithms.leiden,
             'greed_modularity': algorithms.greedy_modularity,
             'label_prop': algorithms.label_propagation,
             'walktrap': algorithms.walktrap,
             'infomap': algorithms.infomap,