def asyn_lpa_communities(G, weight=None):
 labels = {n: i for (i, n) in enumerate(G)}
 cont = True
 while cont:
  cont = False
  nodes = list(G)
  random.shuffle(nodes)
  for node in nodes:
   if (len(G[node]) < 1):
    continue
   label_freq = Counter()
   for v in G[node]:
    label_freq.update({labels[v]: (G.edge[v][node][weight] if weight else 1)})
   max_freq = max(label_freq.values())
   best_labels = [label for (label, freq) in label_freq.items() if (freq == max_freq)]
   new_label = random.choice(best_labels)
   labels[node] = new_label
   cont = (cont or (len(best_labels) > 1))
 return iter(groups(labels).values())

def asyn_lpa_communities ( G , weight = None ) : labels = { n : i for ( i , n ) in enumerate ( G ) } cont = True while cont : cont = False nodes = list ( G ) random . shuffle ( nodes ) for node in nodes : if ( len ( G [ node ] ) < 1 ) : continue label_freq = Counter ( ) for v in G [ node ] : label_freq . update ( { labels [ v ] : ( G . edge [ v ] [ node ] [ weight ] if weight else 1 ) } ) max_freq = max ( label_freq . values ( ) ) best_labels = [ label for ( label , freq ) in label_freq . items ( ) if ( freq == max_freq ) ] new_label = random . choice ( best_labels ) labels [ node ] = new_label cont = ( cont or ( len ( best_labels ) > 1 ) ) return iter ( groups ( labels ) . values ( ) )
returns communities in g as detected by asynchronous label propagation .