
    0Ph@x              
       D   d Z ddlZddlmZmZ ddlZddlmZm	Z	m
Z
 ddlmZ ddlmZmZmZ ddlmZ dd	lmZmZ dd
lmZmZ ddlmZmZ ddlmZmZmZ ddl m!Z! ddl"m#Z# d Z$ddddddZ% edddgid          dddddddddd             Z& G d! d"ee          Z'dS )#z"Algorithms for spectral clustering    N)IntegralReal)LinAlgErrorqrsvd)
csc_matrix   )BaseEstimatorClusterMixin_fit_context)_spectral_embedding)KERNEL_PARAMSpairwise_kernels)NearestNeighborskneighbors_graph)as_float_arraycheck_random_state)Interval
StrOptionsvalidate_params)validate_data   )k_meansc           
      ^   | j         d         }t          | j        d          \  }}}t          | |d|         ddf         j                  \  }}}t	          t          j        | t          j        ||                                                              } |                     d          S )a  Find the discrete partition closest to the eigenvector embedding.

        This implementation was proposed in [1]_.

    .. versionadded:: 1.1

        Parameters
        ----------
        vectors : array-like, shape: (n_samples, n_clusters)
            The embedding space of the samples.

        Returns
        -------
        labels : array of integers, shape: n_samples
            The cluster labels of vectors.

        References
        ----------
        .. [1] :doi:`Simple, direct, and efficient multi-way spectral clustering, 2019
            Anil Damle, Victor Minden, Lexing Ying
            <10.1093/imaiai/iay008>`

    r   T)pivotingNaxis)	shaper   Tr   absnpdotconjargmax)vectorsk_pivutvs         Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/cluster/_spectral.py
cluster_qrr,      s    2 	aA79t,,,IAq#73rr7AAA:&())HB1"&"&QVVXX"6"67788G>>q>!!!    T      )copymax_svd_restarts
n_iter_maxrandom_statec                   t          |          }t          | |          } t          j        t                    j        }| j        \  }}t          j        |          }t          | j        d                   D ]}	| dd|	f         t          j	        
                    | dd|	f                   z  |z  | dd|	f<   | d|	f         dk    r3d| dd|	f         z  t          j        | d|	f                   z  | dd|	f<   | t          j        | dz                      d                    ddt          j        f         z  } d}
d}|
|k     r|st          j        ||f          }| |                    |          ddf         j        |dddf<   t          j        |          }t          d|          D ]c}|t          j        t          j        | |dd|dz
  f                             z  }| |                                ddf         j        |dd|f<   dd	}d}|s)|dz  }t          j        | |          }|                    d          }t+          t          j        t/          |                    t          j        d|          |ff||f
          }|j        | z  }	 t          j	                            |          \  }}}n$# t4          $ r |
dz  }
t7          d           Y naw xY wd||                                z
  z  }t#          ||z
            |k     s||k    rd}n!|}t          j        |j        |j                  }|)|
|k     r||st5          d          |S )ap  Search for a partition matrix which is closest to the eigenvector embedding.

    This implementation was proposed in [1]_.

    Parameters
    ----------
    vectors : array-like of shape (n_samples, n_clusters)
        The embedding space of the samples.

    copy : bool, default=True
        Whether to copy vectors, or perform in-place normalization.

    max_svd_restarts : int, default=30
        Maximum number of attempts to restart SVD if convergence fails

    n_iter_max : int, default=30
        Maximum number of iterations to attempt in rotation and partition
        matrix search if machine precision convergence is not reached

    random_state : int, RandomState instance, default=None
        Determines random number generation for rotation matrix initialization.
        Use an int to make the randomness deterministic.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    labels : array of integers, shape: n_samples
        The labels of the clusters.

    References
    ----------

    .. [1] `Multiclass spectral clustering, 2003
           Stella X. Yu, Jianbo Shi
           <https://people.eecs.berkeley.edu/~jordan/courses/281B-spring04/readings/yu-shi.pdf>`_

    Notes
    -----

    The eigenvector embedding is used to iteratively search for the
    closest discrete partition.  First, the eigenvector embedding is
    normalized to the space of partition matrices. An optimal discrete
    partition matrix closest to this normalized embedding multiplied by
    an initial rotation is calculated.  Fixing this discrete partition
    matrix, an optimal rotation matrix is calculated.  These two
    calculations are performed until convergence.  The discrete partition
    matrix is returned as the clustering solution.  Used in spectral
    clustering, this method tends to be faster and more robust to random
    initialization than k-means.

    )r0   r   Nr   r	   r   F        )r   z2SVD did not converge, randomizing and trying againg       @TzSVD did not converge)r   r   r!   finfofloatepsr   sqrtrangelinalgnormsignsumnewaxiszerosrandintr   r    r"   argminr$   r   oneslenaranger   r   print)r%   r0   r1   r2   r3   r9   	n_samplesn_components	norm_onesisvd_restartshas_convergedrotationcjlast_objective_valuen_iter
t_discretelabelsvectors_discretet_svdUSVh
ncut_values                            r+   
discretizer[   7   s   n &l33LW4000G
(5//
C%mI| 	""I7=#$$ H H A1)F)FF)S11a4=AA.A1G1GGGAAAqDM
 ! 0 0a 0 8 899!!!RZ-HHGLM ***M* 8\<899 !5!5i!@!@!!!!CDFA
 HYq,'' 	6 	6A wAE(:;;<<<A$QXXZZ]35HQQQTNN" 	-aKF22J&&A&..F)V%%	!Y(?(?'HI ,/     
 %&0E9==//1bb   !JKKK
 	AEEGG 34JJ!5566<<&:BUBU $ (2$6"$,,5   	-' ***M*^  20111Ms   #K K$#K$affinityz
array-likezsparse matrixFprefer_skip_nested_validation   
   autokmeans)
n_clustersrI   eigen_solverr3   n_init	eigen_tolassign_labelsverbosec                f    t          |||||d|||	  	                            |           }	|	j        S )a  Apply clustering to a projection of the normalized Laplacian.

    In practice Spectral Clustering is very useful when the structure of
    the individual clusters is highly non-convex or more generally when
    a measure of the center and spread of the cluster is not a suitable
    description of the complete cluster. For instance, when clusters are
    nested circles on the 2D plane.

    If affinity is the adjacency matrix of a graph, this method can be
    used to find normalized graph cuts [1]_, [2]_.

    Read more in the :ref:`User Guide <spectral_clustering>`.

    Parameters
    ----------
    affinity : {array-like, sparse matrix} of shape (n_samples, n_samples)
        The affinity matrix describing the relationship of the samples to
        embed. **Must be symmetric**.

        Possible examples:
          - adjacency matrix of a graph,
          - heat kernel of the pairwise distance matrix of the samples,
          - symmetric k-nearest neighbours connectivity matrix of the samples.

    n_clusters : int, default=None
        Number of clusters to extract.

    n_components : int, default=n_clusters
        Number of eigenvectors to use for the spectral embedding.

    eigen_solver : {None, 'arpack', 'lobpcg', or 'amg'}
        The eigenvalue decomposition method. If None then ``'arpack'`` is used.
        See [4]_ for more details regarding ``'lobpcg'``.
        Eigensolver ``'amg'`` runs ``'lobpcg'`` with optional
        Algebraic MultiGrid preconditioning and requires pyamg to be installed.
        It can be faster on very large sparse problems [6]_ and [7]_.

    random_state : int, RandomState instance, default=None
        A pseudo random number generator used for the initialization
        of the lobpcg eigenvectors decomposition when `eigen_solver ==
        'amg'`, and for the K-Means initialization. Use an int to make
        the results deterministic across calls (See
        :term:`Glossary <random_state>`).

        .. note::
            When using `eigen_solver == 'amg'`,
            it is necessary to also fix the global numpy seed with
            `np.random.seed(int)` to get deterministic results. See
            https://github.com/pyamg/pyamg/issues/139 for further
            information.

    n_init : int, default=10
        Number of time the k-means algorithm will be run with different
        centroid seeds. The final results will be the best output of n_init
        consecutive runs in terms of inertia. Only used if
        ``assign_labels='kmeans'``.

    eigen_tol : float, default="auto"
        Stopping criterion for eigendecomposition of the Laplacian matrix.
        If `eigen_tol="auto"` then the passed tolerance will depend on the
        `eigen_solver`:

        - If `eigen_solver="arpack"`, then `eigen_tol=0.0`;
        - If `eigen_solver="lobpcg"` or `eigen_solver="amg"`, then
          `eigen_tol=None` which configures the underlying `lobpcg` solver to
          automatically resolve the value according to their heuristics. See,
          :func:`scipy.sparse.linalg.lobpcg` for details.

        Note that when using `eigen_solver="lobpcg"` or `eigen_solver="amg"`
        values of `tol<1e-5` may lead to convergence issues and should be
        avoided.

        .. versionadded:: 1.2
           Added 'auto' option.

    assign_labels : {'kmeans', 'discretize', 'cluster_qr'}, default='kmeans'
        The strategy to use to assign labels in the embedding
        space.  There are three ways to assign labels after the Laplacian
        embedding.  k-means can be applied and is a popular choice. But it can
        also be sensitive to initialization. Discretization is another
        approach which is less sensitive to random initialization [3]_.
        The cluster_qr method [5]_ directly extracts clusters from eigenvectors
        in spectral clustering. In contrast to k-means and discretization, cluster_qr
        has no tuning parameters and is not an iterative method, yet may outperform
        k-means and discretization in terms of both quality and speed. For a detailed
        comparison of clustering strategies, refer to the following example:
        :ref:`sphx_glr_auto_examples_cluster_plot_coin_segmentation.py`.

        .. versionchanged:: 1.1
           Added new labeling method 'cluster_qr'.

    verbose : bool, default=False
        Verbosity mode.

        .. versionadded:: 0.24

    Returns
    -------
    labels : array of integers, shape: n_samples
        The labels of the clusters.

    Notes
    -----
    The graph should contain only one connected component, elsewhere
    the results make little sense.

    This algorithm solves the normalized cut for `k=2`: it is a
    normalized spectral clustering.

    References
    ----------

    .. [1] :doi:`Normalized cuts and image segmentation, 2000
           Jianbo Shi, Jitendra Malik
           <10.1109/34.868688>`

    .. [2] :doi:`A Tutorial on Spectral Clustering, 2007
           Ulrike von Luxburg
           <10.1007/s11222-007-9033-z>`

    .. [3] `Multiclass spectral clustering, 2003
           Stella X. Yu, Jianbo Shi
           <https://people.eecs.berkeley.edu/~jordan/courses/281B-spring04/readings/yu-shi.pdf>`_

    .. [4] :doi:`Toward the Optimal Preconditioned Eigensolver:
           Locally Optimal Block Preconditioned Conjugate Gradient Method, 2001
           A. V. Knyazev
           SIAM Journal on Scientific Computing 23, no. 2, pp. 517-541.
           <10.1137/S1064827500366124>`

    .. [5] :doi:`Simple, direct, and efficient multi-way spectral clustering, 2019
           Anil Damle, Victor Minden, Lexing Ying
           <10.1093/imaiai/iay008>`

    .. [6] :doi:`Multiscale Spectral Image Segmentation Multiscale preconditioning
           for computing eigenvalues of graph Laplacians in image segmentation, 2006
           Andrew Knyazev
           <10.13140/RG.2.2.35280.02565>`

    .. [7] :doi:`Preconditioned spectral clustering for stochastic block partition
           streaming graph challenge (Preliminary version at arXiv.)
           David Zhuzhunashvili, Andrew Knyazev
           <10.1109/HPEC.2017.8091045>`

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.metrics.pairwise import pairwise_kernels
    >>> from sklearn.cluster import spectral_clustering
    >>> X = np.array([[1, 1], [2, 1], [1, 0],
    ...               [4, 7], [3, 5], [3, 6]])
    >>> affinity = pairwise_kernels(X, metric='rbf')
    >>> spectral_clustering(
    ...     affinity=affinity, n_clusters=2, assign_labels="discretize", random_state=0
    ... )
    array([1, 1, 1, 0, 0, 0])
    precomputed)	rc   rI   rd   r3   re   r\   rf   rg   rh   )SpectralClusteringfitlabels_)
r\   rc   rI   rd   r3   re   rf   rg   rh   	clusterers
             r+   spectral_clusteringro      sO    \ #!!!#
 
 
 
c(mm  r-   c                       e Zd ZU dZ eeddd          g eh d          dg eeddd          dgdg eeddd          g eeddd          ge e e	e
          h d	z            g eeddd          g eed
dd           edh          g eh d          g eeddd          g eeddd          gedgedgdgdZeed<   	 dddddddddddddddddZ ed          d d            Zd  fd	Z fdZ xZS )!rk   a$  Apply clustering to a projection of the normalized Laplacian.

    In practice Spectral Clustering is very useful when the structure of
    the individual clusters is highly non-convex, or more generally when
    a measure of the center and spread of the cluster is not a suitable
    description of the complete cluster, such as when clusters are
    nested circles on the 2D plane.

    If the affinity matrix is the adjacency matrix of a graph, this method
    can be used to find normalized graph cuts [1]_, [2]_.

    When calling ``fit``, an affinity matrix is constructed using either
    a kernel function such the Gaussian (aka RBF) kernel with Euclidean
    distance ``d(X, X)``::

            np.exp(-gamma * d(X,X) ** 2)

    or a k-nearest neighbors connectivity matrix.

    Alternatively, a user-provided affinity matrix can be specified by
    setting ``affinity='precomputed'``.

    Read more in the :ref:`User Guide <spectral_clustering>`.

    Parameters
    ----------
    n_clusters : int, default=8
        The dimension of the projection subspace.

    eigen_solver : {'arpack', 'lobpcg', 'amg'}, default=None
        The eigenvalue decomposition strategy to use. AMG requires pyamg
        to be installed. It can be faster on very large, sparse problems,
        but may also lead to instabilities. If None, then ``'arpack'`` is
        used. See [4]_ for more details regarding `'lobpcg'`.

    n_components : int, default=None
        Number of eigenvectors to use for the spectral embedding. If None,
        defaults to `n_clusters`.

    random_state : int, RandomState instance, default=None
        A pseudo random number generator used for the initialization
        of the lobpcg eigenvectors decomposition when `eigen_solver ==
        'amg'`, and for the K-Means initialization. Use an int to make
        the results deterministic across calls (See
        :term:`Glossary <random_state>`).

        .. note::
            When using `eigen_solver == 'amg'`,
            it is necessary to also fix the global numpy seed with
            `np.random.seed(int)` to get deterministic results. See
            https://github.com/pyamg/pyamg/issues/139 for further
            information.

    n_init : int, default=10
        Number of time the k-means algorithm will be run with different
        centroid seeds. The final results will be the best output of n_init
        consecutive runs in terms of inertia. Only used if
        ``assign_labels='kmeans'``.

    gamma : float, default=1.0
        Kernel coefficient for rbf, poly, sigmoid, laplacian and chi2 kernels.
        Ignored for ``affinity='nearest_neighbors'``, ``affinity='precomputed'``
        or ``affinity='precomputed_nearest_neighbors'``.

    affinity : str or callable, default='rbf'
        How to construct the affinity matrix.
         - 'nearest_neighbors': construct the affinity matrix by computing a
           graph of nearest neighbors.
         - 'rbf': construct the affinity matrix using a radial basis function
           (RBF) kernel.
         - 'precomputed': interpret ``X`` as a precomputed affinity matrix,
           where larger values indicate greater similarity between instances.
         - 'precomputed_nearest_neighbors': interpret ``X`` as a sparse graph
           of precomputed distances, and construct a binary affinity matrix
           from the ``n_neighbors`` nearest neighbors of each instance.
         - one of the kernels supported by
           :func:`~sklearn.metrics.pairwise.pairwise_kernels`.

        Only kernels that produce similarity scores (non-negative values that
        increase with similarity) should be used. This property is not checked
        by the clustering algorithm.

    n_neighbors : int, default=10
        Number of neighbors to use when constructing the affinity matrix using
        the nearest neighbors method. Ignored for ``affinity='rbf'``.

    eigen_tol : float, default="auto"
        Stopping criterion for eigen decomposition of the Laplacian matrix.
        If `eigen_tol="auto"` then the passed tolerance will depend on the
        `eigen_solver`:

        - If `eigen_solver="arpack"`, then `eigen_tol=0.0`;
        - If `eigen_solver="lobpcg"` or `eigen_solver="amg"`, then
          `eigen_tol=None` which configures the underlying `lobpcg` solver to
          automatically resolve the value according to their heuristics. See,
          :func:`scipy.sparse.linalg.lobpcg` for details.

        Note that when using `eigen_solver="lobpcg"` or `eigen_solver="amg"`
        values of `tol<1e-5` may lead to convergence issues and should be
        avoided.

        .. versionadded:: 1.2
           Added 'auto' option.

    assign_labels : {'kmeans', 'discretize', 'cluster_qr'}, default='kmeans'
        The strategy for assigning labels in the embedding space. There are two
        ways to assign labels after the Laplacian embedding. k-means is a
        popular choice, but it can be sensitive to initialization.
        Discretization is another approach which is less sensitive to random
        initialization [3]_.
        The cluster_qr method [5]_ directly extract clusters from eigenvectors
        in spectral clustering. In contrast to k-means and discretization, cluster_qr
        has no tuning parameters and runs no iterations, yet may outperform
        k-means and discretization in terms of both quality and speed.

        .. versionchanged:: 1.1
           Added new labeling method 'cluster_qr'.

    degree : float, default=3
        Degree of the polynomial kernel. Ignored by other kernels.

    coef0 : float, default=1
        Zero coefficient for polynomial and sigmoid kernels.
        Ignored by other kernels.

    kernel_params : dict of str to any, default=None
        Parameters (keyword arguments) and values for kernel passed as
        callable object. Ignored by other kernels.

    n_jobs : int, default=None
        The number of parallel jobs to run when `affinity='nearest_neighbors'`
        or `affinity='precomputed_nearest_neighbors'`. The neighbors search
        will be done in parallel.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    verbose : bool, default=False
        Verbosity mode.

        .. versionadded:: 0.24

    Attributes
    ----------
    affinity_matrix_ : array-like of shape (n_samples, n_samples)
        Affinity matrix used for clustering. Available only after calling
        ``fit``.

    labels_ : ndarray of shape (n_samples,)
        Labels of each point

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    sklearn.cluster.KMeans : K-Means clustering.
    sklearn.cluster.DBSCAN : Density-Based Spatial Clustering of
        Applications with Noise.

    Notes
    -----
    A distance matrix for which 0 indicates identical elements and high values
    indicate very dissimilar elements can be transformed into an affinity /
    similarity matrix that is well-suited for the algorithm by
    applying the Gaussian (aka RBF, heat) kernel::

        np.exp(- dist_matrix ** 2 / (2. * delta ** 2))

    where ``delta`` is a free parameter representing the width of the Gaussian
    kernel.

    An alternative is to take a symmetric version of the k-nearest neighbors
    connectivity matrix of the points.

    If the pyamg package is installed, it is used: this greatly
    speeds up computation.

    References
    ----------
    .. [1] :doi:`Normalized cuts and image segmentation, 2000
           Jianbo Shi, Jitendra Malik
           <10.1109/34.868688>`

    .. [2] :doi:`A Tutorial on Spectral Clustering, 2007
           Ulrike von Luxburg
           <10.1007/s11222-007-9033-z>`

    .. [3] `Multiclass spectral clustering, 2003
           Stella X. Yu, Jianbo Shi
           <https://people.eecs.berkeley.edu/~jordan/courses/281B-spring04/readings/yu-shi.pdf>`_

    .. [4] :doi:`Toward the Optimal Preconditioned Eigensolver:
           Locally Optimal Block Preconditioned Conjugate Gradient Method, 2001
           A. V. Knyazev
           SIAM Journal on Scientific Computing 23, no. 2, pp. 517-541.
           <10.1137/S1064827500366124>`

    .. [5] :doi:`Simple, direct, and efficient multi-way spectral clustering, 2019
           Anil Damle, Victor Minden, Lexing Ying
           <10.1093/imaiai/iay008>`

    Examples
    --------
    >>> from sklearn.cluster import SpectralClustering
    >>> import numpy as np
    >>> X = np.array([[1, 1], [2, 1], [1, 0],
    ...               [4, 7], [3, 5], [3, 6]])
    >>> clustering = SpectralClustering(n_clusters=2,
    ...         assign_labels='discretize',
    ...         random_state=0).fit(X)
    >>> clustering.labels_
    array([1, 1, 1, 0, 0, 0])
    >>> clustering
    SpectralClustering(assign_labels='discretize', n_clusters=2,
        random_state=0)
    r   Nleft)closed>   amgarpacklobpcgr3   r   >   rj   nearest_neighborsprecomputed_nearest_neighborsr6   ra   >   rb   r,   r[   neitherrh   rc   rd   rI   r3   re   gammar\   n_neighborsrf   rg   degreecoef0kernel_paramsn_jobsrh   _parameter_constraintsr_   r`   g      ?rbfrb      F)rd   rI   r3   re   rz   r\   r{   rf   rg   r|   r}   r~   r   rh   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        || _        d S Nry   )selfrc   rd   rI   r3   re   rz   r\   r{   rf   rg   r|   r}   r~   r   rh   s                   r+   __init__zSpectralClustering.__init__y  sw    & %(((
 &"*
*r-   Tr]   c                    t          | |g dt          j        d          }| j        dv }|j        d         |j        d         k    r|st          j        d           | j        dk    r0t          || j        d	| j	        
          }d||j
        z   z  | _        n| j        dk    rYt          | j        | j	        d                              |          }|                    |d          }d||j
        z   z  | _        nj| j        dk    r|| _        nW| j        }|i }t          | j                  s| j        |d<   | j        |d<   | j        |d<   t'          |f| j        d	d|| _        t)          | j                  }| j        | j        n| j        }t1          | j        || j        || j        d          }	| j        rt9          d| j                    | j        dk    r-t=          |	| j        || j        | j                  \  }
| _         }
n6| j        dk    rtC          |	          | _         ntE          |	|          | _         | S )a@  Perform spectral clustering from features, or affinity matrix.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features) or                 (n_samples, n_samples)
            Training instances to cluster, similarities / affinities between
            instances if ``affinity='precomputed'``, or distances between
            instances if ``affinity='precomputed_nearest_neighbors``. If a
            sparse matrix is provided in a format other than ``csr_matrix``,
            ``csc_matrix``, or ``coo_matrix``, it will be converted into a
            sparse ``csr_matrix``.

        y : Ignored
            Not used, present here for API consistency by convention.

        Returns
        -------
        self : object
            A fitted instance of the estimator.
        )csrcsccoor	   )accept_sparsedtypeensure_min_samplesrj   rw   r   r   zThe spectral clustering API has changed. ``fit``now constructs an affinity matrix from data. To use a custom affinity matrix, set ``affinity=precomputed``.rv   T)r{   include_selfr   g      ?rw   rj   )r{   r   metricconnectivity)XmodeNrz   r|   r}   )r   filter_paramsF)rI   rd   r3   rf   
drop_firstz!Computing label assignment using rb   )r3   re   rh   r,   )r3   )#r   r!   float64r\   r   warningswarnr   r{   r   r   affinity_matrix_r   rl   r~   callablerz   r|   r}   r   r   r3   rI   rc   r   rd   rf   rh   rG   rg   r   re   rm   r,   r[   )r   r   yallow_squaredr   	estimatorparamsr3   rI   mapsr'   s              r+   rl   zSpectralClustering.fit  s   . ///* 
 
 
  *
 
 71:##M#M0   =///+t/d4;  L %(<,.+H$ID!!]===( ,T[  c!ff  %555OOL$'<,.+H$ID!!]m++$%D!!'F~DM** -"&*w#';x "&*w$4%-t% %?E% %D! *$*;<<#08DOOd>O 	 #!%*%n
 
 
 < 	LJd6HJJKKK))!(){" " "At|QQ <//%d++DLL%dFFFDLr-   c                 H    t                                          ||          S )aD  Perform spectral clustering on `X` and return cluster labels.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features) or                 (n_samples, n_samples)
            Training instances to cluster, similarities / affinities between
            instances if ``affinity='precomputed'``, or distances between
            instances if ``affinity='precomputed_nearest_neighbors``. If a
            sparse matrix is provided in a format other than ``csr_matrix``,
            ``csc_matrix``, or ``coo_matrix``, it will be converted into a
            sparse ``csr_matrix``.

        y : Ignored
            Not used, present here for API consistency by convention.

        Returns
        -------
        labels : ndarray of shape (n_samples,)
            Cluster labels.
        )superfit_predict)r   r   r   	__class__s      r+   r   zSpectralClustering.fit_predict  s    , ww""1a(((r-   c                     t                                                      }d|j        _        | j        dv |j        _        |S )NTr   )r   __sklearn_tags__
input_tagssparser\   pairwise)r   tagsr   s     r+   r   z#SpectralClustering.__sklearn_tags__  s?    ww''))!%#'= 5
 $
  r-   )r_   r   )__name__
__module____qualname____doc__r   r   r   r   r   setr   dictr   __annotations__r   r   rl   r   r   __classcell__)r   s   @r+   rk   rk   {  sd        ` `F  x!T&AAAB#$?$?$?@@$G!(AtFCCCTJ'(8Haf===>(4D8889JM""WWWX 
 !1d6BBBCHT3V444Jx  
 %*%K%K%KLLM8D!T&999:(4tI>>>?T";1$ $D   : ! #! ! ! ! !F \555d d d 65dL) ) ) ) ) )0        r-   rk   )(r   r   numbersr   r   numpyr!   scipy.linalgr   r   r   scipy.sparser   baser
   r   r   manifold._spectral_embeddingr   metrics.pairwiser   r   	neighborsr   r   utilsr   r   utils._param_validationr   r   r   utils.validationr   _kmeansr   r,   r[   ro   rk    r-   r+   <module>r      s   ( (
  " " " " " " " "     - - - - - - - - - - # # # # # # < < < < < < < < < < > > > > > > > > > > > > > > : : : : : : : : 6 6 6 6 6 6 6 6 K K K K K K K K K K , , , , , ,      " " "B B2DD D D D DN ,01"'   v v v v	 vrg g g g g} g g g g gr-   