<s> """<STR_LIT>""" <EOL> from collections import defaultdict <EOL> import networkx as nx <EOL> import numpy <EOL> from scipy . cluster import hierarchy <EOL> from scipy . spatial import distance <EOL> import matplotlib . pyplot as plt <EOL> def create_hc ( G ) : <EOL> """<STR_LIT>""" <EOL> path_length = nx . all_pairs_shortest_path_length ( G ) <EOL> distances = numpy . zeros ( ( len ( G ) , len ( G ) ) ) <EOL> for u , p in path_length . items ( ) : <EOL> for v , d in p . items ( ) : <EOL> distances [ u ] [ v ] = d <EOL> Y = distance . squareform ( distances ) <EOL> Z = hierarchy . complete ( Y ) <EOL> membership = list ( hierarchy . fcluster ( Z , t = <NUM_LIT> ) ) <EOL> partition = defaultdict ( list ) <EOL> for n , p in zip ( list ( range ( len ( G ) ) ) , membership ) : <EOL> partition [ p ] . append ( n ) <EOL> return list ( partition . values ( ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> G = nx . read_edgelist ( "<STR_LIT>" ) <EOL> H = next ( nx . connected_component_subgraphs ( G ) ) <EOL> H = nx . convert_node_labels_to_integers ( H ) <EOL> partitions = create_hc ( H ) <EOL> BM = nx . blockmodel ( H , partitions ) <EOL> pos = nx . spring_layout ( H , iterations = <NUM_LIT:100> ) <EOL> fig = plt . figure ( <NUM_LIT:1> , figsize = ( <NUM_LIT:6> , <NUM_LIT:10> ) ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> nx . draw ( H , pos , with_labels = False , node_size = <NUM_LIT:10> ) <EOL> plt . xlim ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> plt . ylim ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> node_size = [ BM . node [ x ] [ '<STR_LIT>' ] * <NUM_LIT:10> for x in BM . nodes ( ) ] <EOL> edge_width = [ ( <NUM_LIT:2> * d [ '<STR_LIT>' ] ) for ( u , v , d ) in BM . edges ( data = True ) ] <EOL> posBM = { } <EOL> for n in BM : <EOL> xy = numpy . array ( [ pos [ u ] for u in BM . node [ n ] [ '<STR_LIT>' ] ] ) <EOL> posBM [ n ] = xy . mean ( axis = <NUM_LIT:0> ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> nx . draw ( BM , posBM , node_size = node_size , width = edge_width , with_labels = False ) <EOL> plt . xlim ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> plt . ylim ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> plt . axis ( '<STR_LIT>' ) <EOL> plt . savefig ( '<STR_LIT>' ) </s>
