ó
    §ñ:i–w  ã            
       ó"  • S r SSKrSSKJrJr  SSKrSSKJrJ	r	J
r
  SSKJr  SSKJrJrJr  SSKJr  SS	KJrJr  SS
KJrJr  SSKJrJr  SSKJrJrJr  SSK J!r!  S r"SSSSS.S jr#\" SSS/0SS9SSSSSSSSS.S j5       r$ " S  S!\\5      r%g)"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é   )Úk_meansc           
      ó2  • U R                   S   n[        U R                  SS9u    p#[        XSU SS24   R                  5      u  pBn[	        [
        R                  " U [
        R                  " XER                  5       5      5      5      n U R                  SS9$ )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         Ú\/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/sklearn/cluster/_spectral.pyÚ
cluster_qrr+      s|   € ð2 	�‰�aÑ€AÜ�7—9‘9 tÑ,�I€A€qÜ�7˜r ˜7¢A˜:Ñ&×(Ñ(Ó)�H€Bˆ1Ü”"—&’&˜¤"§&¢&¨¯V©V«XÓ"6Ó7Ó8€GØ�>‰>˜qˆ>Ð!Ð!ó    Té   é   )ÚcopyÚmax_svd_restartsÚ
n_iter_maxÚrandom_statec                ó¼  • [        U5      n[        XS9n [        R                  " [        5      R
                  nU R                  u  pg[        R                  " U5      n[        U R                  S   5       Hy  n	U SS2U	4   [        R                  R                  U SS2U	4   5      -  U-  U SS2U	4'   U SU	4   S:w  d  MJ  SU SS2U	4   -  [        R                  " U SU	4   5      -  U SS2U	4'   M{     U [        R                  " U S-  R                  SS95      SS2[        R                  4   -  n Sn
SnX¢:  Gaï  U(       Gdç  [        R                  " Xw45      nXR                  U5      SS24   R                   USS2S4'   [        R                  " U5      n[        SU5       Ha  nU[        R"                  " [        R$                  " XSS2US-
  4   5      5      -  nXR'                  5       SS24   R                   USS2U4'   Mc     S	nSnU(       Gd  US-  n[        R$                  " X5      nUR)                  SS9n[+        [        R,                  " [/        U5      5      [        R0                  " SU5      U44Xg4S
9nUR                   U -  n [        R                  R3                  U5      u  nnnSUUR                  5       -
  -  n[#        UU-
  5      U:  d  UU:”  a  SnO-Un[        R$                  " UR                   UR                   5      nU(       d  GM  X¢:  a
  U(       d  GMç  U(       d  [5        S5      eW$ ! [4         a    U
S-  n
[7        S5         M@  f = f)aØ  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.

)r/   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$   r/   r0   r1   r2   r8   Ú	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*   Ú
discretizerZ   9   s  € ôn & lÓ3€Lä˜WÑ0€Gä
�(Š(”5‹/×
Ñ
€CØ%Ÿm™mÑ€Iô —’˜	Ó"€IÜ�7—=‘= Ñ#Ö$ˆØ ¢ A ™¬¯©¯©¸ÂÀ1À¹Ó)FÑFÈ)ÑSˆ’�1�‰Ø�1�a�4‰=˜AÕØ ª¨A¨¡Ñ.´·²¸ÀÀAÀ¹Ó1GÑGˆG’A�q�D‹Mñ %ð œŸš ¨!¡× 0Ñ 0°aÐ 0Ð 8Ó9º!¼R¿Z¹Z¸-ÑHÑH€Gà€LØ€Mð Ô*·Mô —8’8˜\Ð8Ó9ˆØ ×!5Ñ!5°iÓ!@Â!Ð!CÑD×FÑFˆ’�A�‰ô
 �HŠH�YÓˆÜ�q˜,Ö'ˆAð ”—’œŸš˜w²°A¸±E°Ñ(:Ó;Ó<Ñ<ˆAØ$§X¡X£Z² ]Ñ3×5Ñ5ˆH’Q˜�T‹Nñ	 (ð  #ÐØˆçØ�a‰KˆFäŸš Ó2ˆJà×&Ñ&¨AÐ&Ð.ˆFÜ)Ü—’œ˜V›Ó%¬¯	ª	°!°YÓ(?ÀÐ'HÐIØ Ð/ñ Ðð
 %×&Ñ&¨Ñ0ˆEðÜŸ9™9Ÿ=™=¨Ó/‘��1�bð  	¨A¯E©E«GÑ 3Ñ4ˆJÜ�JÐ!5Ñ5Ó6¸Ó<À&È:ÓBUØ $‘ð (2Ð$ÜŸ6š6 "§$¡$¨¯©Ó,�÷5  ‘-ð' Ó*·M±Mö^ ÜÐ0Ó1Ð1Ø€Møô ó Ø Ñ!�ÜÐJÔKÚðús   Ê#L= Ì=MÍMÚaffinityz
array-likezsparse matrixF©Úprefer_skip_nested_validationé   é
   ÚautoÚkmeans)Ú
n_clustersrH   Úeigen_solverr2   Ún_initÚ	eigen_tolÚassign_labelsÚverbosec                óZ   • [        UUUUUSUUUS9	R                  U 5      n	U	R                  $ )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.

    .. 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)	rb   rH   rc   r2   rd   r[   re   rf   rg   )ÚSpectralClusteringÚfitÚlabels_)
r[   rb   rH   rc   r2   rd   re   rf   rg   Ú	clusterers
             r*   Úspectral_clusteringrn   À   sF   € ôX #ØØ!Ø!Ø!ØØØØ#Øñ
÷ 
�cˆ(ƒmð ð ×ÑÐr,   c                   óš  ^ • \ rS rSr% Sr\" \SSSS9/\" 1 Sk5      S/\" \SSSS9S/S/\" \SSSS9/\" \S	SSS9/\	\" \
" \5      1 S
k-  5      /\" \SSSS9/\" \SSSS9\" S15      /\" 1 Sk5      /\" \S	SSS9/\" \SSSS9/\S/\S/S/S.r\\S'    S SSSSSSSSSSSSSSS.S jjr\" SS9S!S j5       rS!U 4S jjrS rSrU =r$ )"rj   i{  aS!  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Úlobpcgr2   r   >   ri   Únearest_neighborsÚprecomputed_nearest_neighborsr5   r`   >   ra   r+   rZ   Úneitherrg   ©rb   rc   rH   r2   rd   Úgammar[   Ún_neighborsre   rf   ÚdegreeÚcoef0Úkernel_paramsÚn_jobsrg   Ú_parameter_constraintsr_   g      ð?Úrbfra   é   F)rc   rH   r2   rd   ry   r[   rz   re   rf   r{   r|   r}   r~   rg   c                ó¸   • Xl         X l        X0l        X@l        XPl        X`l        Xpl        X€l        X�l        X l	        X°l
        XÀl        XÐl        Xàl        Xðl        g ©Nrx   )Úselfrb   rc   rH   r2   rd   ry   r[   rz   re   rf   r{   r|   r}   r~   rg   s                   r*   Ú__init__ÚSpectralClustering.__init__y  sU   € ð& %ŒØ(ÔØ(ÔØ(ÔØŒØŒ
Ø ŒØ&ÔØ"ŒØ*ÔØŒØŒ
Ø*ÔØŒØ�r,   Tr\   c           	      óZ  • U R                  U/ SQ[        R                  SS9nU R                  S;   nUR                  S   UR                  S   :X  a  U(       d  [
        R                  " S5        U R                  S:X  a6  [        XR                  S	U R                  S
9nSXDR                  -   -  U l        OòU R                  S:X  aU  [        U R                  U R                  SS9R                  U5      nUR                  USS9nSXDR                  -   -  U l        O�U R                  S:X  a  Xl        OvU R                  nUc  0 n[        U R                  5      (       d-  U R                   US'   U R"                  US'   U R$                  US'   ['        U4U R                  S	S.UD6U l        [)        U R*                  5      nU R,                  c  U R.                  OU R,                  n[1        U R                  UU R2                  UU R4                  SS9n	U R6                  (       a  [9        SU R:                   35        U R:                  S:X  a5  [=        U	U R.                  UU R>                  U R6                  S9u  o l         n
U $ U R:                  S:X  a  [C        U	5      U l         U $ [E        X—S9U l         U $ )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©ri   rv   r   r   z›The spectral clustering API has changed. ``fit``now constructs an affinity matrix from data. To use a custom affinity matrix, set ``affinity=precomputed``.ru   T)rz   Úinclude_selfr~   g      à?rv   ri   )rz   r~   ÚmetricÚconnectivity)ÚXÚmodery   r{   r|   )r�   Úfilter_paramsF)rH   rc   r2   re   Ú
drop_firstz!Computing label assignment using ra   )r2   rd   rg   r+   )r2   )#Ú_validate_datar    Úfloat64r[   r   ÚwarningsÚwarnr   rz   r~   r   Úaffinity_matrix_r   rk   r}   Úcallablery   r{   r|   r   r   r2   rH   rb   r   rc   re   rg   rF   rf   r   rd   rl   r+   rZ   )r„   r’   ÚyÚallow_squaredr‘   Ú	estimatorÚparamsr2   rH   Úmapsr&   s              r*   rk   ÚSpectralClustering.fitœ  s„  € ð. ×ÑØÚ/Ü—*‘*Ø ð	  ð 
ˆð Ÿ™ð *
ñ 
ˆð �7‰7�1‰:˜Ÿ™ ™Ó#®MÜ�MŠMð0ôð �=‰=Ð/Ó/Ü+Ø×/Ñ/¸dÈ4Ï;É;ñˆLð %(¨<¿.¹.Ñ+HÑ$IˆDÕ!Ø�]‰]Ð=Ó=Ü(Ø ×,Ñ,°T·[±[Èñç‰c�!‹fð ð %×5Ñ5¸ÀÐ5ÐOˆLØ$'¨<¿.¹.Ñ+HÑ$IˆDÕ!Ø�]‰]˜mÓ+Ø$%Õ!à×'Ñ'ˆFØ‰~Ø�Ü˜DŸM™M×*Ñ*Ø"&§*¡*��w‘Ø#'§;¡;��xÑ Ø"&§*¡*��w‘Ü$4Øð%ØŸ-™-°tñ%Ø?Eñ%ˆDÔ!ô *¨$×*;Ñ*;Ó<ˆà#×0Ñ0Ñ8ˆD�OŠO¸d×>OÑ>Oð 	ô #Ø×!Ñ!Ø%Ø×*Ñ*Ø%Ø—n‘nØñ
ˆð �<�<ÜÐ5°d×6HÑ6HÐ5IÐJÔKà×Ñ Ó)Ü!(ØØ—‘Ø)Ø—{‘{ØŸ™ñ"ÑˆAŒ|˜Qð ˆð ×Ñ <Ó/Ü% dÓ+ˆDŒLð ˆô & dÑFˆDŒLàˆr,   c                 ó"   >• [         TU ]  X5      $ )aÄ  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¤   ÚSpectralClustering.fit_predict  s   ø€ ô, ‰wÑ" 1Ó(Ð(r,   c                 ó$   • SU R                   S;   0$ )NÚpairwiserŽ   )r[   )r„   s    r*   Ú
_more_tagsÚSpectralClustering._more_tags  s   € à˜Ÿ™ðñð
ð 	
r,   )r[   rš   rf   r|   r{   rc   re   ry   r}   rl   rb   rH   rd   r~   rz   r2   rg   )r^   rƒ   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r   r›   Úsetr   Údictr   Ú__annotations__r…   r   rk   r¤   r©   Ú__static_attributes__Ú__classcell__)r¥   s   @r*   rj   rj   {  sq  ø‡ ñ`ñF   ¨!¨T¸&ÑAÐBÙ#Ò$?Ó@À$ÐGÙ! (¨A¨t¸FÑCÀTÐJØ'Ð(Ù˜H a¨°fÑ=Ð>Ù˜4  D°Ñ8Ð9àÙÙ�MÓ"ÚWñXóð
ñ ! ¨1¨d¸6ÑBÐCá�T˜3 ¨VÑ4Ù˜�xÓ ð
ñ %Ò%KÓLÐMÙ˜D ! T°&Ñ9Ð:Ù˜4  t°IÑ>Ð?Ø ˜Ø˜TÐ"Ø�;ñ1$Ð˜Dó ð: ð!ð ØØØØØØØØØØØØØö#!ñF °Ñ5ócó 6ðc÷J)÷0
ð 
r,   rj   )&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   Ú_kmeansr   r+   rZ   rn   rj   © r,   r*   Ú<module>rÁ      s¥   ðÙ (ó ß "ã ß -Ñ -Ý #ç <Ñ <Ý >ß >ß :ß 6ß KÑ KÝ ò"ðB ¨B¸2ÈDõDñN Ø�, Ð0Ð1Ø"'ñð ØØØØØØØôtó	ðtônf
˜ }õ f
r,   