+
    �°³j›2  ã                   ó  € R t ^ RIHt ^ RIt^ RIHt . ROtR tR t	R t
R]R]
R	]	/t]P                  RR
 l4       t]t]P                  ! RR7      RR l4       t]P                  R 4       t]! R4      ]P                  RR l4       4       tR tR# )z+Functions for computing clustering of pairs)ÚdefaultdictN)Únot_implemented_forc                 óP   € \        W,          4      \        W,          4      ,          # ©N)Úlen©ÚnuÚnvs   &&Úf/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/algorithms/bipartite/cluster.pyÚcc_dotr      s   € Üˆr�w‹<œ#˜b�g›,Õ&Ð&ó    c                 ój   € \        W,          4      \        \        V 4      \        V4      4      ,          # r   )r   Úmaxr   s   &&r
   Úcc_maxr      ó"   € Üˆr�w‹<œ#œc "›g¤s¨2£wÓ/Õ/Ð/r   c                 ój   € \        W,          4      \        \        V 4      \        V4      4      ,          # r   )r   Úminr   s   &&r
   Úcc_minr      r   r   Údotr   r   c           
     ó8  € \         P                  P                  P                  V 4      '       g   \         P                  ! R4      h \
        V,          pTf   T p/ pT Fˆ  pRpY,           UU	u0 uF  q€T,           F  q™kK  	  K  	  up	pT0,
          p
T
 F0  p	Ys! \        Y	,          4      \        Y,          4      4      ,          pK2  	  TR8”  d   T\        T
4      ,          pYuT&   KŠ  	  T#   \         d   p\         P                  ! R4      ThRp?ii ; iu up	pi )uB  Compute a bipartite clustering coefficient for nodes.

The bipartite clustering coefficient is a measure of local density
of connections defined as [1]_:

.. math::

   c_u = \frac{\sum_{v \in N(N(u))} c_{uv} }{|N(N(u))|}

where `N(N(u))` are the second order neighbors of `u` in `G` excluding `u`,
and `c_{uv}` is the pairwise clustering coefficient between nodes
`u` and `v`.

The mode selects the function for `c_{uv}` which can be:

`dot`:

.. math::

   c_{uv}=\frac{|N(u)\cap N(v)|}{|N(u) \cup N(v)|}

`min`:

.. math::

   c_{uv}=\frac{|N(u)\cap N(v)|}{min(|N(u)|,|N(v)|)}

`max`:

.. math::

   c_{uv}=\frac{|N(u)\cap N(v)|}{max(|N(u)|,|N(v)|)}


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

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

mode : string
    The pairwise bipartite clustering method to be used in the computation.
    It must be "dot", "max", or "min".

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


Examples
--------
>>> 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
average_clustering
networkx.algorithms.cluster.square_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.
zGraph is not bipartitez6Mode for bipartite clustering must be: dot, min or maxNg        )	ÚnxÚ
algorithmsÚ	bipartiteÚis_bipartiteÚNetworkXErrorÚmodesÚKeyErrorÚsetr   )ÚGÚnodesÚmodeÚcc_funcÚerrÚccsÚvÚccÚnbrÚuÚnbrs2s   &&&        r
   Úlatapy_clusteringr)       s  € ô\ �=‰=×"Ñ"×/Ñ/°×2Ò2Ü×ÒÐ7Ó8Ð8ðÜ˜•+ˆð ‚}ØˆØ
€CÛˆØˆØždÔ3™d�s¨c¯F¨F q’©F‘™dÒ3°q°cÕ9ˆÛˆAØ�'œ#˜a�d›)¤S¨­£YÓ/Õ/ŠBñ à�Œ8Ø”#�e“*ÕˆBØˆA‹ñ ð €Jøô! ô Ü×ÒØDó
àð	ûðüó 4s   ÁC, Á.DÃ,DÃ7DÄDÚbipartite_average_clustering)Únamec                ót   a€ Vf   T p\        WVR7      o\        V3R lV 4       4      \        V4      ,          # )u°  Compute 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 pairwise 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 <networkx.algorithms.bipartite>`
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.
)r   r    c              3   ó6   <"  € T F  pSV,          x € K  	  R # 5ir   © )Ú.0r$   r#   s   & €r
   Ú	<genexpr>Ú%average_clustering.<locals>.<genexpr>Ó   s   øé € Ð%™u˜!ˆs�1�vŠv›uùs   ƒ)r)   Úsumr   )r   r   r    r#   s   &&&@r
   Úaverage_clusteringr3   ‰   s6   ø€ ðN ‚}ØˆÜ
˜A°Ô
6€CÜÔ%™uÓ%Ó%¬¨E«
Õ2Ð2r   c                óÔ   € V P                  4       ^8  g   V P                  4       ^8  d   ^ # \        V 4      pV^ 8X  d   ^ # \        \	        V 4      P                  4       4      V,          # )uÐ  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}

The four cycles counted here are *butterflies* (also called *squares*
or *four-cycles* in other contexts)  â€” complete bipartite
subgraphs K_{2,2} where alternating nodes belong to different
partitions.  See :func:`butterflies` for per-node butterfly counts.

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
--------
butterflies : per-node butterfly (four-cycle) counts
latapy_clustering
networkx.algorithms.cluster.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.

)ÚorderÚsizeÚ_threepathsr2   ÚbutterfliesÚvalues)r   ÚL_3s   & r
   Úrobins_alexander_clusteringr;   Ö   sQ   € ð^ 	‡w�wƒy�1„}˜Ÿ™› 1œÙÜ
�a‹.€CØ
ˆa„xÙäŒ{˜1‹~×$Ñ$Ó&Ó'¨#Õ-Ð-r   Údirectedc           	     ó–  € V P                  4       ^ 8X  dR   \        P                  V P                  4       ^ 4      pVf   V# V P	                  V4       Uu/ uF  q3W#,          bK  	  up# \        V P                  4       4       UUUu/ uF  w  pw  rVWVV3bK  	  ppppV  Uu/ uF)  q3\        V P                  V4      VP                  R7      bK+  	  pp\        P                  V ^ 4      p	V  EF  p
Wz,          p\        \        4      p\        \        4      pWŠ,           F\  pWs,          V8¼  d    MNWƒ,           F>  pW~,          V8¼  d    K-  WÎ;;,          ^,          uu&   WÞ,          P                  V4       K@  	  K^  	  VP                  4        Fv  w  rïV^8  d   K  Wÿ^,
          ,          ^,          pWš;;,          V,          uu&   Wž;;,          V,          uu&   WÞ,           F  pW“;;,          V^,
          ,          uu&   K   	  Kx  	  EK  	  Vf   V	# V P	                  V4       Uu/ uF  q3W“,          bK  	  up# u upi u upppi u upi u upi )u  Count the number of butterflies for each node in a bipartite graph.

A *butterfly* is a complete bipartite subgraph K_{2,2} â€” four nodes
(two from each partition) with all four cross-edges present.  It is
the bipartite analogue of a triangle in unipartite graphs.

.. code-block:: none

    A1   A2
    | \ / |
    |  X  |
    | / \ |
    B1   B2

Equivalently, a butterfly is a 4-cycle (C_4) in which alternating
nodes belong to different partitions of the bipartite graph.
This structure is also called a *square* in the physics and
complex-networks literature [3]_, and a *four-cycle* in the
sociology literature [4]_.  The name *butterfly* is standard in
the data-mining and bipartite-network literature [1]_ [2]_.

Parameters
----------
G : NetworkX graph
    An undirected bipartite graph.
nodes : iterable of nodes, optional (default: all nodes)
    Return butterfly counts only for these nodes.  The computation
    always uses the full graph; ``nodes`` only filters the returned
    dictionary (same convention as :func:`~networkx.triangles`).
    When ``None`` (default), counts for all nodes are returned.
    Nodes not present in `G` are silently ignored.

Returns
-------
butterflies : dict
    A dictionary keyed by node to the number of butterflies that
    node participates in.  Each butterfly is counted once per
    participating node, so::

        sum(butterflies(G).values()) == 4 * total_butterfly_count

Examples
--------
A single K_{2,2} contains exactly one butterfly, and each of its
four nodes participates in that butterfly:

>>> G = nx.complete_bipartite_graph(2, 2)
>>> nx.bipartite.butterflies(G)
{0: 1, 1: 1, 2: 1, 3: 1}

The total number of butterflies is the sum divided by 4:

>>> bt = nx.bipartite.butterflies(G)
>>> sum(bt.values()) // 4
1

K_{3,3} contains nine butterflies; every node participates in six:

>>> G2 = nx.complete_bipartite_graph(3, 3)
>>> bt2 = nx.bipartite.butterflies(G2)
>>> sum(bt2.values()) // 4
9

Nodes not in any butterfly receive count zero:

>>> G = nx.complete_bipartite_graph(2, 2)
>>> G.add_edge(0, 5)
>>> nx.bipartite.butterflies(G)
{0: 1, 1: 1, 2: 1, 3: 1, 5: 0}

Notes
-----
This algorithm uses wedge enumerate to count butterflies.
The wedge enumeration method uses the vertex-priority of BFC-VP [2]_ :
nodes are ranked by degree, neighbor lists are
pre-sorted by ascending rank, and for each start node ``u`` only
neighbors with lower rank are processed as middle and end nodes,
with early termination on the sorted lists.  This gives time
complexity :math:`O\!\bigl(\sum_{(u,v)\in E} \min(d(u), d(v))\bigr)
= O(\alpha m)` where :math:`\alpha` is the arboricity, i.e. the minimum
number of forests into which $E$ can be partitioned, and :math:`m`
the number of edges.

The per-node attribution (distributing butterfly credits to start,
middle, and end nodes) is an extension of BFC-VP not present in the
original paper, which computes only a global count.

See Also
--------
robins_alexander_clustering : graph-level bipartite clustering
    coefficient whose numerator is ``4 * total butterfly count``.
networkx.algorithms.cluster.square_clustering : per-node square
    clustering coefficient for general graphs.

References
----------
.. [1] Sanei-Mehri, S. V., Sariyuce, A. E., & Tirthapura, S.
   (2018).  Butterfly counting in bipartite networks.
   *Proceedings of the 24th ACM SIGKDD*, 2150â€“2159.
   https://doi.org/10.1145/3219819.3220097

.. [2] Wang, K., Lin, X., Qin, L., Zhang, W., & Zhang, Y. (2023).
   Accelerated butterfly counting with vertex priority on bipartite
   graphs.  *The VLDB Journal*, 32, 257â€“281.
   https://doi.org/10.1007/s00778-022-00746-0

.. [3] Lind, P. G., Gonzalez, M. C., & Herrmann, H. J. (2005).
   Cycles and clustering in bipartite networks.
   *Physical Review E*, 72, 056127.
   https://doi.org/10.1103/PhysRevE.72.056127

.. [4] 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.
   https://doi.org/10.1023/B:CMOT.0000032580.12184.c0
)Úkey)Únumber_of_edgesÚdictÚfromkeysr   Únbunch_iterÚ	enumerateÚdegreeÚsortedÚ	neighborsÚ__getitem__r   ÚintÚlistÚappendÚitems)r   r   Úresultr$   ÚiÚnÚdegÚpriorityÚsorted_nbrsÚ_btr'   ÚpuÚwedge_countÚ	wedge_midÚwÚkÚbfs   &&               r
   r8   r8     sá  € ðn 	×ÑÓ˜aÔÜ—‘˜qŸw™w›y¨!Ó,ˆØŠ=ØˆMØ&'§m¡m°EÔ&:Ó;Ñ&: �6•9’Ñ&:Ñ;Ð;ä/8¸¿¹»Ô/DÕEÑ/D¡ ¡8 A�˜�8’Ñ/D€HÒEáPQÓRÑPQÈ1”f˜QŸ[™[¨›^°×1EÑ1EÔFÒFÑPQ€KÐRä
�-‰-˜˜1Ó
€CäˆØ�[ˆÜ!¤#Ó&ˆÜ¤Ó%ˆ	à—�ˆAØ�{˜bÔ ÙØ —^�^�Ø•; "Ô$ÚØ— !Õ#“Ø•×#Ñ# AÖ&ó	 $ñ  ð  ×%Ñ%Ö'‰DˆAØ�1ŒuÙà˜!•e• Õ!ˆBØ�F�b�L‹FØ�F�b�L‹FØ—\�\�à—˜!˜a�%••ó "ô (ñ ð0 ‚}Øˆ
Ø Ÿ}™}¨UÔ3Ó4Ñ3˜!ˆs�vŠIÑ3Ñ4Ð4ùòE <ùäEùâRùò< 5s   ÁH5ÂH:Â/IÈ!Ic           
      óÚ   € ^ pV  F[  pW,           FL  p\        W,          4      V0,
           F,  pV\        \        W,          4      W#0,
          4      ,          pK.  	  KN  	  K]  	  V^,          # )é    )r   r   )r   Úpathsr$   r'   rV   s   &    r
   r7   r7   ®  s_   € Ø€EÛˆØ—�ˆAÜ˜�“Y ! —_�_�ØœœS ¥›Y¨!¨Õ/Ó0Õ0’ó %ó ñ ð �1�9Ðr   )Ú
clusteringr3   r)   r;   r8   )Nr   r   )Ú__doc__Úcollectionsr   Únetworkxr   Únetworkx.utils.decoratorsr   Ú__all__r   r   r   r   Ú_dispatchabler)   r\   r3   r;   r8   r7   r.   r   r
   Ú<module>rc      sÌ   ðÙ 1å #ã Ý 9ò€ò'ò0ò0ð 
�˜˜v u¨fÐ5€ð ×Ñóbó ðbðJ €
ð ×ÒÐ5Ô6óI3ó 7ðI3ðX ×Ññ4.ó ð4.ñn �ZÓ Ø×Ñó[5ó ó !ð[5ô|r   