<s> import networkx as nx <EOL> import csv <EOL> import pylab as plt <EOL> nyc_net = nx . read_edgelist ( <EOL> '<STR_LIT>' , create_using = nx . DiGraph ( ) , nodetype = int ) <EOL> node_data = { } <EOL> with open ( '<STR_LIT>' ) as csvfile : <EOL> reader = csv . DictReader ( csvfile ) <EOL> for row in reader : <EOL> latit = float ( row [ '<STR_LIT>' ] ) <EOL> longit = float ( row [ '<STR_LIT>' ] ) <EOL> place_title = row [ '<STR_LIT:title>' ] <EOL> node_id = int ( row [ '<STR_LIT>' ] ) <EOL> node_data [ node_id ] = ( place_title , latit , longit ) <EOL> N , K = nyc_net . order ( ) , nyc_net . size ( ) <EOL> avg_deg = float ( K ) / N <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % N ) <EOL> print ( "<STR_LIT>" % K ) <EOL> print ( "<STR_LIT>" % avg_deg ) <EOL> in_degrees = nyc_net . in_degree ( ) <EOL> in_values = sorted ( set ( in_degrees . values ( ) ) ) <EOL> in_hist = [ list ( in_degrees . values ( ) ) . count ( x ) for x in in_values ] <EOL> out_degrees = nyc_net . out_degree ( ) <EOL> out_values = sorted ( set ( out_degrees . values ( ) ) ) <EOL> out_hist = [ list ( out_degrees . values ( ) ) . count ( x ) for x in out_values ] <EOL> logScale = True <EOL> plt . figure ( ) <EOL> if logScale : <EOL> plt . loglog ( in_values , in_hist , '<STR_LIT>' ) <EOL> plt . loglog ( out_values , out_hist , '<STR_LIT>' ) <EOL> else : <EOL> plt . plot ( in_values , in_hist , '<STR_LIT>' ) <EOL> plt . plot ( out_values , out_hist , '<STR_LIT>' ) <EOL> plt . legend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> plt . xlabel ( '<STR_LIT>' ) <EOL> plt . ylabel ( '<STR_LIT>' ) <EOL> plt . title ( '<STR_LIT>' ) <EOL> plt . grid ( True ) <EOL> if logScale : <EOL> plt . xlim ( [ <NUM_LIT:0> , <NUM_LIT:2> * <NUM_LIT:10> ** <NUM_LIT:2> ] ) <EOL> plt . savefig ( '<STR_LIT>' ) <EOL> else : <EOL> plt . savefig ( '<STR_LIT>' ) <EOL> plt . close ( ) <EOL> pos_dict = { } <EOL> for node_id , node_info in node_data . items ( ) : <EOL> pos_dict [ node_id ] = ( node_info [ <NUM_LIT:2> ] , node_info [ <NUM_LIT:1> ] ) <EOL> nx . draw ( nyc_net , pos = pos_dict , with_labels = False , node_size = <NUM_LIT:20> ) <EOL> plt . savefig ( '<STR_LIT>' ) <EOL> plt . close ( ) <EOL> nyc_net_ud = nyc_net . to_undirected ( ) <EOL> nyc_net_components = nx . connected_component_subgraphs ( nyc_net_ud ) <EOL> nyc_net_mc = next ( nyc_net_components ) <EOL> N_mc , K_mc = nyc_net_mc . order ( ) , nyc_net_mc . size ( ) <EOL> avg_deg_mc = float ( <NUM_LIT:2> * K_mc ) / N_mc <EOL> avg_clust = nx . average_clustering ( nyc_net_mc ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % N_mc ) <EOL> print ( "<STR_LIT>" % K_mc ) <EOL> print ( "<STR_LIT>" % avg_deg_mc ) <EOL> print ( "<STR_LIT>" % avg_clust ) <EOL> bet_cen = nx . betweenness_centrality ( nyc_net_mc ) <EOL> deg_cen = nx . degree_centrality ( nyc_net_mc ) <EOL> eig_cen = nx . eigenvector_centrality ( nyc_net_mc ) <EOL> def getTopDictionaryKeys ( dictionary , number ) : <EOL> topList = [ ] <EOL> a = dict ( dictionary ) <EOL> for i in range ( <NUM_LIT:0> , number ) : <EOL> m = max ( a , key = a . get ) <EOL> topList . append ( [ m , a [ m ] ] ) <EOL> del a [ m ] <EOL> return topList <EOL> top_bet_cen = getTopDictionaryKeys ( bet_cen , <NUM_LIT:10> ) <EOL> top_deg_cen = getTopDictionaryKeys ( deg_cen , <NUM_LIT:10> ) <EOL> top_eig_cent = getTopDictionaryKeys ( eig_cen , <NUM_LIT:10> ) <EOL> print ( '<STR_LIT>' ) <EOL> for [ node_id , value ] in top_bet_cen : <EOL> title = node_data [ node_id ] [ <NUM_LIT:0> ] <EOL> print ( title ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> for [ node_id , value ] in top_deg_cen : <EOL> title = node_data [ node_id ] [ <NUM_LIT:0> ] <EOL> print ( title ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> for [ node_id , value ] in top_eig_cent : <EOL> title = node_data [ node_id ] [ <NUM_LIT:0> ] <EOL> print ( title ) <EOL> print ( '<STR_LIT>' ) </s>
