
    h                     H    S r SSKrS/r\R                  " SS9 SS j5       rg)z 
Laplacian centrality measures.
    Nlaplacian_centralityweight)
edge_attrsc                    SSK nSSKn[        U 5      S:X  a  [        R                  " S5      eU R                  US9S:X  a%  U(       a  [        S5      eU  Vs0 s H  oS_M     sn$ Ube  [        U R                  U5      5      n	[        U	5      [        U5      :w  a  [        R                  " S5      eX  Vs/ s H  oU	;  d  M
  UPM     sn-   n
O[        U 5      =p*U R                  5       (       a  [        R                  " X
X4U5      nO%[        R                  " X
U5      R                  5       nUR                  UR                   R#                  USS9S	5      R%                  5       n0 n['        U5       H  u  p[        UR)                  UR*                  S   5      5      nUR-                  U5        UUSS24   SS2U4   nUR/                  5       [1        USS2U4   5      -
  nUR3                  UUU   5        [        U5      S:  a9  UR                  UR                   R#                  USS9S	5      R%                  5       nOS
nUU-
  nU(       a  UU-  n[5        U5      X'   M     U$ s  snf s  snf )a  Compute the Laplacian centrality for nodes in the graph `G`.

The Laplacian Centrality of a node ``i`` is measured by the drop in the
Laplacian Energy after deleting node ``i`` from the graph. The Laplacian Energy
is the sum of the squared eigenvalues of a graph's Laplacian matrix.

.. math::

    C_L(u_i,G) = \frac{(\Delta E)_i}{E_L (G)} = \frac{E_L (G)-E_L (G_i)}{E_L (G)}

    E_L (G) = \sum_{i=0}^n \lambda_i^2

Where $E_L (G)$ is the Laplacian energy of graph `G`,
E_L (G_i) is the Laplacian energy of graph `G` after deleting node ``i``
and $\lambda_i$ are the eigenvalues of `G`'s Laplacian matrix.
This formula shows the normalized value. Without normalization,
the numerator on the right side is returned.

Parameters
----------
G : graph
    A networkx graph

normalized : bool (default = True)
    If True the centrality score is scaled so the sum over all nodes is 1.
    If False the centrality score for each node is the drop in Laplacian
    energy when that node is removed.

nodelist : list, optional (default = None)
    The rows and columns are ordered according to the nodes in nodelist.
    If nodelist is None, then the ordering is produced by G.nodes().

weight: string or None, optional (default=`weight`)
    Optional parameter `weight` to compute the Laplacian matrix.
    The edge data key used to compute each value in the matrix.
    If None, then each edge has weight 1.

walk_type : string or None, optional (default=None)
    Optional parameter `walk_type` used when calling
    :func:`directed_laplacian_matrix <networkx.directed_laplacian_matrix>`.
    One of ``"random"``, ``"lazy"``, or ``"pagerank"``. If ``walk_type=None``
    (the default), then a value is selected according to the properties of `G`:
    - ``walk_type="random"`` if `G` is strongly connected and aperiodic
    - ``walk_type="lazy"`` if `G` is strongly connected but not aperiodic
    - ``walk_type="pagerank"`` for all other cases.

alpha : real (default = 0.95)
    Optional parameter `alpha` used when calling
    :func:`directed_laplacian_matrix <networkx.directed_laplacian_matrix>`.
    (1 - alpha) is the teleportation probability used with pagerank.

Returns
-------
nodes : dictionary
   Dictionary of nodes with Laplacian centrality as the value.

Examples
--------
>>> G = nx.Graph()
>>> edges = [(0, 1, 4), (0, 2, 2), (2, 1, 1), (1, 3, 2), (1, 4, 2), (4, 5, 1)]
>>> G.add_weighted_edges_from(edges)
>>> sorted((v, f"{c:0.2f}") for v, c in laplacian_centrality(G).items())
[(0, '0.70'), (1, '0.90'), (2, '0.28'), (3, '0.22'), (4, '0.26'), (5, '0.04')]

Notes
-----
The algorithm is implemented based on [1]_ with an extension to directed graphs
using the ``directed_laplacian_matrix`` function.

Raises
------
NetworkXPointlessConcept
    If the graph `G` is the null graph.
ZeroDivisionError
    If the graph `G` has no edges (is empty) and normalization is requested.

References
----------
.. [1] Qi, X., Fuller, E., Wu, Q., Wu, Y., and Zhang, C.-Q. (2012).
   Laplacian centrality: A new centrality measure for weighted networks.
   Information Sciences, 194:240-253.
   https://math.wvu.edu/~cqzhang/Publication-files/my-paper/INS-2012-Laplacian-W.pdf

See Also
--------
:func:`~networkx.linalg.laplacianmatrix.directed_laplacian_matrix`
:func:`~networkx.linalg.laplacianmatrix.laplacian_matrix`
r   Nz$null graph has no centrality defined)r   z(graph with no edges has zero full energyz.nodelist has duplicate nodes or nodes not in GT)eigvals_only   g        )numpyscipylennxNetworkXPointlessConceptsizeZeroDivisionErrorsetnbunch_iterNetworkXErrorlistis_directeddirected_laplacian_matrixlaplacian_matrixtoarraypowerlinalgeighsum	enumeratearangeshaperemovediagonalabsfill_diagonalfloat)G
normalizednodelistr   	walk_typealphanpspnnodesetnodes
lap_matrixfull_energylaplace_centralities_dictinode	all_but_iA_2new_diag
new_energy	lapl_cents                        Z/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/centrality/laplacian.pyr   r   
   s1   x 
1v{))*PQQvvVv!#$NOO a1a  ammH-.w<3x=(""#STTq=q!W,<Aq==7"}}11!FuU
((6:BBD
((299>>*4>H!LPPRK !#X&:#3#3A#678	A&q)|4 &&(3z!Q$/?+@@
hy12y>A"))..4."H!LPPRJJ*,	!K/I*/	*:!'' '* %$Q ! >s   I%5	I*I*)TNr   Ngffffff?)__doc__networkxr   __all___dispatchabler        r8   <module>r?      s;    !
" X&NRK% 'K%r>   