Yc@sKdZddlmZddlZddlmZdgZddZdS(sBAsynchronous label propagation algorithms for community detection.i(tCounterN(tgroupstasyn_lpa_communitiesc CsRdt|D}t}x|r;t}t|}tj|x|D]}t||dkrmqKnt}xG||D];}|ji|r|j ||f|nd||6qWt |j }g|j D]\} } | |kr| ^q} tj | } | ||<|p1t| dk}qKWqWtt|j S(sBReturns communities in `G` as detected by asynchronous label propagation. The asynchronous label propagation algorithm is described in [1]_. The algorithm is probabilistic and the found communities may vary on different executions. The algorithm proceeds as follows. After initializing each node with a unique label, the algorithm repeatedly sets the label of a node to be the label that appears most frequently among that nodes neighbors. The algorithm halts when each node has the label that appears most frequently among its neighbors. The algorithm is asynchronous because each node is updated without waiting for updates on the remaining nodes. This generalized version of the algorithm in [1]_ accepts edge weights. Parameters ---------- G : Graph weight : string The edge attribute representing the weight of an edge. If None, each edge is assumed to have weight one. In this algorithm, the weight of an edge is used in determining the frequency with which a label appears among the neighbors of a node: a higher weight means the label appears more often. Returns ------- communities : iterable Iterable of communities given as sets of nodes. Notes ------ Edge weight attributes must be numerical. References ---------- .. [1] Raghavan, Usha Nandini, Réka Albert, and Soundar Kumara. "Near linear time algorithm to detect community structures in large-scale networks." Physical Review E 76.3 (2007): 036106. cSsi|]\}}||qS(((t.0titn((s|/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/community/asyn_lpa.pys =s i(t enumeratetTruetFalsetlisttrandomtshuffletlenRtupdatetedgestmaxtvaluestitemstchoicetiterR( tGtweighttlabelstconttnodestnodet label_freqtvtmax_freqtlabeltfreqt best_labelst new_label((s|/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/community/asyn_lpa.pyRs(.      0  ( t__doc__t collectionsRR tnetworkx.utilsRt__all__tNoneR(((s|/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/community/asyn_lpa.pyts