, n_components=2, n_inliers=10, n_outliers=5, n_random=5, metric='euclidean', weight_adj=500.0, lr=1000.0, n_iters=400, verbose=None, copy=False)

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.

adata : AnnDataAnnData

Annotated data matrix.

n_components : intint (default: 2)

Number of dimensions of the embedding.

n_inliers : intint (default: 10)

Number of inlier points for triplet constraints.

n_outliers : intint (default: 5)

Number of outlier points for triplet constraints.

n_random : intint (default: 5)

Number of random triplet constraints per point.

metric : {‘angular’, ‘euclidean’, ‘hamming’, ‘manhattan’}Literal[‘angular’, ‘euclidean’, ‘hamming’, ‘manhattan’] (default: 'euclidean')

Distance measure: ‘angular’, ‘euclidean’, ‘hamming’, ‘manhattan’.

weight_adj : floatfloat (default: 500.0)

Adjusting the weights using a non-linear transformation.

lr : floatfloat (default: 1000.0)

Learning rate.

n_iters : intint (default: 400)

Number of iterations.

verbose : bool | int | NoneUnion[bool, int, None] (default: None)

If True, print the progress report. If None, sc.settings.verbosity is used.

copy : boolbool (default: False)

Return a copy instead of writing to adata.

Return type

AnnData | NoneOptional[AnnData]


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

X_trimapndarray, (obsm, shape=(n_samples, n_components), dtype float)

TriMap coordinates of data.


>>> import scanpy as sc
>>> import scanpy.external as sce
>>> pbmc = sc.datasets.pbmc68k_reduced()
>>> pbmc =, copy=True)
>>>, color=['bulk_labels'], s=10)