ó
    ¦ñ:iã<  ã                   óÖ   • S r SSKrSSKJrJr  SSKrSSKJr  SSK	J
r
Jr  SSKJrJrJrJr  SSK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  SSK J!r!   " S S\\\5      r"g)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)Ú_fix_connected_components)Úcheck_is_fittedc                   ó~  • \ rS rSr% Sr\" \SSSS9S/\" \SSSS9S/\" \SSSS9/\" 1 S	k5      /\" \SSSS9/\" \SSSS9S/\" 1 S
k5      /\" 1 Sk5      /\S/\" \SSSS9/\" \	" \
5      S1-  5      \/\S/S.r\\S'   SSSSSSSSSSSSS.S jrS rS r\" SS9SS j5       r\" SS9SS j5       rS rS rSrg)ÚIsomapé   a:  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   r   Ú	minkowski©r'   r(   r)   r*   r+   r,   r-   r.   r/   r1   r0   r2   c                ó”   • Xl         X l        X0l        X@l        XPl        X`l        Xpl        X€l        X�l        X l	        X°l
        XÀl        g ©Nr6   )Úselfr'   r(   r)   r*   r+   r,   r-   r.   r/   r1   r0   r2   s                Ú[/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/sklearn/manifold/_isomap.pyÚ__init__ÚIsomap.__init__¶   sF   € ð  'ÔØŒØ(ÔØ(ÔØŒØ ŒØ&ÔØ#6Ô ØŒØŒØŒØ*Õó    c           
      óè  • U R                   b&  U R                  b  [        SU R                   S35      e[        U R                   U R                  U R                  U R
                  U R                  U R                  U R                  S9U l	        U R                  R                  U5        U R                  R                  U l        [        U R                  S5      (       a  U R                  R                  U l        [        U R                  SU R                   U R"                  U R$                  U R                  S9R'                  SS9U l        U R                   bL  [+        U R                  U R                   U R
                  U R                  U R                  S	U R                  S
9nOK[-        U R                  U R                  U R
                  U R                  U R                  S	U R                  S9n[/        U5      u  p4US:”  a–  U R
                  S:X  a  [1        U5      (       a  [3        SU S35      e[4        R6                  " SU S3SS9  [9        SU R                  R:                  UUUS	U R                  R<                  S.U R                  R>                  D6n[A        X RB                  SS9U l"        U R                  R:                  RF                  [H        RJ                  :X  a=  U RD                  RM                  U R                  R:                  RF                  SS9U l"        U RD                  S-  nUS-  nU R(                  RO                  U5      U l(        U RP                  RR                  S   U l*        g )Nz<Both n_neighbors and radius are provided. Use Isomap(radius=z=, n_neighbors=None) if intended to use radius-based neighbors)r'   r(   Ú	algorithmr1   r0   r2   r/   Úfeature_names_in_r&   )r)   Úkernelr*   r+   r,   r/   Údefault)Ú	transformÚdistance)r1   r0   r2   Úmoder/   )r(   r1   r0   r2   rE   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.r   )Ú
stacklevel)ÚXÚgraphÚn_connected_componentsÚcomponent_labelsrE   r1   F)ÚmethodÚdirected)Úcopyç      à¿© )+r'   r(   Ú
ValueErrorr   r.   r1   r0   r2   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-   Údist_matrix_ÚdtypeÚnpÚfloat32ÚastypeÚfit_transformÚ
embedding_ÚshapeÚ_n_features_out)r9   rG   ÚnbgrI   ÚlabelsÚGs         r:   Ú_fit_transformÚIsomap._fit_transformÓ   s  € Ø×ÑÑ'¨D¯K©KÑ,CÜð"Ø"&§+¡+ ð /*ð*óð ô &Ø×(Ñ(Ø—;‘;Ø×.Ñ.Ø—;‘;Ø�f‰fØ×,Ñ,Ø—;‘;ñ
ˆŒ
ð 	�
‰
�‰�qÔØ"Ÿj™j×7Ñ7ˆÔÜ�4—:‘:Ð2×3Ñ3Ø%)§Z¡Z×%AÑ%AˆDÔ"ä$Ø×*Ñ*Ø Ø×*Ñ*Ø—‘Ø—]‘]Ø—;‘;ñ
÷ ‰*˜yˆ*Ð
)ð 	Ôð ×ÑÑ'Ü"Ø—
‘
Ø× Ñ Ø—{‘{Ø—&‘&Ø"×0Ñ0ØØ—{‘{ñ‰Cô )Ø—
‘
Ø—{‘{Ø—{‘{Ø—&‘&Ø"×0Ñ0ØØ—{‘{ñˆCô *>¸cÓ)BÑ&ÐØ! AÓ%Ø�{‰{˜mÓ+´¸·±Ü"ðØ1Ð2ð 3;ð;óð ô �MŠMðØ0Ð1ð 2(ð(ð
 òô ,ð Ø—*‘*×#Ñ#ØØ'=Ø!'ØØ—z‘z×3Ñ3ñð —*‘*×5Ñ5ñˆCô *¨#×6FÑ6FÐQVÑWˆÔà�:‰:×Ñ×"Ñ"¤b§j¡jÓ0Ø $× 1Ñ 1× 8Ñ 8Ø—
‘
×!Ñ!×'Ñ'¨eð !9ð !ˆDÔð ×Ñ˜qÑ ˆØ	ˆT‰	ˆà×*Ñ*×8Ñ8¸Ó;ˆŒØ#Ÿ™×4Ñ4°QÑ7ˆÕr=   c                 ó2  • SU R                   S-  -  n[        5       R                  U5      nU R                  R                  n[
        R                  " [
        R                  " US-  5      [
        R                  " US-  5      -
  5      UR                  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)``
rN   r   r   )	r]   r   rb   rV   Úeigenvalues_r_   ÚsqrtÚsumrd   )r9   rh   ÚG_centerÚevalss       r:   Úreconstruction_errorÚIsomap.reconstruction_error8  sx   € ð( �4×$Ñ$ aÑ'Ñ'ˆÜ!Ó#×1Ñ1°!Ó4ˆØ× Ñ ×-Ñ-ˆÜ�wŠw”r—v’v˜h¨™kÓ*¬R¯VªV°E¸1±HÓ-=Ñ=Ó>ÀÇÁÈÁÑKÐKr=   F)Úprefer_skip_nested_validationc                 ó(   • U R                  U5        U $ )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.
)ri   ©r9   rG   Úys      r:   rR   Ú
Isomap.fitQ  s   € ð, 	×Ñ˜AÔØˆr=   c                 ó<   • U R                  U5        U R                  $ )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.
)ri   rc   ru   s      r:   rb   ÚIsomap.fit_transformj  s   € ð* 	×Ñ˜AÔØ�‰Ðr=   c                 ó”  • [        U 5        U R                  b  U R                  R                  USS9u  p#OU R                  R	                  USS9u  p#U R                  R
                  nUR                  S   n[        US5      (       a/  UR                  [        R                  :X  a  [        R                  nO[        R                  n[        R                  " XT4U5      n[        U5       H7  n[        R                  " U R                  X8      X(   SS2S4   -   S5      Xx'   M9     US-  nUS-  nU R                   R#                  U5      $ )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^   r   rN   )r   r'   rQ   Ú
kneighborsÚradius_neighborsÚn_samples_fit_rd   rT   r^   r_   r`   Úfloat64ÚzerosÚrangeÚminr]   rV   rC   )	r9   rG   Ú	distancesÚindicesÚn_samples_fitÚ	n_queriesr^   ÚG_XÚis	            r:   rC   ÚIsomap.transform‚  s  € ô. 	˜ÔØ×ÑÑ'Ø!%§¡×!6Ñ!6°qÈ$Ð!6Ð!OÑˆI�wà!%§¡×!<Ñ!<¸QÐPTÐ!<Ð!UÑˆIð Ÿ
™
×1Ñ1ˆØ—O‘O AÑ&ˆ	ä�1�g×Ñ 1§7¡7¬b¯j©jÓ#8Ü—J‘J‰Eä—J‘JˆEä�hŠh˜	Ð1°5Ó9ˆÜ�yÖ!ˆAÜ—V’V˜D×-Ñ-¨g©jÑ9¸I¹LÊÈDÈÑ<QÑQÐSTÓUˆC‹Fñ "ð 	�‰	ˆØˆt‰ˆà×Ñ×)Ñ)¨#Ó.Ð.r=   c                 óF   • S[         R                  [         R                  /0$ )NÚpreserves_dtype)r_   r   r`   )r9   s    r:   Ú
_more_tagsÚIsomap._more_tagsµ  s   € Ø!¤B§J¡J´·
±
Ð#;Ð<Ð<r=   )re   r]   r*   rc   r@   rV   r,   r1   r2   r)   rS   r/   r'   rQ   r.   r0   r-   r(   r+   r8   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r   Úsetr   ÚcallableÚdictr3   Ú__annotations__r;   ri   rq   r   rR   rb   rC   rŒ   Ú__static_attributes__rO   r=   r:   r   r      sM  ‡ ñIñX ! ¨1¨d¸6ÑBÀDÐIÙ˜D ! T°&Ñ9¸4Ð@Ù! (¨A¨t¸FÑCÐDÙ#Ò$?Ó@ÐAÙ˜˜q $¨vÑ6Ð7Ù˜h¨¨4¸Ñ?ÀÐFÙ"Ò#6Ó7Ð8Ù *Ò+TÓ UÐVØ˜TÐ"Ù�t˜Q ¨VÑ4Ð5Ù™c .Ó1°]°OÑCÓDÀhÐOØ ˜ñ$Ð˜Dó ð$ ØØØØØØØ"ØØØ
Øõ+ò:c8òJLñ2 à&+ñóó	ðñ* à&+ñóó	ðò(1/õf=r=   r   )#r’   rX   Únumbersr   r   Únumpyr_   Úscipy.sparser   Úscipy.sparse.csgraphr   r   Úbaser	   r
   r   r   Údecompositionr   Úmetrics.pairwiser   Ú	neighborsr   r   r   Úpreprocessingr   Úutils._param_validationr   r   Úutils.graphr   Úutils.validationr   r   rO   r=   r:   Ú<module>r¤      sQ   ðÙ "ó ß "ã Ý !ß D÷ó õ &Ý -ß RÑ RÝ *ß :Ý 3Ý .ô[=Ð,Ð.>Àõ [=r=   