
    2;ji                         d Z ddlmZ ddl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 dd	lmZ dd
lmZ  G d de          ZdS )z6
Classical multi-dimensional scaling (classical MDS).
    )IntegralN)linalg)BaseEstimator_fit_context)pairwise_distances)check_symmetric)Interval)svd_flip)validate_datac                        e Zd ZU dZ eeddd          geegedgdZ	ee
d<   	 dd	dd
dZ fdZddZ ed          dd            Z xZS )ClassicalMDSa7  Classical multidimensional scaling (MDS).

    This is also known as principal coordinates analysis (PCoA) or
    Torgerson's scaling. It is a version of MDS that has exact solution
    in terms of eigendecomposition. If the input dissimilarity matrix
    consists of the pairwise Euclidean distances between some vectors,
    then classical MDS is equivalent to PCA applied to this set of vectors.

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

    Parameters
    ----------
    n_components : int, default=2
        Number of embedding dimensions.

    metric : str or callable, default='euclidean'
        Metric to use for dissimilarity computation. Default is "euclidean".

        If metric is a string, it must be one of the options allowed by
        `scipy.spatial.distance.pdist` for its metric parameter, or a metric
        listed in :func:`sklearn.metrics.pairwise.distance_metrics`

        If metric is "precomputed", X is assumed to be a distance matrix and
        must be square during fit.

        If metric is a callable function, it takes two arrays representing 1D
        vectors as inputs and must return one value indicating the distance
        between those vectors. This works for Scipy's metrics, but is less
        efficient than passing the metric name as a string.

    metric_params : dict, default=None
        Additional keyword arguments for the dissimilarity computation.

    Attributes
    ----------
    embedding_ : ndarray of shape (n_samples, n_components)
        Stores the position of the dataset in the embedding space.

    dissimilarity_matrix_ : ndarray of shape (n_samples, n_samples)
        Pairwise dissimilarities between the points.

    eigenvalues_ : ndarray of shape (n_components,)
        Eigenvalues of the double-centered dissimilarity matrix, corresponding
        to each of the selected components. They are equal to the squared 2-norms
        of the `n_components` variables in the embedding space.

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

    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.

    See Also
    --------
    sklearn.decomposition.PCA : Principal component analysis.
    MDS : Metric and non-metric MDS.

    References
    ----------
    .. [1] "Modern Multidimensional Scaling - Theory and Applications" Borg, I.;
       Groenen P. Springer Series in Statistics (1997)

    Examples
    --------
    >>> from sklearn.datasets import load_digits
    >>> from sklearn.manifold import ClassicalMDS
    >>> X, _ = load_digits(return_X_y=True)
    >>> X.shape
    (1797, 64)
    >>> cmds = ClassicalMDS(n_components=2)
    >>> X_emb = cmds.fit_transform(X[:100])
    >>> X_emb.shape
    (100, 2)
       Nleft)closedn_componentsmetricmetric_params_parameter_constraints   	euclidean)r   r   c                0    || _         || _        || _        d S Nr   )selfr   r   r   s       Y/root/voice-cloning/.venv/lib/python3.11/site-packages/sklearn/manifold/_classical_mds.py__init__zClassicalMDS.__init__h   s!     )*    c                 r    t                                                      }| j        dk    |j        _        |S )Nprecomputed)super__sklearn_tags__r   
input_tagspairwise)r   tags	__class__s     r   r!   zClassicalMDS.__sklearn_tags__s   s.    ww''))#';-#? r   c                 0    |                      |           | S )a  
        Compute the embedding positions.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features) or                 (n_samples, n_samples)
            Input data. If ``metric=='precomputed'``, the input should
            be the dissimilarity matrix.

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

        Returns
        -------
        self : object
            Fitted estimator.
        )fit_transform)r   Xys      r   fitzClassicalMDS.fitx   s    & 	1r   T)prefer_skip_nested_validationc                    t          | |          }| j        dk    r#|| _        t          | j        d          | _        n't	          |fd| j        i| j        | j        ni | _        | j        dz  }|                    t          j                  }|t          j	        |d          z  }|t          j	        |d	d
          z  }|dz  }t          j        |          \  }}|ddd         d| j                 }|dddddf         ddd| j        f         }t          |d          \  }}t          j        |          |z  | _        || _        | j        S )a  
        Compute and return the embedding positions.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features) or                 (n_samples, n_samples)
            Input data. If ``metric=='precomputed'``, the input should
            be the dissimilarity matrix.

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

        Returns
        -------
        X_new : ndarray of shape (n_samples, n_components)
            The embedding coordinates.
        r   T)raise_exceptionr   Nr   r   )axisr   )r.   keepdimsg      )r   r   dissimilarity_matrix_r   r   r   astypenpfloat64meanr   eighr   r
   sqrt
embedding_eigenvalues_)r   r(   r)   BwU_s          r   r'   zClassicalMDS.fit_transform   s   * $"";-'')*D&)8*D* * *D&& *<* *{* *.);)G4%%R* *D& &)HHRZ  	RWQQ	RWQQ....	T	 {1~~1 dddG'd''(aaa2gJqqq-D---. 4  1'!**q.r   )r   r   )__name__
__module____qualname____doc__r	   r   strcallabledictr   __annotations__r   r!   r*   r   r'   __classcell__)r%   s   @r   r   r      s         J JZ "(AtFCCCD/$ $D    	+ 	+ 	+ 	+ 	+ 	+    
   , \5557 7 7 657 7 7 7 7r   r   )rA   numbersr   numpyr3   scipyr   sklearn.baser   r   sklearn.metricsr   sklearn.utilsr   sklearn.utils._param_validationr	   sklearn.utils.extmathr
   sklearn.utils.validationr   r    r   r   <module>rQ      s                     4 4 4 4 4 4 4 4 . . . . . . ) ) ) ) ) ) 4 4 4 4 4 4 * * * * * * 2 2 2 2 2 2q q q q q= q q q q qr   