§
    bŠtjb  ã                   ó  — d Z ddlZddlmZ ddgZ ed¦  «         ed¦  «         ej        d¬	¦  «        dd
„¦   «         ¦   «         ¦   «         Z ed¦  «         ed¦  «         ej        d¬	¦  «        dd„¦   «         ¦   «         ¦   «         ZdS )zModularity matrix of graphs.é    N)Únot_implemented_forÚmodularity_matrixÚdirected_modularity_matrixÚdirectedÚ
multigraphÚweight)Ú
edge_attrsc                 óø   — ddl }|€t          | ¦  «        }t          j        | ||d¬¦  «        }|                     d¬¦  «        }|                     ¦   «         dz  }|                     ||¦  «        d|z  z  }||z
  S )	aÑ  Returns the modularity matrix of G.

    The modularity matrix is the matrix B = A - <A>, where A is the adjacency
    matrix and <A> is the average adjacency matrix, assuming that the graph
    is described by the configuration model.

    More specifically, the element B_ij of B is defined as

    .. math::
        A_{ij} - {k_i k_j \over 2 m}

    where k_i is the degree of node i, and where m is the number of edges
    in the graph. When weight is set to a name of an attribute edge, Aij, k_i,
    k_j and m are computed using its value.

    Parameters
    ----------
    G : Graph
       A NetworkX graph

    nodelist : list, optional
       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=None)
       The edge attribute that holds the numerical value used for
       the edge weight.  If None then all edge weights are 1.

    Returns
    -------
    B : Numpy array
      The modularity matrix of G.

    Examples
    --------
    >>> k = [3, 2, 2, 1, 0]
    >>> G = nx.havel_hakimi_graph(k)
    >>> B = nx.modularity_matrix(G)


    See Also
    --------
    to_numpy_array
    modularity_spectrum
    adjacency_matrix
    directed_modularity_matrix

    References
    ----------
    .. [1] M. E. J. Newman, "Modularity and community structure in networks",
           Proc. Natl. Acad. Sci. USA, vol. 103, pp. 8577-8582, 2006.
    r   NÚcsr©Únodelistr   Úformaté   ©Úaxisg      à?é   ©ÚnumpyÚlistÚnxÚto_scipy_sparse_arrayÚsumÚouter)ÚGr   r   ÚnpÚAÚkÚmÚXs           ú^/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/linalg/modularitymatrix.pyr   r   	   s€   € ðp ÐÐÐàÐÝ˜‘7”7ˆÝ
Ô  ¨X¸fÈUÐSÑSÔS€AØ	�Š�1ˆ‰Œ€AØ	�Š‰Œ�#‰€Aà
�Š��A‰Œ˜!˜a™%Ñ €Aàˆq‰5€Ló    Ú
undirectedc                 ó  — ddl }|€t          | ¦  «        }t          j        | ||d¬¦  «        }|                     d¬¦  «        }|                     d¬¦  «        }|                     ¦   «         }|                     ||¦  «        |z  }||z
  S )a(  Returns the directed modularity matrix of G.

    The modularity matrix is the matrix B = A - <A>, where A is the adjacency
    matrix and <A> is the expected adjacency matrix, assuming that the graph
    is described by the configuration model.

    More specifically, the element B_ij of B is defined as

    .. math::
        B_{ij} = A_{ij} - k_i^{out} k_j^{in} / m

    where :math:`k_i^{in}` is the in degree of node i, and :math:`k_j^{out}` is the out degree
    of node j, with m the number of edges in the graph. When weight is set
    to a name of an attribute edge, Aij, k_i, k_j and m are computed using
    its value.

    Parameters
    ----------
    G : DiGraph
       A NetworkX DiGraph

    nodelist : list, optional
       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=None)
       The edge attribute that holds the numerical value used for
       the edge weight.  If None then all edge weights are 1.

    Returns
    -------
    B : Numpy array
      The modularity matrix of G.

    Examples
    --------
    >>> G = nx.DiGraph()
    >>> G.add_edges_from(
    ...     (
    ...         (1, 2),
    ...         (1, 3),
    ...         (3, 1),
    ...         (3, 2),
    ...         (3, 5),
    ...         (4, 5),
    ...         (4, 6),
    ...         (5, 4),
    ...         (5, 6),
    ...         (6, 4),
    ...     )
    ... )
    >>> B = nx.directed_modularity_matrix(G)


    Notes
    -----
    NetworkX defines the element A_ij of the adjacency matrix as 1 if there
    is a link going from node i to node j. Leicht and Newman use the opposite
    definition. This explains the different expression for B_ij.

    See Also
    --------
    to_numpy_array
    modularity_spectrum
    adjacency_matrix
    modularity_matrix

    References
    ----------
    .. [1] E. A. Leicht, M. E. J. Newman,
        "Community structure in directed networks",
        Phys. Rev Lett., vol. 100, no. 11, p. 118703, 2008.
    r   Nr   r   r   r   r   )	r   r   r   r   r   Úk_inÚk_outr   r   s	            r    r   r   N   s‹   € ðZ ÐÐÐàÐÝ˜‘7”7ˆÝ
Ô  ¨X¸fÈUÐSÑSÔS€AØ�5Š5�aˆ5‰=Œ=€DØ�EŠE�qˆE‰MŒM€EØ�Š‰
Œ
€Aà
�Š�˜ÑÔ Ñ!€Aàˆq‰5€Lr!   )NN)	Ú__doc__Únetworkxr   Únetworkx.utilsr   Ú__all__Ú_dispatchabler   r   © r!   r    ú<module>r,      sÿ   ðØ "Ð "à Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .àÐ <Ð
=€ð Ð�ZÑ Ô ØÐ�\Ñ"Ô"Ø€Ô˜XÐ&Ñ&Ô&ð?ð ?ð ?ñ 'Ô&ñ #Ô"ñ !Ô ð?ðD Ð�\Ñ"Ô"ØÐ�\Ñ"Ô"Ø€Ô˜XÐ&Ñ&Ô&ðUð Uð Uñ 'Ô&ñ #Ô"ñ #Ô"ðUð Uð Ur!   