+
    �°³jÐ  ã                   ó
  € R t ^ RIt^ RIHt . R	Ot]! R4      ]P                  ! RR7      R
R l4       4       t]! R4      ]P                  ! RR7      R
R l4       4       t]! R4      ]P                  ! RR7      RR l4       4       t	R# )zTrophic levelsN)Únot_implemented_forÚ
undirectedÚweight)Ú
edge_attrsc                ór  € V P                    UUu. uF  w  r#V^ 8X  g   K  VNK  	  pppV'       g   \        P                  ! R4      h\        P                  ! WR7       UUu0 uF  qU F  qfkK  	  K  	  ppp\	        V4      \	        V P
                  4      8w  d   \        P                  ! R4      h^ RIp\        P                  ! WR7      P                  P                  4       p	VP                  V	^R7      p
Wš^ 8g  ,          RV
^ 8g  3,          pWºV
^ 8g  ,          RVP                  3,          ,          pVP                  ^ ,          pVP                  V4      p VP                  P                  WÛ,
          4      pTP                  ^R7      ^,           p/ pR T P                    4       pT F  p^TT&   K
  	  R	 T P                    4       p\#        T4       F  w  ppTP%                  T4      TT&   K  	  T# u uppi u uppi   TP                  P                    d   pRp\        P                  ! T4      ThRp?ii ; i)
aB  Compute the trophic levels of nodes.

The trophic level of a node $i$ is

.. math::

    s_i = 1 + \frac{1}{k^{in}_i} \sum_{j} a_{ij} s_j

where $k^{in}_i$ is the in-degree of i

.. math::

    k^{in}_i = \sum_{j} a_{ij}

and nodes with $k^{in}_i = 0$ have $s_i = 1$ by convention.

These are calculated using the method outlined in Levine [1]_.

Parameters
----------
G : DiGraph
    A directed networkx graph

Returns
-------
nodes : dict
    Dictionary of nodes with trophic level as the value.

References
----------
.. [1] Stephen Levine (1980) J. theor. Biol. 83, 195-207
z|This graph has no basal nodes (nodes with no incoming edges).Trophic levels are not defined without at least one basal node.)ÚsourceszˆTrophic levels are only defined for graphs where every node has a path from a basal node (basal nodes are nodes with no incoming edges).N©r   )Úaxis:NNNc              3   ó<   "  € T F  w  rV^ 8X  g   K  Vx € K  	  R# 5i©é    N© ©Ú.0Únode_idÚdegrees   &  Úg/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/algorithms/centrality/trophic.pyÚ	<genexpr>Ú!trophic_levels.<locals>.<genexpr>[   s   é € ÐO±K¡ À6ÈQÁ;—W’W³Kùó   ‚’
c              3   ó<   "  € T F  w  rV^ 8w  g   K  Vx € K  	  R# 5ir   r   r   s   &  r   r   r   `   s   é € ÐR±{¡O GÀfÐPQÁkŸš³{ùr   )Ú	in_degreeÚnxÚNetworkXErrorÚ
bfs_layersÚlenÚnodesÚnumpyÚadjacency_matrixÚTÚtoarrayÚsumÚnewaxisÚshapeÚeyeÚlinalgÚinvÚLinAlgErrorÚ	enumerateÚitem)ÚGr   ÚnÚdegÚbasal_nodesÚlayerÚnodeÚreachable_nodesÚnpÚaÚrowsumÚpÚnnÚiÚerrÚmsgÚyÚlevelsÚzero_node_idsr   Únonzero_node_idss   &&                   r   Útrophic_levelsr=   	   s  € ðH $%§;¢;Ô;¡;™˜°#¸±(—1�1¡;€KÑ;ßÜ×ÒðNó
ð 	
ô Ÿ-š-¨Õ?ôÙ?�ÊEÀDŠÉE‰Ñ?ð ñ ô ˆ?Óœs 1§7¡7›|Ô+Ü×ÒðPó
ð 	
ó
 ô 	×Ò˜AÔ-×/Ñ/×7Ñ7Ó9€Að �V‰V�A˜AˆVÓ€FØ	�A‰+��q˜& A™+�~Õ&€Aà	�6˜Q‘;Õ  2§:¡: Õ.Õ.€Að 
�‰��€BØ
�‰ˆr‹
€Að	-Ø�I‰I�M‰M˜!�%Ó ˆð 	
�‰�1ˆ‹˜Õ€Aà€Fñ P°A·K²KÓO€MÛ ˆØˆˆw‹ñ !ñ S°q·{²{ÓRÐÜÐ 0Ö1‰
ˆˆ7ØŸ&™& ›)ˆˆw‹ñ 2ð €Mùóo <ùóøð4 �9‰9× Ñ ô -ð)ð 	ô
 ×Ò˜sÓ#¨Ð,ûð-ús(   �G1 G1Á!G7Å!G= Ç=H6ÈH1È1H6c                ó~   € \        WR7      p/ pV P                   F  w  rEW%,          W$,          ,
          W4V3&   K   	  V# )a+  Compute the trophic differences of the edges of a directed graph.

The trophic difference $x_ij$ for each edge is defined in Johnson et al.
[1]_ as:

.. math::
    x_ij = s_j - s_i

Where $s_i$ is the trophic level of node $i$.

Parameters
----------
G : DiGraph
    A directed networkx graph

Returns
-------
diffs : dict
    Dictionary of edges with trophic differences as the value.

References
----------
.. [1] Samuel Johnson, Virginia Dominguez-Garcia, Luca Donetti, Miguel A.
    Munoz (2014) PNAS "Trophic coherence determines food-web stability"
r   )r=   Úedges)r*   r   r:   ÚdiffsÚuÚvs   &&    r   Útrophic_differencesrC   g   s<   € ô8 ˜AÔ-€FØ€EØ—”‰ˆØ�	 F¥IÕ-ˆ�!ˆf‹ñ à€Ló    c                óD  € ^ RI pV'       d   \        WR7      pMW\        \        P                  ! V 4      4      pV'       d#   V P                  4       pVP                  V4       MT p\        WaR7      p\        VP                  \        VP                  4       4      4      4      # )aß  Compute the trophic incoherence parameter of a graph.

Trophic coherence is defined as the homogeneity of the distribution of
trophic distances: the more similar, the more coherent. This is measured by
the standard deviation of the trophic differences and referred to as the
trophic incoherence parameter $q$ by [1].

Parameters
----------
G : DiGraph
    A directed networkx graph

cannibalism: Boolean
    If set to False, self edges are not considered in the calculation

Returns
-------
trophic_incoherence_parameter : float
    The trophic coherence of a graph

References
----------
.. [1] Samuel Johnson, Virginia Dominguez-Garcia, Luca Donetti, Miguel A.
    Munoz (2014) PNAS "Trophic coherence determines food-web stability"
Nr   )
r   rC   Úlistr   Úselfloop_edgesÚcopyÚremove_edges_fromÚfloatÚstdÚvalues)r*   r   Úcannibalismr1   r@   Ú
self_loopsÚG_2s   &&&    r   Útrophic_incoherence_parameterrP   Š   sw   € ó8 çÜ# AÔ5‰ô œ"×+Ò+¨AÓ.Ó/ˆ
ßà—&‘&“(ˆCØ×!Ñ! *Õ-ð ˆCÜ# CÔ7ˆÜ�—‘œ˜UŸ\™\›^Ó,Ó-Ó.Ð.rD   )r=   rC   rP   r   )r   F)
Ú__doc__Únetworkxr   Únetworkx.utilsr   Ú__all__Ú_dispatchabler=   rC   rP   r   rD   r   Ú<module>rV      s›   ðÙ ã Ý .â
T€ñ �\Ó"Ø×Ò˜XÔ&óYó 'ó #ðYñx �\Ó"Ø×Ò˜XÔ&óó 'ó #ðñB �\Ó"Ø×Ò˜XÔ&ó)/ó 'ó #ò)/rD   