ó žÃÒYc@s¸ddlZddlZdjddgƒZddddgZd „Zd „Zd „Zied 6ed 6ed6Z dd d„Z e Z dd d„Z d„Zd„Zd„ZdS(iÿÿÿÿNs s%Jordi Torrents sAric Hagberg (hagberg@lanl.gov)t clusteringtaverage_clusteringtlatapy_clusteringtrobins_alexander_clusteringcCs"tt||@ƒƒt||BƒS(N(tfloattlen(tnutnv((s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/cluster.pytcc_dotscCs-tt||@ƒƒtt|ƒt|ƒƒS(N(RRtmax(RR((s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/cluster.pytcc_maxscCs-tt||@ƒƒtt|ƒt|ƒƒS(N(RRtmin(RR((s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/cluster.pytcc_minstdotR R c Cs0tjjj|ƒs'tjdƒ‚nyt|}Wn tk rWtjdƒ‚nX|dkrm|}ni}x¶|D]®}d}tg||D]}||D] }|^q¢q”ƒt|gƒ} x5| D]-}||t||ƒt||ƒƒ7}qÎW|dkr|t | ƒ:}n|||>> from networkx.algorithms import bipartite >>> G = nx.path_graph(4) # path graphs are bipartite >>> c = bipartite.clustering(G) >>> c[0] 0.5 >>> c = bipartite.clustering(G,mode='min') >>> c[0] 1.0 See Also -------- robins_alexander_clustering square_clustering average_clustering References ---------- .. [1] Latapy, Matthieu, Clémence Magnien, and Nathalie Del Vecchio (2008). Basic notions for the analysis of large two-mode networks. Social Networks 30(1), 31--48. sGraph is not bipartites6Mode for bipartite clustering must be: dot, min or maxgN( tnxt algorithmst bipartitet is_bipartitet NetworkXErrortmodestKeyErrortNonetsetR( tGtnodestmodetcc_functccstvtcctnbrtutnbrs2((s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/cluster.pyRs&M     A + csW|dkr|}nt|d|d|ƒ‰tt‡fd†|Dƒƒƒt|ƒS(sCompute the average bipartite clustering coefficient. A clustering coefficient for the whole graph is the average, .. math:: C = \frac{1}{n}\sum_{v \in G} c_v, where `n` is the number of nodes in `G`. Similar measures for the two bipartite sets can be defined [1]_ .. math:: C_X = \frac{1}{|X|}\sum_{v \in X} c_v, where `X` is a bipartite set of `G`. Parameters ---------- G : graph a bipartite graph nodes : list or iterable, optional A container of nodes to use in computing the average. The nodes should be either the entire graph (the default) or one of the bipartite sets. mode : string The pariwise bipartite clustering method. It must be "dot", "max", or "min" Returns ------- clustering : float The average bipartite clustering for the given set of nodes or the entire graph if no nodes are specified. Examples -------- >>> from networkx.algorithms import bipartite >>> G=nx.star_graph(3) # star graphs are bipartite >>> bipartite.average_clustering(G) 0.75 >>> X,Y=bipartite.sets(G) >>> bipartite.average_clustering(G,X) 0.0 >>> bipartite.average_clustering(G,Y) 1.0 See Also -------- clustering Notes ----- The container of nodes passed to this function must contain all of the nodes in one of the bipartite sets ("top" or "bottom") in order to compute the correct average bipartite clustering coefficients. See :mod:`bipartite documentation ` for further details on how bipartite graphs are handled in NetworkX. References ---------- .. [1] Latapy, Matthieu, Clémence Magnien, and Nathalie Del Vecchio (2008). Basic notions for the analysis of large two-mode networks. Social Networks 30(1), 31--48. RRc3s|]}ˆ|VqdS(N((t.0R(R(s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/cluster.pys ÌsN(RRRtsumR(RRR((Rs{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/cluster.pyRƒsF  cCs\|jƒdks$|jƒdkr(dSt|ƒ}|dkrDdSt|ƒ}d||S(súCompute the bipartite clustering of G. Robins and Alexander [1]_ defined bipartite clustering coefficient as four times the number of four cycles `C_4` divided by the number of three paths `L_3` in a bipartite graph: .. math:: CC_4 = \frac{4 * C_4}{L_3} Parameters ---------- G : graph a bipartite graph Returns ------- clustering : float The Robins and Alexander bipartite clustering for the input graph. Examples -------- >>> from networkx.algorithms import bipartite >>> G = nx.davis_southern_women_graph() >>> print(round(bipartite.robins_alexander_clustering(G), 3)) 0.468 See Also -------- latapy_clustering square_clustering References ---------- .. [1] Robins, G. and M. Alexander (2004). Small worlds among interlocking directors: Network structure and distance in bipartite graphs. Computational & Mathematical Organization Theory 10(1), 69–94. iiig@(tordertsizet _threepathst _four_cycles(RtL_3tC_4((s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/cluster.pyRÎs($   cCs{d}xj|D]b}xYtj||dƒD]A\}}|tt||ƒt||ƒ@t|gƒƒ7}q*Wq W|dS(Niii(t itertoolst combinationsRR(RtcyclesRRtw((s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/cluster.pyR&þs  #=c Cs†d}xu|D]m}xd||D]X}xOt||ƒt|gƒD]0}|tt||ƒt||gƒƒ7}qBWqWq W|dS(Nii(RR(RtpathsRRR,((s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/cluster.pyR%s  $6(R)tnetworkxRtjoint __author__t__all__RR R RRRRRRR&R%(((s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/cluster.pyts&          cK 0