ó žÃÒYc@sRddlZdjddgƒZdddgZd„Zd „Zed „ZdS( iÿÿÿÿNs s%Jordi Torrents sAric Hagberg (hagberg@lanl.gov)tdegree_centralitytbetweenness_centralitytcloseness_centralitycs‘t|ƒ}t|ƒ|}dt|ƒ‰t‡fd†|j|ƒDƒƒ}dt|ƒ‰|jt‡fd†|j|ƒDƒƒƒ|S(sCompute the degree centrality for nodes in a bipartite network. The degree centrality for a node `v` is the fraction of nodes connected to it. Parameters ---------- G : graph A bipartite network nodes : list or container Container with all nodes in one bipartite node set. Returns ------- centrality : dictionary Dictionary keyed by node with bipartite degree centrality as the value. See Also -------- betweenness_centrality, closeness_centrality, sets, is_bipartite Notes ----- The nodes input parameter must conatin all nodes in one bipartite node set, but the dictionary returned contains all nodes from both bipartite node sets. See :mod:`bipartite documentation ` for further details on how bipartite graphs are handled in NetworkX. For unipartite networks, the degree centrality values are normalized by dividing by the maximum possible degree (which is `n-1` where `n` is the number of nodes in G). In the bipartite case, the maximum possible degree of a node in a bipartite node set is the number of nodes in the opposite node set [1]_. The degree centrality for a node `v` in the bipartite sets `U` with `n` nodes and `V` with `m` nodes is .. math:: d_{v} = \frac{deg(v)}{m}, \mbox{for} v \in U , d_{v} = \frac{deg(v)}{n}, \mbox{for} v \in V , where `deg(v)` is the degree of node `v`. References ---------- .. [1] Borgatti, S.P. and Halgin, D. In press. "Analyzing Affiliation Networks". In Carrington, P. and Scott, J. (eds) The Sage Handbook of Social Network Analysis. Sage Publications. http://www.steveborgatti.com/research/publications/bhaffiliations.pdf gð?c3s%|]\}}||ˆfVqdS(N((t.0tntd(ts(s~/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/centrality.pys Lsc3s%|]\}}||ˆfVqdS(N((RRR(R(s~/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/centrality.pys Ns(tsettlentdicttdegreetupdate(tGtnodesttoptbottomt centrality((Rs~/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/centrality.pyRs: %,cCsmt|ƒ}t|ƒ|}tt|ƒƒ}tt|ƒƒ}|d|}|d|}|d|dd||dd||d|d||dd}|d|} |d|} |d| dd|| dd| | d| d| | dd} tj|dtddƒ} x|D]} | | c|:` for further details on how bipartite graphs are handled in NetworkX. References ---------- .. [1] Borgatti, S.P. and Halgin, D. In press. "Analyzing Affiliation Networks". In Carrington, P. and Scott, J. (eds) The Sage Handbook of Social Network Analysis. Sage Publications. http://www.steveborgatti.com/research/publications/bhaffiliations.pdf iiig@t normalizedtweightN(RtfloatRtnxRtFalsetNone(R R RRRtmRttt bet_max_toptptrt bet_max_bott betweennesstnode((s~/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/centrality.pyRRs&H //   c Cs»i}tj}t|ƒ}t|ƒ|}tt|ƒƒ}tt|ƒƒ}x±|D]©} t||| ƒƒ} t| jƒƒ} | dkrõt|ƒdkrõ|d|d| || <|rÿt| ƒdt|ƒd} || c| 9` for further details on how bipartite graphs are handled in NetworkX. Closeness centrality is normalized by the minimum distance possible. In the bipartite case the minimum distance for a node in one bipartite node set is 1 from all nodes in the other node set and 2 from all other nodes in its own set [1]_. Thus the closeness centrality for node `v` in the two bipartite sets `U` with `n` nodes and `V` with `m` nodes is .. math:: c_{v} = \frac{m + 2(n - 1)}{d}, \mbox{for} v \in U, c_{v} = \frac{n + 2(m - 1)}{d}, \mbox{for} v \in V, where `d` is the sum of the distances from `v` to all other nodes. Higher values of closeness indicate higher centrality. As in the unipartite case, setting normalized=True causes the values to normalized further to n-1 / size(G)-1 where n is the number of nodes in the connected part of graph containing the node. If the graph is not completely connected, this algorithm computes the closeness centrality for each connected part separately. References ---------- .. [1] Borgatti, S.P. and Halgin, D. In press. "Analyzing Affiliation Networks". In Carrington, P. and Scott, J. (eds) The Sage Handbook of Social Network Analysis. Sage Publications. http://www.steveborgatti.com/research/publications/bhaffiliations.pdf giigð?(Rt"single_source_shortest_path_lengthRRRR tsumtvalues( R R Rt closenesst path_lengthRRRRRtspttotspR((s~/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/centrality.pyR±s2G    ( tnetworkxRtjoint __author__t__all__RRtTrueR(((s~/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/bipartite/centrality.pyts     C _