+
    �°³j  ã                   ó^   € R t ^ RIHt ^ RIt^ RIHt R.t]P                  RR l4       tR t	R# )z%Node redundancy for bipartite graphs.)ÚcombinationsN)ÚNetworkXErrorÚnode_redundancyc                óè   a € Vf   S p\         ;QJ d    V 3R lV 4       F  '       g   K   RM	  RM! V 3R lV 4       4      '       d   \        R4      hV Uu/ uF  q"\        S V4      bK  	  up# u upi )u�  Computes the node redundancy coefficients for the nodes in the bipartite
graph `G`.

The redundancy coefficient of a node `v` is the fraction of pairs of
neighbors of `v` that are both linked to other nodes. In a one-mode
projection these nodes would be linked together even if `v` were
not there.

More formally, for any vertex `v`, the *redundancy coefficient of `v`* is
defined by

.. math::

    rc(v) = \frac{|\{\{u, w\} \subseteq N(v),
    \: \exists v' \neq  v,\: (v',u) \in E\:
    \mathrm{and}\: (v',w) \in E\}|}{ \frac{|N(v)|(|N(v)|-1)}{2}},

where `N(v)` is the set of neighbors of `v` in `G` [1]_.

Parameters
----------
G : graph
    A bipartite graph

nodes : list or iterable (optional)
    Compute redundancy for these nodes. The default is all nodes in G.

Returns
-------
redundancy : dictionary
    A dictionary keyed by node with the node redundancy value.

Examples
--------
Compute the redundancy coefficient of each node in a graph:

>>> from networkx.algorithms import bipartite
>>> G = nx.cycle_graph(4)
>>> rc = bipartite.node_redundancy(G)
>>> rc[0]
1.0

Compute the average redundancy for the graph:

>>> from networkx.algorithms import bipartite
>>> G = nx.cycle_graph(4)
>>> rc = bipartite.node_redundancy(G)
>>> sum(rc.values()) / len(G)
1.0

Compute the average redundancy for a set of nodes:

>>> from networkx.algorithms import bipartite
>>> G = nx.cycle_graph(4)
>>> rc = bipartite.node_redundancy(G)
>>> nodes = [0, 2]
>>> sum(rc[n] for n in nodes) / len(nodes)
1.0

Raises
------
NetworkXError
    If any of the nodes in the graph (or in `nodes`, if specified) has
    (out-)degree less than two (which would result in division by zero,
    according to the definition of the redundancy coefficient).

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.

c              3   óN   <"  € T F  p\        SV,          4      ^8  x € K  	  R# 5i)é   N)Úlen)Ú.0ÚvÚGs   & €Úi/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/algorithms/bipartite/redundancy.pyÚ	<genexpr>Ú"node_redundancy.<locals>.<genexpr>X   s   øé € Ð
(¡%˜QŒ3ˆq��t‹9�qŽ=£%ùs   ƒ"%TFzSCannot compute redundancy coefficient for a node that has fewer than two neighbors.)Úanyr   Ú_node_redundancy)r   Únodesr
   s   f& r   r   r      sh   ø€ ðV ‚}Øˆß
ƒsÔ
(¡%Ó
(‡s‡s‚sÔ
(¡%Ó
(×(Ò(Üð2ó
ð 	
ñ
 05Ó5©u¨!Ô  1Ó%Ò%©uÑ5Ð5ùÒ5s   ÁA/c                ó²   a a€ \        S S,          4      p\        V V3R l\        S S,          ^4       4       4      p^V,          W"^,
          ,          ,          # )a�  Returns the redundancy of the node `v` in the bipartite graph `G`.

If `G` is a graph with `n` nodes, the redundancy of a node is the ratio
of the "overlap" of `v` to the maximum possible overlap of `v`
according to its degree. The overlap of `v` is the number of pairs of
neighbors that have mutual neighbors themselves, other than `v`.

`v` must have at least two neighbors in `G`.

c              3   óž   <"  € T FB  w  r\        SV,          4      \        SV,          4      ,          S0,
          '       g   K>  ^x € KD  	  R# 5i)é   N)Úset)r	   ÚuÚwr   r
   s   &  €€r   r   Ú#_node_redundancy.<locals>.<genexpr>m   s:   øé € ð Ù-‰fˆq´#°a¸µd³)¼cÀ!ÀAÅ$»iÕ2GÈAÈ3×1NÑ1N�ŠÓ-ùs   ƒ;AÁ
A)r   Úsumr   )r   r
   ÚnÚoverlaps   ff  r   r   r   a   sK   ù€ ô 	ˆAˆa�D‹	€AÜõ Ü$ Q q¥T¨1Ô-óó €Gð ��K˜A Q¥�KÕ(Ð(ó    )N)
Ú__doc__Ú	itertoolsr   ÚnetworkxÚnxr   Ú__all__Ú_dispatchabler   r   © r   r   Ú<module>r$      s;   ðÙ +å "ã Ý "àÐ
€ð ×ÑóR6ó ðR6ôj)r   