
    h                         S r SSKrSSKJr  SS/r\" S5      \" S5      \R                  S 5       5       5       r\" S5      \" S5      \R                  S	 5       5       5       rg)
z
Communicability.
    N)not_implemented_forcommunicabilitycommunicability_expdirected
multigraphc           
         SSK n[        U 5      n[        R                  " X5      nSX3S:g  '   UR                  R                  U5      u  pEUR                  U5      n[        [        U[        [        U5      5      5      5      n0 nU  He  n	0 X'   U  HX  n
SnXy   nXz   n[        [        U5      5       H#  nXSS2U4   U   USS2U4   U   -  Xn   -  -  nM%     [        U5      X   U
'   MZ     Mg     U$ )a  Returns communicability between all pairs of nodes in G.

The communicability between pairs of nodes in G is the sum of
walks of different lengths starting at node u and ending at node v.

Parameters
----------
G: graph

Returns
-------
comm: dictionary of dictionaries
    Dictionary of dictionaries keyed by nodes with communicability
    as the value.

Raises
------
NetworkXError
   If the graph is not undirected and simple.

See Also
--------
communicability_exp:
   Communicability between all pairs of nodes in G  using spectral
   decomposition.
communicability_betweenness_centrality:
   Communicability betweenness centrality for each node in G.

Notes
-----
This algorithm uses a spectral decomposition of the adjacency matrix.
Let G=(V,E) be a simple undirected graph.  Using the connection between
the powers  of the adjacency matrix and the number of walks in the graph,
the communicability  between nodes `u` and `v` based on the graph spectrum
is [1]_

.. math::
    C(u,v)=\sum_{j=1}^{n}\phi_{j}(u)\phi_{j}(v)e^{\lambda_{j}},

where `\phi_{j}(u)` is the `u\rm{th}` element of the `j\rm{th}` orthonormal
eigenvector of the adjacency matrix associated with the eigenvalue
`\lambda_{j}`.

References
----------
.. [1] Ernesto Estrada, Naomichi Hatano,
   "Communicability in complex networks",
   Phys. Rev. E 77, 036111 (2008).
   https://arxiv.org/abs/0707.0756

Examples
--------
>>> G = nx.Graph([(0, 1), (1, 2), (1, 5), (5, 4), (2, 4), (2, 3), (4, 3), (3, 6)])
>>> c = nx.communicability(G)
r   N           )numpylistnxto_numpy_arraylinalgeighexpdictziprangelenfloat)GnpnodelistAwvecexpwmappingcuvspqjs                  Y/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/communicability_alg.pyr   r      s    v AwH
!&AA3hKYY^^AFA66!9D3xs8}!567G
AAA
A
A3x=)AYq\C1IaL047:: *AhADG   H    c           
      D   SSK n[        U 5      n[        R                  " X5      nSX3S:g  '   UR                  R                  U5      n[        [        U[        [        U5      5      5      5      n0 nU  H)  n0 Xg'   U  H  n[        XEU   XX   4   5      Xg   U'   M     M+     U$ )a  Returns communicability between all pairs of nodes in G.

Communicability between pair of node (u,v) of node in G is the sum of
walks of different lengths starting at node u and ending at node v.

Parameters
----------
G: graph

Returns
-------
comm: dictionary of dictionaries
    Dictionary of dictionaries keyed by nodes with communicability
    as the value.

Raises
------
NetworkXError
    If the graph is not undirected and simple.

See Also
--------
communicability:
   Communicability between pairs of nodes in G.
communicability_betweenness_centrality:
   Communicability betweenness centrality for each node in G.

Notes
-----
This algorithm uses matrix exponentiation of the adjacency matrix.

Let G=(V,E) be a simple undirected graph.  Using the connection between
the powers  of the adjacency matrix and the number of walks in the graph,
the communicability between nodes u and v is [1]_,

.. math::
    C(u,v) = (e^A)_{uv},

where `A` is the adjacency matrix of G.

References
----------
.. [1] Ernesto Estrada, Naomichi Hatano,
   "Communicability in complex networks",
   Phys. Rev. E 77, 036111 (2008).
   https://arxiv.org/abs/0707.0756

Examples
--------
>>> G = nx.Graph([(0, 1), (1, 2), (1, 5), (5, 4), (2, 4), (2, 3), (4, 3), (3, 6)])
>>> c = nx.communicability_exp(G)
r   Nr	   r
   )scipyr   r   r   r   expmr   r   r   r   r   )	r   spr   r   expAr   r   r    r!   s	            r&   r   r   ]   s    p AwH
!&AA3hK99>>!D3xs8}!567G
AADWZ!789ADG   Hr'   )	__doc__networkxr   networkx.utilsr   __all___dispatchabler   r    r'   r&   <module>r3      s     .3
4 Z \"L  # !L^ Z \"C  # !Cr'   