ó
    …~iA  ã                   óö   • S r SSKrSS/r\R                  R                  S5      \R                  " SS9SS j5       5       r\R                  R                  S5      \R                  " SS9SS	 j5       5       rS
 r	g)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_attrsc                 ó’  • SSK nSSKn[        R                  " U 5      n[	        X5      u  pgUR
                  S   S:X  a  [        R                  " SU S35      eUR
                  S   nUR
                  S   n	UR                  X‰45      n
UR                  SS9nSX»S:H  '   UR                  R                  SU-  S4Xˆ4S9R                  5       nXÅ-  R                  5       nSXÖSS2S4   '   UR                  X‰45      nSXæSS2S4   USS2S4   4'   [        U5       H
  nXÚ-  U-   n
M     XsR                  U
SS9   R                  5       $ )	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                   Úd/home/mande/repo/quber/.venv/lib/python3.13/site-packages/networkx/algorithms/node_classification.pyr   r      sV  € óZ Ûä
× Ò  Ó#€AÜ(¨Ó7Ñ€Fà‡|�|�A�˜!ÓÜ×ÒØ8¸¸ÀBÐGó
ð 	
ð —‘˜‘
€IØ× Ñ  Ñ#€IØ
�‰�)Ð'Ó(€Að �e‰e˜ˆeˆm€GØ€G�q‰LÑØ
�	‰	×Ñ˜S 7™]¨AÐ.°yÐ6LÐÐM×SÑSÓU€AØ	
‰�‰‹€AØ€AŠQ�ˆT�l�Oà
�‰�)Ð'Ó(€AØ$%€AŠQ�ˆT�l�Fš1˜a˜4‘LÐ Ñ!ä�8Ž_ˆØ‰U�a‰KŠñ ð —i‘i ¨�iÐ*Ñ+×2Ñ2Ó4Ð4ó    c                 ó�  • SSK nSSKn[        R                  " U 5      n[	        X5      u  pxUR
                  S   S:X  a  [        R                  " SU S35      eUR
                  S   n	UR
                  S   n
UR                  Xš45      nUR                  SS9nSXÌS:H  '   UR                  R                  SUR                  U5      -  S4X™4S9R                  5       nXU-  U-  -  nUR                  Xš45      nSU-
  X÷SS2S4   USS2S4   4'   [        U5       H
  nXë-  U-   nM     X„R                  USS9   R                  5       $ )	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-   r.   s                    r/   r   r   k   s`  € ó^ Ûä
× Ò  Ó#€AÜ(¨Ó7Ñ€Fà‡|�|�A�˜!ÓÜ×ÒØ8¸¸ÀBÐGó
ð 	
ð —‘˜‘
€IØ× Ñ  Ñ#€IØ
�‰�)Ð'Ó(€Að �e‰e˜ˆeˆm€GØ€G�q‰LÑØ	�‰×	Ñ	Ø	ˆr�w‰w�wÓÑ	 Ð#¨IÐ+Að 
ð 
ç�eƒgð ð 	�q‘&˜B‘Ñ€Aà
�‰�)Ð'Ó(€AØ$%¨¡I€AŠQ�ˆT�l�Fš1˜a˜4‘LÐ Ñ!ä�8Ž_ˆØ‰U�a‰KŠñ ð —i‘i ¨�iÐ*Ñ+×2Ñ2Ó4Ð4r0   c                 óp  • SSK n/ n0 nSn[        U R                  SS95       H:  u  pgXS   ;   d  M  US   U   nX„;  a	  XTU'   US-  nUR                  XdU   /5        M<     UR	                  U5      nUR	                  [        UR                  5       S S9 VV	s/ s H  u  p‰UPM	     sn	n5      n
X:4$ s  sn	nf )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                 ó   • U S   $ )Nr   © )Úxs    r/   Ú<lambda>Ú!_get_label_info.<locals>.<lambda>Ù   s   € ÈÈ1Êr0   )Úkey)r   Ú	enumerateÚnodesÚappendÚarrayÚsortedÚitems)r    r   r"   r%   Úlabel_to_idÚlidÚiÚnÚlabelr.   r&   s              r/   r   r   º   sÊ   € ó" à€FØ€KØ
€CÜ˜!Ÿ'™' t˜'Ð,Ö-‰ˆØ˜1™ÕØ�a‘D˜Ñ$ˆEØÓ'Ø%(˜EÑ"Ø�q‘�Ø�M‰M˜1¨%Ñ0Ð1Ö2ñ .ð �X‰X�fÓ€FØ—‘Ü% k×&7Ñ&7Ó&9¹~ÒNÔOÒN‘8�5‹ÑNÒOó€Jð ÐÐùó 	Ps   ÂB2
)é   rG   )g®Gáz®ï?rH   rG   )
Ú__doc__Únetworkxr   Ú__all__ÚutilsÚnot_implemented_forÚ_dispatchabler   r   r   r8   r0   r/   Ú<module>rO      s‘   ðñó2 àÐ >Ð
?€ð ‡�×Ñ˜jÓ)Ø×Ò˜\Ñ*óG5ó +ó *ðG5ðT ‡�×Ñ˜jÓ)Ø×Ò˜\Ñ*óJ5ó +ó *ðJ5óZ! r0   