def main(args): ''' Pipeline for representational learning for all nodes in a graph. ''' # nx_G = read_graph() nx_G = nt.load_network('fed', 'net') nx_G = nt.get_gaint_comp(nx_G) G = node2vec.Graph(nx_G, args.directed, args.p, args.q) G.preprocess_transition_probs() walks = G.simulate_walks(args.num_walks, args.walk_length) learn_embeddings(walks)
def network_stat(dbname, comname, fnetname, bnetname): db = dbt.db_connect_no_auth(dbname) com = db[comname] G = nt.load_network(dbname, fnetname) # print G.number_of_nodes() BG = nt.load_behavior_network(dbname, bnetname, 'retweet') close_cen = nt.closeness_centrality(G) # normalized=True between_cen = nt.betweenness_centrality(G, weight='weight') # normalized=True, weight=None eigen_cen = nt.eigenvector_centrality_numpy(G) # weight='weight' kt_cen = nt.katz_centrality_numpy(G) # normalized=True, weight='weight' diff_cen = nt.diffusion_centrality(BG, G) indegree_all = sum(G.in_degree().values()) outdegree_all = sum(G.out_degree().values()) close_cen_all = sum(close_cen.values()) between_cen_all = sum(between_cen.values()) eigen_cen_all = sum(eigen_cen.values()) kt_cen_all = sum(kt_cen.values()) diff_cen_all = sum([diff_cen[item][0] for item in diff_cen]) goss_all = sum([diff_cen[item][1] for item in diff_cen]) for v in G.nodes(): values = com.find_one({'id': v}, ['id', 'net_anal']).get('net_anal', {'mined': True}) net_sta = {} net_sta['node_no'] = G.number_of_nodes() net_sta['indegree'] = G.in_degree(v) net_sta['indegree_all'] = indegree_all net_sta['outdegree'] = G.out_degree(v) net_sta['outdegree_all'] = outdegree_all net_sta['closeness_centrality'] = close_cen[v] net_sta['closeness_centrality_all'] = close_cen_all net_sta['betweenness_centrality'] = between_cen[v] net_sta['betweenness_centrality_all'] = between_cen_all net_sta['eigenvector_centrality'] = eigen_cen[v] net_sta['eigenvector_centrality_all'] = eigen_cen_all net_sta['katz_centrality'] = kt_cen[v] net_sta['katz_centrality_all'] = kt_cen_all net_sta['diffusion_centrality'] = diff_cen.get(v, [0.0, 0.0])[0] net_sta['diffusion_centrality_all'] = diff_cen_all net_sta['gossip'] = diff_cen.get(v, [0.0, 0.0])[1] net_sta['gossip_all'] = goss_all values['friendship_net'] = net_sta com.update_one({'id': v}, {'$set': {'net_anal': values}}, upsert=True)