§
    bŠtjA  ã                   ó  — d Z ddlZddgZej                             d¦  «         ej        d¬¦  «        dd
„¦   «         ¦   «         Zej                             d¦  «         ej        d¬¦  «        dd„¦   «         ¦   «         Zd„ Z	dS )a  This module provides the functions for node classification problem.

The functions in this module are not imported
into the top level `networkx` namespace.
You can access these functions by importing
the `networkx.algorithms.node_classification` modules,
then accessing the functions as attributes of `node_classification`.
For example:

  >>> from networkx.algorithms import node_classification
  >>> G = nx.path_graph(4)
  >>> G.edges()
  EdgeView([(0, 1), (1, 2), (2, 3)])
  >>> G.nodes[0]["label"] = "A"
  >>> G.nodes[3]["label"] = "B"
  >>> node_classification.harmonic_function(G)
  ['A', 'A', 'B', 'B']

References
----------
Zhu, X., Ghahramani, Z., & Lafferty, J. (2003, August).
Semi-supervised learning using gaussian fields and harmonic functions.
In ICML (Vol. 3, pp. 912-919).
é    NÚharmonic_functionÚlocal_and_global_consistencyÚdirectedÚ
label_name)Ú
node_attrsé   Úlabelc                 óþ  — ddl }ddl}t          j        | ¦  «        }t	          | |¦  «        \  }}|j        d         dk    rt          j        d|› d�¦  «        ‚|j        d         }|j        d         }	|                     ||	f¦  «        }
|                     d¬¦  «        }d||dk    <   |j	         
                    d|z  df||f¬¦  «                             ¦   «         }||z                       ¦   «         }d||dd…df         <   |                     ||	f¦  «        }d||dd…df         |dd…df         f<   t          |¦  «        D ]
}||
z  |z   }
Œ||                     |
d¬¦  «                                      ¦   «         S )	aˆ  Node classification by Harmonic function

    Function for computing Harmonic function algorithm by Zhu et al.

    Parameters
    ----------
    G : NetworkX Graph
    max_iter : int
        maximum number of iterations allowed
    label_name : string
        name of target labels to predict

    Returns
    -------
    predicted : list
        List of length ``len(G)`` with the predicted labels for each node.

    Raises
    ------
    NetworkXError
        If no nodes in `G` have attribute `label_name`.

    Examples
    --------
    >>> from networkx.algorithms import node_classification
    >>> G = nx.path_graph(4)
    >>> G.nodes[0]["label"] = "A"
    >>> G.nodes[3]["label"] = "B"
    >>> G.nodes(data=True)
    NodeDataView({0: {'label': 'A'}, 1: {}, 2: {}, 3: {'label': 'B'}})
    >>> G.edges()
    EdgeView([(0, 1), (1, 2), (2, 3)])
    >>> predicted = node_classification.harmonic_function(G)
    >>> predicted
    ['A', 'A', 'B', 'B']

    References
    ----------
    Zhu, X., Ghahramani, Z., & Lafferty, J. (2003, August).
    Semi-supervised learning using gaussian fields and harmonic functions.
    In ICML (Vol. 3, pp. 912-919).
    r   Nú*No node on the input graph is labeled by 'ú'.©Úaxisé   ç      ð?©Úshape)ÚnumpyÚscipyÚnxÚto_scipy_sparse_arrayÚ_get_label_infor   ÚNetworkXErrorÚzerosÚsumÚsparseÚ	dia_arrayÚtocsrÚtolilÚrangeÚargmaxÚtolist)ÚGÚmax_iterr   ÚnpÚspÚXÚlabelsÚ
label_dictÚ	n_samplesÚ	n_classesÚFÚdegreesÚDÚPÚBÚ_s                   úe/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/algorithms/node_classification.pyr   r      s¨  € ðZ ÐÐÐØÐÐÐå
Ô  Ñ#Ô#€AÝ(¨¨JÑ7Ô7Ñ€FˆJà„|�A„˜!ÒÐÝÔØG¸ÐGÐGÐGñ
ô 
ð 	
ð ”˜”
€IØÔ  Ô#€IØ
�Š�)˜YÐ'Ñ(Ô(€Að �eŠe˜ˆe‰mŒm€GØ€GˆG�qŠLÑØ
Œ	×Ò˜S 7™]¨AÐ.°yÀ)Ð6LÐÑMÔM×SÒSÑUÔU€AØ	
ˆQ‰�Š‰Œ€AØ€A€fˆQˆQˆQ�ˆT„l�Oà
�Š�)˜YÐ'Ñ(Ô(€AØ$%€A€fˆQˆQˆQ�ˆT„l�F˜1˜1˜1˜a˜4”LÐ Ñ!å�8‰_Œ_ð ð ˆØ�‰U�a‰Kˆˆà�b—i’i ¨�iÑ*Ô*Ô+×2Ò2Ñ4Ô4Ð4ó    ç®Gáz®ï?c                 óô  — ddl }ddl}t          j        | ¦  «        }t	          | |¦  «        \  }}|j        d         dk    rt          j        d|› d�¦  «        ‚|j        d         }	|j        d         }
|                     |	|
f¦  «        }|                     d¬¦  «        }d||dk    <   |j	         
                    d|                     |¦  «        z  df|	|	f¬¦  «                             ¦   «         }|||z  |z  z  }|                     |	|
f¦  «        }d|z
  ||dd…df         |dd…df         f<   t          |¦  «        D ]
}||z  |z   }Œ||                     |d¬¦  «                                      ¦   «         S )	uï  Node classification by Local and Global Consistency

    Function for computing Local and global consistency algorithm by Zhou et al.

    Parameters
    ----------
    G : NetworkX Graph
    alpha : float
        Clamping factor
    max_iter : int
        Maximum number of iterations allowed
    label_name : string
        Name of target labels to predict

    Returns
    -------
    predicted : list
        List of length ``len(G)`` with the predicted labels for each node.

    Raises
    ------
    NetworkXError
        If no nodes in `G` have attribute `label_name`.

    Examples
    --------
    >>> from networkx.algorithms import node_classification
    >>> G = nx.path_graph(4)
    >>> G.nodes[0]["label"] = "A"
    >>> G.nodes[3]["label"] = "B"
    >>> G.nodes(data=True)
    NodeDataView({0: {'label': 'A'}, 1: {}, 2: {}, 3: {'label': 'B'}})
    >>> G.edges()
    EdgeView([(0, 1), (1, 2), (2, 3)])
    >>> predicted = node_classification.local_and_global_consistency(G)
    >>> predicted
    ['A', 'A', 'B', 'B']

    References
    ----------
    Zhou, D., Bousquet, O., Lal, T. N., Weston, J., & SchÃ¶lkopf, B. (2004).
    Learning with local and global consistency.
    Advances in neural information processing systems, 16(16), 321-328.
    r   Nr   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   Úsqrtr   r   r    r!   )r"   Úalphar#   r   r$   r%   r&   r'   r(   r)   r*   r+   r,   ÚD2r.   r/   r0   s                    r1   r   r   k   s®  € ð^ ÐÐÐØÐÐÐå
Ô  Ñ#Ô#€AÝ(¨¨JÑ7Ô7Ñ€FˆJà„|�A„˜!ÒÐÝÔØG¸ÐGÐGÐGñ
ô 
ð 	
ð ”˜”
€IØÔ  Ô#€IØ
�Š�)˜YÐ'Ñ(Ô(€Að �eŠe˜ˆe‰mŒm€GØ€GˆG�qŠLÑØ	Œ×	Ò	Ø	ˆr�wŠw�wÑÔÑ	 Ð#¨I°yÐ+Að 
ñ 
ô 
ç‚e�g„gð ð 	�"�q‘&˜B‘Ñ€Aà
�Š�)˜YÐ'Ñ(Ô(€AØ$%¨¡I€A€fˆQˆQˆQ�ˆT„l�F˜1˜1˜1˜a˜4”LÐ Ñ!å�8‰_Œ_ð ð ˆØ�‰U�a‰Kˆˆà�b—i’i ¨�iÑ*Ô*Ô+×2Ò2Ñ4Ô4Ð4r2   c                 ó¢  — ddl }g }i }d}t          |                      d¬¦  «        ¦  «        D ]H\  }}||d         v r9|d         |         }||vr
|||<   |dz  }|                     |||         g¦  «         ŒI|                     |¦  «        }|                     d„ t          |                     ¦   «         d„ ¬¦  «        D ¦   «         ¦  «        }	||	fS )	aÄ  Get and return information of labels from the input graph

    Parameters
    ----------
    G : Network X graph
    label_name : string
        Name of the target label

    Returns
    -------
    labels : numpy array, shape = [n_labeled_samples, 2]
        Array of pairs of labeled node ID and label ID
    label_dict : numpy array, shape = [n_classes]
        Array of labels
        i-th element contains the label corresponding label ID `i`
    r   NT)Údatar   c                 ó   — g | ]\  }}|‘ŒS © r;   )Ú.0r	   r0   s      r1   ú
<listcomp>z#_get_label_info.<locals>.<listcomp>Ù   s   € ÐOÐOÐO‘8�5˜!ˆÐOÐOÐOr2   c                 ó   — | d         S )Nr   r;   )Úxs    r1   ú<lambda>z!_get_label_info.<locals>.<lambda>Ù   s
   € ÈÈ1Ì€ r2   )Úkey)r   Ú	enumerateÚnodesÚappendÚarrayÚsortedÚitems)
r"   r   r$   r'   Úlabel_to_idÚlidÚiÚnr	   r(   s
             r1   r   r   º   sý   € ð" ÐÐÐà€FØ€KØ
€CÝ˜!Ÿ'š' t˜'Ñ,Ô,Ñ-Ô-ð 3ð 3‰ˆˆ1Ø˜˜1œÐÐØ�a”D˜Ô$ˆEØ˜KÐ'Ð'Ø%(�˜EÑ"Ø�q‘�Ø�MŠM˜1˜k¨%Ô0Ð1Ñ2Ô2Ð2øØ�XŠX�fÑÔ€FØ—’ØOÐO�v k×&7Ò&7Ñ&9Ô&9¸~¸~ÐNÑNÔNÐOÑOÔOñô €Jð �JÐÐr2   )r   r	   )r3   r   r	   )
Ú__doc__Únetworkxr   Ú__all__ÚutilsÚnot_implemented_forÚ_dispatchabler   r   r   r;   r2   r1   ú<module>rR      sã   ððð ð2 Ð Ð Ð àÐ >Ð
?€ð „×Ò˜jÑ)Ô)Ø€Ô˜\Ð*Ñ*Ô*ðG5ð G5ð G5ñ +Ô*ñ *Ô)ðG5ðT „×Ò˜jÑ)Ô)Ø€Ô˜\Ð*Ñ*Ô*ðJ5ð J5ð J5ñ +Ô*ñ *Ô)ðJ5ðZ! ð ! ð ! ð ! ð ! r2   