o
    ˷e
                     @   s@   d Z ddlZddlmZ ddlmZ dgZeddd
dZdS )u  Function for computing Local and global consistency algorithm by Zhou et al.

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.
    N)_get_label_info)not_implemented_forlocal_and_global_consistencydirectedGz?   labelc                 C   s"  ddl }ddl}ddl}t| }t| |\}}	|jd dkr(td| d|jd }
|	jd }||
|f}|j	dd}d||dk< |
|j|jjd| dd}||| |  }||
|f}d| ||dddf |dddf f< t|D ]}|| | }q}|	|j|dd  S )	u  Node classification by Local and Global Consistency

    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   Nz*No node on the input graph is labeled by 'z'.)axis   g      ?)offsets)numpyscipyscipy.sparsenxto_scipy_sparse_arrayr   shapeNetworkXErrorzerossumsqrtsparse	csr_arraydiagsrangeargmaxtolist)Galphamax_iter
label_namenpspr   Xlabels
label_dict	n_samples	n_classesFdegreesD2PB_ r-   b/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/algorithms/node_classification/lgc.pyr      s*   ,



"()r   r   r   )	__doc__networkxr   -networkx.algorithms.node_classification.utilsr   networkx.utils.decoratorsr   __all__r   r-   r-   r-   r.   <module>   s    