U
    Åmœd>  ã                   @   sŒ   d 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 deeeeeed eeeeeedf eee dœdd„ZdS )z)Embed high-dimensional data using TriMap
é    )ÚOptionalÚUnion)ÚAnnDataNé   )Úsettings)ÚLiteral)Úloggingé   é
   é   Ú	euclideanç     @@ç     @�@é�  F)Úangularr   ZhammingZ	manhattan)ÚadataÚn_componentsÚ	n_inliersÚ
n_outliersÚn_randomÚmetricÚ
weight_adjÚlrÚn_itersÚverboseÚcopyÚreturnc                 C   s&  zddl m} W n tk
r,   tdƒ‚Y nX |
r:|  ¡ n| } t d¡}|
rT|  ¡ n| } |	dkrftjn|	}t|t	ƒrx|n|dk}	d| j
kr¼| j
d jd }| j
d dd…dt|dƒ…f }n"| j}t |¡rÔtd	ƒ‚t d
¡ ||||||||||	d�	 |¡}|| j
d< tjd|dd� |
�r"| S dS )ah      TriMap: Large-scale Dimensionality Reduction Using Triplets [Amid19]_.

    TriMap is a dimensionality reduction method that uses triplet constraints
    to form a low-dimensional embedding of a set of points. The triplet
    constraints are of the form "point i is closer to point j than point k".
    The triplets are sampled from the high-dimensional representation of the
    points and a weighting scheme is used to reflect the importance of each
    triplet.

    TriMap provides a significantly better global view of the data than the
    other dimensionality reduction methods such t-SNE, LargeVis, and UMAP.
    The global structure includes relative distances of the clusters, multiple
    scales in the data, and the existence of possible outliers. We define a
    global score to quantify the quality of an embedding in reflecting the
    global structure of the data.

    Parameters
    ----------
    adata
        Annotated data matrix.
    n_components
        Number of dimensions of the embedding.
    n_inliers
        Number of inlier points for triplet constraints.
    n_outliers
        Number of outlier points for triplet constraints.
    n_random
        Number of random triplet constraints per point.
    metric
        Distance measure: 'angular', 'euclidean', 'hamming', 'manhattan'.
    weight_adj
        Adjusting the weights using a non-linear transformation.
    lr
        Learning rate.
    n_iters
        Number of iterations.
    verbose
        If `True`, print the progress report.
        If `None`, `sc.settings.verbosity` is used.
    copy
        Return a copy instead of writing to `adata`.

    Returns
    -------
    Depending on `copy`, returns or updates `adata` with the following fields.

    **X_trimap** : :class:`~numpy.ndarray`, (:attr:`~anndata.AnnData.obsm`, shape=(n_samples, n_components), dtype `float`)
        TriMap coordinates of data.

    Example
    -------

    >>> import scanpy as sc
    >>> import scanpy.external as sce
    >>> pbmc = sc.datasets.pbmc68k_reduced()
    >>> pbmc = sce.tl.trimap(pbmc, copy=True)
    >>> sce.pl.trimap(pbmc, color=['bulk_labels'], s=10)
    r   )ÚTRIMAPz2
please install trimap: 

	sudo pip install trimapzcomputing TriMapNZX_pcaé   éd   z_trimap currently does not support sparse matrices. Pleaseuse a dense matrix or apply pca first.z5`X_pca` not found. Run `sc.pp.pca` first for speedup.)	Zn_dimsr   r   r   r   Zdistancer   r   r   ÚX_trimapz    finishedz5added
    'X_trimap', TriMap coordinates (adata.obsm))ÚtimeÚdeep)Útrimapr   ÚImportErrorr   ÚloggÚinfor   Ú	verbosityÚ
isinstanceÚboolZobsmÚshapeÚminÚXÚscpÚissparseÚ
ValueErrorÚwarningZfit_transform)r   r   r   r   r   r   r   r   r   r   r   r   Ústartr'   Z	n_dim_pcar,   r    © r2   úS/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/scanpy/external/tl/_trimap.pyr#      sL    I

"
ÿ
÷
ö
ýr#   )
r	   r
   r   r   r   r   r   r   NF)Ú__doc__Útypingr   r   Zanndatar   Zscipy.sparseÚsparser-   Z	_settingsr   Z_compatr   Ú r   r%   ÚintÚfloatr)   r#   r2   r2   r2   r3   Ú<module>   s<             õô