+
    )iA                        R t ^ RItRR.t]P                  P                  R4      ]P                  ! RR7      R
R l4       4       t]P                  P                  R4      ]P                  ! RR7      RR l4       4       tR	 t	R# )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                   ^ RI p^ RIp\        P                  ! V 4      p\	        W4      w  rgVP
                  ^ ,          ^ 8X  d   \        P                  ! RV R24      hVP
                  ^ ,          pVP
                  ^ ,          p	VP                  W34      p
VP                  ^ R7      p^W^ 8H  &   VP                  P                  RV,          ^ 3W3R7      P                  4       pW,          P                  4       p^ WR,          &   VP                  W34      p^WR,          VR,          3&   \        V4       F  pW,          V,           p
K  	  WsP                  V
^R7      ,          P                  4       # )	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).
N*No node on the input graph is labeled by ''.axis      ?shapeNNN    r      )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/photoedit/myenv/lib/python3.14/site-packages/networkx/algorithms/node_classification.pyr   r      sJ   Z 
  #A(7F||A!8BG
 	
 
I  #I
)'(A eeemGGqL
		S7]A.y6LMSSUA	
AATlO
)'(A$%ATlF4L !8_UaK  iii*+2244    c                   ^ RI p^ RIp\        P                  ! V 4      p\	        W4      w  rxVP
                  ^ ,          ^ 8X  d   \        P                  ! RV R24      hVP
                  ^ ,          p	VP
                  ^ ,          p
VP                  W34      pVP                  ^ R7      p^W^ 8H  &   VP                  P                  RVP                  V4      ,          ^ 3W3R7      P                  4       pWV,          V,          ,          pVP                  W34      p^V,
          WR,          VR,          3&   \        V4       F  pW,          V,           pK  	  WP                  V^R7      ,          P                  4       # )	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.
Nr   r	   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/   r0   r1   s   &&&&             r2   r   r   k   sX   ^ 
  #A(7F||A!8BG
 	
 
I  #I
)'(A eeemGGqL				rwww	#I+A 
 
eg  	q&BA
)'(A$%IATlF4L !8_UaK  iii*+2244r3   c                   ^ RI p. p/ p^ p\        V P                  RR7      4       FP  w  rgW^,          9   g   K  V^,          V,          pW9  d   WTV&   V^,          pVP                  WdV,          .4       KR  	  VP	                  V4      pTP	                  \        VP                  4       R R7       UU	u. uF  w  rVNK	  	  up	p4      p
W:3# u up	pi )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`
NT)datac                     V ^,          # )r    )xs   &r2   <lambda>!_get_label_info.<locals>.<lambda>   s    1r3   )key)r   	enumeratenodesappendarraysorteditems)r#   r   r%   r(   label_to_idlidinlabelr1   r)   s   &&         r2   r   r      s    " FK
C!''t',-1aD$E'%(E"qMM1%012 . XXfF%k&7&7&9~NON85NOJ  	Ps   5C
)   rJ   )gGz?rK   rJ   )
__doc__networkxr   __all__utilsnot_implemented_for_dispatchabler   r   r   r;   r3   r2   <module>rR      s   2  >
? j)\*G5 + *G5T j)\*J5 + *J5Z! r3   