The famous GN Community Discovery Algorithm Python Code Realization

Home > Sci-Tech

The famous GN Community Discovery Algorithm Python Code Realization

2021-12-05 12:03:28 20 ℃

# - * - CODING: UTF-8 - * - # Everyone pays attention to the format of the above line, generally need to declare the encoded format issues need to make a declaration from Algorithm Import Gnfrom Matplotlib Import Pyplot AS Pltimport NetworkX As NxImport CopyFilePath = R './data/football.gml'# Get the path of the data set, try to choose English, Chinese may report an error #Get the community division g = nx.read_gml (filepath) g_copy = copy.deepcopy (g) GN_COM = gn.Partition (G_copy) # Visualization POS = nx.spring_layout (g) NX.DRAW (g, pOS, with_LABELS = false, node_size = 70, width = 0.5, node_color = gn_com) plt.showv = [Node for node in G.nodes] com_dict = {node: com for node, com in zip (v, gn_com)} k = max (com_dict.values) + 1COM = [[μ] for i in range (g.number_of_nodes) if gn_com [i] == j] for J in Range (k)] # Constructs Visualization Map g_graph = nx.graphfor Each in COM: g_graph.Update (Nx.Subgraph (G, EACH) #COLOR = [COM_DICT [ Node] # visualization POS = nx.spring_layout (g_graph, seed = 4, k = 0.33) NX.DRAW (g, pOS, with_Labels = false, node_size = 1, width = 0.1, alpha = 0.2 ) nx.draw (g_graph, pos, with_labels = true, node_color = color, node_size = 70, width = 0.5, font_size = 5, font_color = '# 000000') PL T.SHOW

Help TA