def plot_intact_basic(num_it=10): print("Plotting intact") multilayer_network = multinet.multi_layer_network().load_network( "../datasets/intact02.gpickle", input_type="gpickle", directed=False).add_dummy_layers() network_colors, graph = multilayer_network.get_layers(style="hairball") partition = cw.louvain_communities(multilayer_network) # select top n communities by size top_n = 3 partition_counts = dict(Counter(partition.values())) top_n_communities = list(partition_counts.keys())[0:top_n] # assign node colors color_mappings = dict( zip(top_n_communities, [x for x in colors_default if x != "black"][0:top_n])) network_colors = [ color_mappings[partition[x]] if partition[x] in top_n_communities else "black" for x in multilayer_network.get_nodes() ] layout_parameters = {"iterations": num_it, "forceImport": True} f = plt.figure() hairball_plot(graph, network_colors, legend=False, layout_parameters=layout_parameters) f.savefig("../example_images/intact_" + str(num_it) + "_BH_basic.png", bbox_inches='tight', dpi=300)
def test_basic_visualizatio6(): logging.info("Import viz test 7") # string layout for larger network ----------------------------------- multilayer_network = multinet.multi_layer_network().load_network( "datasets/soc-Epinions1.edgelist", label_delimiter="---", input_type="edgelist", directed=True) hairball_plot(multilayer_network.core_network, layout_parameters={"iterations": 30})
def test_basic_visualizatio5(): logging.info("Import viz test 6") # basic string layout ---------------------------------- multilayer_network = multinet.multi_layer_network().load_network( "datasets/epigenetics.gpickle", directed=False, label_delimiter="---", input_type="gpickle_biomine") network_colors, graph = multilayer_network.get_layers(style="hairball") hairball_plot(graph, network_colors, legend=True, layout_parameters={"iterations": 30})
# select top n communities by size top_n = 10 partition_counts = dict(Counter(partition.values())) top_n_communities = list(partition_counts.keys())[0:top_n] # assign node colors color_mappings = dict( zip(top_n_communities, [x for x in colors_default if x != "black"][0:top_n])) network_colors = [ color_mappings[partition[x]] if partition[x] in top_n_communities else "black" for x in multilayer_network.get_nodes() ] f = plt.figure() # gravity=0.2,strongGravityMode=False,barnesHutTheta=1.2,edgeWeightInfluence=1,scalingRatio=2.0 hairball_plot(graph, network_colors, layout_algorithm="custom_coordinates", layout_parameters=layout_parameters, nodesize=0.02, alpha_channel=0.30, edge_width=0.001, scale_by_size=False) f.savefig("../datasets/intact.png", bbox_inches='tight', dpi=300) f.savefig("../datasets/intact.pdf", bbox_inches='tight')
network.basic_stats() # check core imports network.read_ground_truth_communities("../datasets/community.dat") partition = network.ground_truth_communities # print(partition) # select top n communities by size top_n = 100 partition_counts = dict(Counter(partition.values())) top_n_communities = list(partition_counts.keys())[0:top_n] # assign node colors color_mappings = dict( zip(top_n_communities, [x for x in colors_default if x != "black"][0:top_n])) network_colors = [ color_mappings[partition[x]] if partition[x] in top_n_communities else "black" for x in network.get_nodes() ] # visualize the network's communities! hairball_plot(network.core_network, color_list=network_colors, layout_parameters={"iterations": 100}, scale_by_size=True, layout_algorithm="force", legend=False) plt.show()
def plot_intact_embedding(num_it): # string layout for larger network ----------------------------------- multilayer_network = multinet.multi_layer_network().load_network( "../datasets/intact02.gpickle", input_type="gpickle", directed=False).add_dummy_layers() multilayer_network.basic_stats() # use embedding to first initialize the nodes.. # call a specific n2v compiled binary train_node2vec_embedding.call_node2vec_binary( "../datasets/IntactEdgelistedges.txt", "../datasets/test_embedding.emb", binary="../bin/node2vec", weighted=False) # preprocess and check embedding -- for speed, install parallel tsne from https://github.com/DmitryUlyanov/Multicore-TSNE, py3plex knows how to use it. multilayer_network.load_embedding("../datasets/test_embedding.emb") # load the positions and select the projection algorithm output_positions = embedding_tools.get_2d_coordinates_tsne( multilayer_network, output_format="pos_dict") # custom layouts are part of the custom coordinate option layout_parameters = {"iterations": num_it} layout_parameters['pos'] = output_positions # assign parameters network_colors, graph = multilayer_network.get_layers(style="hairball") partition = cw.louvain_communities(multilayer_network) # select top n communities by size top_n = 10 partition_counts = dict(Counter(partition.values())) top_n_communities = list(partition_counts.keys())[0:top_n] # assign node colors color_mappings = dict( zip(top_n_communities, [x for x in colors_default if x != "black"][0:top_n])) network_colors = [ color_mappings[partition[x]] if partition[x] in top_n_communities else "black" for x in multilayer_network.get_nodes() ] f = plt.figure() # gravity=0.2,strongGravityMode=False,barnesHutTheta=1.2,edgeWeightInfluence=1,scalingRatio=2.0 hairball_plot(graph, network_colors, layout_algorithm="custom_coordinates_initial_force", layout_parameters=layout_parameters, nodesize=0.02, alpha_channel=0.30, edge_width=0.001, scale_by_size=False) f.savefig("../datasets/" + str(num_it) + "intact.png", bbox_inches='tight', dpi=300)