def main(): test_network = ["karate_club", "facebook"] for net in test_network: net_file = data_utils.get_data_path(net) g = graph_utils.load_basic_network(net_file) sir_file = net_file.split('.')[0] + '-sir.txt' sir = {} if os.path.exists(sir_file): with open(sir_file, 'r') as f: for l in f: data = l.split() id = int(data[0]) score = float(data[1]) sir[id] = score else: print("SIR Simulation start.") sir = sir_ranking(g, gamma=1.0, num_epoch=100) print("SIR Simulation end.") centralities = [ nx.degree_centrality, nx.closeness_centrality, nx.eigenvector_centrality, nx.pagerank, Local_gravity_model ] for c in centralities: if c.__name__ == 'pagerank': res = c(g, alpha=0.95) elif c.__name__ == 'Local_gravity_model': res = c(g, depth=2) else: res = c(g) tau, p = kendallTau(res, sir) print("%s\t%s\t%f" % (net, c.__name__, tau))
def explore_lyb(): net_file = data_utils.get_data_path("lyb") g = graph_utils.load_basic_network(net_file) n2v_emb = node2vec.node2vec_emb(g, p=0.5, q=2, out_dim=32, num_walks=20) n2v_emb.learn_embedding() # out_file = net_file.split('.')[0]+'-n2v_emb.txt' # n2v_emb.output_embedding(out_file) node_labels = graph_utils.load_node_labels(data_utils.get_node_path("lyb")) sus_best = n2v_emb.model.most_similar(positive=['23']) for item in sus_best: print(node_labels[int(item[0])], item[1]) com = list(greedy_modularity_communities(g)) node_community = {} for i, c in enumerate(com): for node in c: node_community[node_labels[node]] = i print(node_community)
network_stats(g, 'BA-Network') # WS-Network k = 20 p = 0.01 g = nx.watts_strogatz_graph(n, k, p) g = g.to_undirected() draw_degree_dist(g, k, title='WS-Network Distribution') network_stats(g, 'WS-Network') # powerlaw_cluster network m = 10 p = 1 g = nx.powerlaw_cluster_graph(n, m, p) g = g.to_undirected() draw_degree_dist(g, m, title='PC-Network Distribution') network_stats(g, 'PC-Network') # Facebook Network import os, sys projct_root_path = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(projct_root_path) import common.graph_utils as graph_utils import common.data_utils as data_utils net_file = data_utils.get_data_path("facebook") g = graph_utils.load_basic_network(net_file) g = g.to_undirected() draw_degree_dist(g, m, title='Facebook-Network Distribution') network_stats(g, 'Facebook-Network')
def main(): net_file = data_utils.get_data_path("lyb") g = graph_utils.load_basic_network(net_file) n2v_emb = node2vec.node2vec_emb(g, p=0.5, q=2, out_dim=64, num_walks=20) n2v_emb.learn_embedding()