U
    md>                     @   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|rt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<             