§
    rŠtjÙ=  ã                   óê   — d Z ddlZddlmZmZ ddlZddlmZ ddl	m
Z
mZ ddlmZmZmZmZ ddl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 ddl m!Z! ddl"m#Z#  G d„ deee¦  «        Z$dS )zIsomap for manifold learningé    N)ÚIntegralÚReal)Úissparse)Úconnected_componentsÚshortest_path)ÚBaseEstimatorÚClassNamePrefixFeaturesOutMixinÚTransformerMixinÚ_fit_context)Ú	KernelPCA)Ú_VALID_METRICS)ÚNearestNeighborsÚkneighbors_graphÚradius_neighbors_graph)ÚKernelCenterer)ÚIntervalÚ
StrOptions)Ú_ensure_sparse_index_int32)Ú_fix_connected_components)Úcheck_is_fittedc                   ó  ‡ — e Zd ZU dZ eeddd¬¦  «        dg eeddd¬¦  «        dg eeddd¬¦  «        g eh d£¦  «        g eeddd¬¦  «        g eeddd¬¦  «        dg eh d	£¦  «        g eh d
£¦  «        gedg eeddd¬¦  «        g e ee	¦  «        dhz  ¦  «        e
gedgdœZeed<   dddddddddddddœd„Zd„ Zd„ Z ed¬¦  «        dd„¦   «         Z ed¬¦  «        dd„¦   «         Zd„ Zˆ fd„Zˆ xZS )ÚIsomapaÎ  Isomap Embedding.

    Non-linear dimensionality reduction through Isometric Mapping

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

    Parameters
    ----------
    n_neighbors : int or None, default=5
        Number of neighbors to consider for each point. If `n_neighbors` is an int,
        then `radius` must be `None`.

    radius : float or None, default=None
        Limiting distance of neighbors to return. If `radius` is a float,
        then `n_neighbors` must be set to `None`.

        .. versionadded:: 1.1

    n_components : int, default=2
        Number of coordinates for the manifold.

    eigen_solver : {'auto', 'arpack', 'dense'}, default='auto'
        'auto' : Attempt to choose the most efficient solver
        for the given problem.

        'arpack' : Use Arnoldi decomposition to find the eigenvalues
        and eigenvectors.

        'dense' : Use a direct solver (i.e. LAPACK)
        for the eigenvalue decomposition.

    tol : float, default=0
        Convergence tolerance passed to arpack or lobpcg.
        not used if eigen_solver == 'dense'.

    max_iter : int, default=None
        Maximum number of iterations for the arpack solver.
        not used if eigen_solver == 'dense'.

    path_method : {'auto', 'FW', 'D'}, default='auto'
        Method to use in finding shortest path.

        'auto' : attempt to choose the best algorithm automatically.

        'FW' : Floyd-Warshall algorithm.

        'D' : Dijkstra's algorithm.

    neighbors_algorithm : {'auto', 'brute', 'kd_tree', 'ball_tree'},                           default='auto'
        Algorithm to use for nearest neighbors search,
        passed to neighbors.NearestNeighbors instance.

    n_jobs : int or None, default=None
        The number of parallel jobs to run.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    metric : str, or callable, default="minkowski"
        The metric to use when calculating distance between instances in a
        feature array. If metric is a string or callable, it must be one of
        the options allowed by :func:`sklearn.metrics.pairwise_distances` for
        its metric parameter.
        If metric is "precomputed", X is assumed to be a distance matrix and
        must be square. X may be a :term:`Glossary <sparse graph>`.

        .. versionadded:: 0.22

    p : float, default=2
        Parameter for the Minkowski metric from
        sklearn.metrics.pairwise.pairwise_distances. When p = 1, this is
        equivalent to using manhattan_distance (l1), and euclidean_distance
        (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.

        .. versionadded:: 0.22

    metric_params : dict, default=None
        Additional keyword arguments for the metric function.

        .. versionadded:: 0.22

    Attributes
    ----------
    embedding_ : array-like, shape (n_samples, n_components)
        Stores the embedding vectors.

    kernel_pca_ : object
        :class:`~sklearn.decomposition.KernelPCA` object used to implement the
        embedding.

    nbrs_ : sklearn.neighbors.NearestNeighbors instance
        Stores nearest neighbors instance, including BallTree or KDtree
        if applicable.

    dist_matrix_ : array-like, shape (n_samples, n_samples)
        Stores the geodesic distance matrix of training data.

    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.decomposition.PCA : Principal component analysis that is a linear
        dimensionality reduction method.
    sklearn.decomposition.KernelPCA : Non-linear dimensionality reduction using
        kernels and PCA.
    MDS : Manifold learning using multidimensional scaling.
    TSNE : T-distributed Stochastic Neighbor Embedding.
    LocallyLinearEmbedding : Manifold learning using Locally Linear Embedding.
    SpectralEmbedding : Spectral embedding for non-linear dimensionality.

    References
    ----------

    .. [1] Tenenbaum, J.B.; De Silva, V.; & Langford, J.C. A global geometric
           framework for nonlinear dimensionality reduction. Science 290 (5500)

    Examples
    --------
    >>> from sklearn.datasets import load_digits
    >>> from sklearn.manifold import Isomap
    >>> X, _ = load_digits(return_X_y=True)
    >>> X.shape
    (1797, 64)
    >>> embedding = Isomap(n_components=2)
    >>> X_transformed = embedding.fit_transform(X[:100])
    >>> X_transformed.shape
    (100, 2)
    é   NÚleft)Úclosedr   Úboth>   ÚautoÚdenseÚarpack>   ÚDÚFWr   >   r   ÚbruteÚkd_treeÚ	ball_treeÚprecomputed)Ún_neighborsÚradiusÚn_componentsÚeigen_solverÚtolÚmax_iterÚpath_methodÚneighbors_algorithmÚn_jobsÚpÚmetricÚmetric_paramsÚ_parameter_constraintsé   é   r   Ú	minkowski©r&   r'   r(   r)   r*   r+   r,   r-   r.   r0   r/   r1   c                ó®   — || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        d S ©Nr6   )Úselfr&   r'   r(   r)   r*   r+   r,   r-   r.   r0   r/   r1   s                úV/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/manifold/_isomap.pyÚ__init__zIsomap.__init__¸   sd   € ð  'ˆÔØˆŒØ(ˆÔØ(ˆÔØˆŒØ ˆŒØ&ˆÔØ#6ˆÔ ØˆŒØˆŒØˆŒØ*ˆÔÐÐó    c           
      ó|  — | j         �| j        �t          d| j        › d�¦  «        ‚t          | j         | j        | j        | j        | j        | j        | j        ¬¦  «        | _	        | j	         
                    |¦  «         | j	        j        | _        t          | j	        d¦  «        r| j	        j        | _        t          | j        d| j        | j        | j        | j        ¬¦  «                             d¬¦  «        | _        | j         �5t+          | j	        | j         | j        | j        | j        d	| j        ¬
¦  «        }n4t-          | j	        | j        | j        | j        | j        d	| j        ¬¦  «        }t/          |¦  «        \  }}|dk    rx| j        dk    r"t1          |¦  «        rt3          d|› d�¦  «        ‚t5          j        d|› d�d¬¦  «         t9          d| j	        j        |||d	| j	        j        dœ| j	        j        ¤Ž}tA          |¦  «         tC          || j"        d¬¦  «        | _#        | j	        j        j$        tJ          j&        k    r0| j#         '                    | j	        j        j$        d¬¦  «        | _#        | j#        dz  }|dz  }| j         (                    |¦  «        | _)        | j)        j*        d         | _+        d S )Nz<Both n_neighbors and radius are provided. Use Isomap(radius=z=, n_neighbors=None) if intended to use radius-based neighbors)r&   r'   Ú	algorithmr0   r/   r1   r.   Úfeature_names_in_r%   )r(   Úkernelr)   r*   r+   r.   Údefault)Ú	transformÚdistance)r0   r/   r1   Úmoder.   )r'   r0   r/   r1   rD   r.   r   z=The number of connected components of the neighbors graph is zä > 1. The graph cannot be completed with metric='precomputed', and Isomap cannot befitted. Increase the number of neighbors to avoid this issue, or precompute the full distance matrix instead of passing a sparse neighbors graph.zm > 1. Completing the graph to fit Isomap might be slow. Increase the number of neighbors to avoid this issue.r4   )Ú
stacklevel)ÚXÚgraphÚn_connected_componentsÚcomponent_labelsrD   r0   F)ÚmethodÚdirected)Úcopyç      à¿© ),r&   r'   Ú
ValueErrorr   r-   r0   r/   r1   r.   Únbrs_ÚfitÚn_features_in_Úhasattrr?   r   r(   r)   r*   r+   Ú
set_outputÚkernel_pca_r   r   r   r   ÚRuntimeErrorÚwarningsÚwarnr   Ú_fit_XÚeffective_metric_Úeffective_metric_params_r   r   r,   Údist_matrix_ÚdtypeÚnpÚfloat32ÚastypeÚfit_transformÚ
embedding_ÚshapeÚ_n_features_out)r9   rF   ÚnbgrH   ÚlabelsÚGs         r:   Ú_fit_transformzIsomap._fit_transformÕ   s  € ØÔÐ'¨D¬KÐ,CÝð*Ø"&¤+ð*ð *ð *ñô ð õ &ØÔ(Ø”;ØÔ.Ø”;ØŒfØÔ,Ø”;ð
ñ 
ô 
ˆŒ
ð 	Œ
�Š�qÑÔÐØ"œjÔ7ˆÔÝ�4”:Ð2Ñ3Ô3ð 	BØ%)¤ZÔ%AˆDÔ"å$ØÔ*Ø ØÔ*Ø”Ø”]Ø”;ð
ñ 
ô 
÷ Š*˜yˆ*Ñ
)Ô
)ð 	Ôð ÔÐ'Ý"Ø”
ØÔ Ø”{Ø”&Ø"Ô0ØØ”{ðñ ô ˆCˆCõ )Ø”
Ø”{Ø”{Ø”&Ø"Ô0ØØ”{ðñ ô ˆCõ *>¸cÑ)BÔ)BÑ&Ð Ø! AÒ%Ð%ØŒ{˜mÒ+Ð+µ¸±´Ð+Ý"ð;Ø1ð;ð ;ð ;ñô ð õ ŒMð(Ø0ð(ð (ð (ð
 ðñ ô ð õ ,ð Ø”*Ô#ØØ'=Ø!'ØØ”zÔ3ðð ð ”*Ô5ðð ˆCõ 	# 3Ñ'Ô'Ð'Ý)¨#°dÔ6FÐQVÐWÑWÔWˆÔàŒ:ÔÔ"¥b¤jÒ0Ð0Ø $Ô 1× 8Ò 8Ø”
Ô!Ô'¨eð !9ñ !ô !ˆDÔð Ô˜qÑ ˆØ	ˆT‰	ˆàÔ*×8Ò8¸Ñ;Ô;ˆŒØ#œÔ4°QÔ7ˆÔÐÐr<   c                 ó  — d| j         dz  z  }t          ¦   «                              |¦  «        }| j        j        }t          j        t          j        |dz  ¦  «        t          j        |dz  ¦  «        z
  ¦  «        |j        d         z  S )a(  Compute the reconstruction error for the embedding.

        Returns
        -------
        reconstruction_error : float
            Reconstruction error.

        Notes
        -----
        The cost function of an isomap embedding is

        ``E = frobenius_norm[K(D) - K(D_fit)] / n_samples``

        Where D is the matrix of distances for the input data X,
        D_fit is the matrix of distances for the output embedding X_fit,
        and K is the isomap kernel:

        ``K(D) = -0.5 * (I - 1/n_samples) * D^2 * (I - 1/n_samples)``
        rM   r4   r   )	r\   r   ra   rU   Úeigenvalues_r^   ÚsqrtÚsumrc   )r9   rg   ÚG_centerÚevalss       r:   Úreconstruction_errorzIsomap.reconstruction_error;  sv   € ð( �4Ô$ aÑ'Ñ'ˆÝ!Ñ#Ô#×1Ò1°!Ñ4Ô4ˆØÔ Ô-ˆÝŒw•r”v˜h¨™kÑ*Ô*­R¬V°E¸1±HÑ-=Ô-=Ñ=Ñ>Ô>ÀÄÈÄÑKÐKr<   F)Úprefer_skip_nested_validationc                 ó0   — |                       |¦  «         | S )a  Compute the embedding vectors for data X.

        Parameters
        ----------
        X : {array-like, sparse matrix, BallTree, KDTree, NearestNeighbors}
            Sample data, shape = (n_samples, n_features), in the form of a
            numpy array, sparse matrix, precomputed tree, or NearestNeighbors
            object.

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

        Returns
        -------
        self : object
            Returns a fitted instance of self.
        )rh   ©r9   rF   Úys      r:   rQ   z
Isomap.fitT  s   € ð, 	×Ò˜AÑÔÐØˆr<   c                 ó:   — |                       |¦  «         | j        S )aö  Fit the model from data in X and transform X.

        Parameters
        ----------
        X : {array-like, sparse matrix, BallTree, KDTree}
            Training vector, where `n_samples` is the number of samples
            and `n_features` is the number of features.

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

        Returns
        -------
        X_new : array-like, shape (n_samples, n_components)
            X transformed in the new space.
        )rh   rb   rr   s      r:   ra   zIsomap.fit_transformm  s    € ð* 	×Ò˜AÑÔÐØŒÐr<   c                 ól  — t          | ¦  «         | j        � | j                             |d¬¦  «        \  }}n| j                             |d¬¦  «        \  }}| j        j        }|j        d         }t          |d¦  «        r"|j        t          j
        k    rt          j
        }nt          j        }t          j        ||f|¦  «        }t          |¦  «        D ]>}t          j        | j        ||                  ||         dd…df         z   d¦  «        ||<   Œ?|dz  }|dz  }| j                             |¦  «        S )a›  Transform X.

        This is implemented by linking the points X into the graph of geodesic
        distances of the training data. First the `n_neighbors` nearest
        neighbors of X are found in the training data, and from these the
        shortest geodesic distances from each point in X to each point in
        the training data are computed in order to construct the kernel.
        The embedding of X is the projection of this kernel onto the
        embedding vectors of the training set.

        Parameters
        ----------
        X : {array-like, sparse matrix}, shape (n_queries, n_features)
            If neighbors_algorithm='precomputed', X is assumed to be a
            distance matrix or a sparse graph of shape
            (n_queries, n_samples_fit).

        Returns
        -------
        X_new : array-like, shape (n_queries, n_components)
            X transformed in the new space.
        NT)Úreturn_distancer   r]   r4   rM   )r   r&   rP   Ú
kneighborsÚradius_neighborsÚn_samples_fit_rc   rS   r]   r^   r_   Úfloat64ÚzerosÚrangeÚminr\   rU   rB   )	r9   rF   Ú	distancesÚindicesÚn_samples_fitÚ	n_queriesr]   ÚG_XÚis	            r:   rB   zIsomap.transform…  s6  € õ. 	˜ÑÔÐØÔÐ'Ø!%¤×!6Ò!6°qÈ$Ð!6Ñ!OÔ!OÑˆI�w�wà!%¤×!<Ò!<¸QÐPTÐ!<Ñ!UÔ!UÑˆI�wð œ
Ô1ˆØ”O AÔ&ˆ	å�1�gÑÔð 	 1¤7­b¬jÒ#8Ð#8Ý”JˆEˆEå”JˆEåŒh˜	 =Ð1°5Ñ9Ô9ˆÝ�yÑ!Ô!ð 	Vð 	VˆAÝ”V˜DÔ-¨g°a¬jÔ9¸IÀa¼LÈÈÈÈDÈÔ<QÑQÐSTÑUÔUˆC�‰FˆFà�‰	ˆØˆt‰ˆàÔ×)Ò)¨#Ñ.Ô.Ð.r<   c                 ó|   •— t          ¦   «                              ¦   «         }ddg|j        _        d|j        _        |S )Nrz   r_   T)ÚsuperÚ__sklearn_tags__Útransformer_tagsÚpreserves_dtypeÚ
input_tagsÚsparse)r9   ÚtagsÚ	__class__s     €r:   r†   zIsomap.__sklearn_tags__¸  s7   ø€ Ý‰wŒw×'Ò'Ñ)Ô)ˆØ1:¸IÐ0FˆÔÔ-Ø!%ˆŒÔØˆr<   r8   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Úsetr   ÚcallableÚdictr2   Ú__annotations__r;   rh   ro   r   rQ   ra   rB   r†   Ú__classcell__)rŒ   s   @r:   r   r      s\  ø€ € € € € € ðIð IðX !˜ ¨1¨d¸6ÐBÑBÔBÀDÐIØ�8˜D ! T°&Ð9Ñ9Ô9¸4Ð@Ø!˜ (¨A¨t¸FÐCÑCÔCÐDØ#˜Ð$?Ð$?Ð$?Ñ@Ô@ÐAØ�˜˜q $¨vÐ6Ñ6Ô6Ð7Ø�X˜h¨¨4¸Ð?Ñ?Ô?ÀÐFØ"˜
Ð#6Ð#6Ð#6Ñ7Ô7Ð8Ø * 
Ð+TÐ+TÐ+TÑ UÔ UÐVØ˜TÐ"Øˆh�t˜Q ¨VÐ4Ñ4Ô4Ð5Ø�:˜c˜c .Ñ1Ô1°]°OÑCÑDÔDÀhÐOØ ˜ð$ð $Ð˜Dð ð ñ ð$ ØØØØØØØ"ØØØ
Øð+ð +ð +ð +ð +ð:d8ð d8ð d8ðLLð Lð Lð2 €\à&+ðñ ô ðð ð ñ	ô ðð* €\à&+ðñ ô ðð ð ñ	ô ðð(1/ð 1/ð 1/ðfð ð ð ð ð ð ð ð r<   r   )%r�   rW   Únumbersr   r   Únumpyr^   Úscipy.sparser   Úscipy.sparse.csgraphr   r   Úsklearn.baser   r	   r
   r   Úsklearn.decompositionr   Úsklearn.metrics.pairwiser   Úsklearn.neighborsr   r   r   Úsklearn.preprocessingr   Úsklearn.utils._param_validationr   r   Úsklearn.utils.fixesr   Úsklearn.utils.graphr   Úsklearn.utils.validationr   r   rN   r<   r:   ú<module>r£      sˆ  ðØ "Ð "ð
 €€€Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ Dðð ð ð ð ð ð ð ð ð ð ð ð ,Ð +Ð +Ð +Ð +Ð +Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XØ 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ø :Ð :Ð :Ð :Ð :Ð :Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4ð_ð _ð _ð _ð _Ð,Ð.>Àñ _ô _ð _ð _ð _r<   