Contents, 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)[source]#

TriMap: Large-scale Dimensionality Reduction Using Triplets [Amid and Warmuth, 2019].

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 AnnData

Annotated data matrix.

n_components int (default: 2)

Number of dimensions of the embedding.

n_inliers int (default: 10)

Number of inlier points for triplet constraints.

n_outliers int (default: 5)

Number of outlier points for triplet constraints.

n_random int (default: 5)

Number of random triplet constraints per point.

metric Literal['angular', 'euclidean', 'hamming', 'manhattan'] (default: 'euclidean')

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

weight_adj float (default: 500.0)

Adjusting the weights using a non-linear transformation.

lr float (default: 1000.0)

Learning rate.

n_iters int (default: 400)

Number of iterations.

verbose bool | int | None (default: None)

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

copy bool (default: False)

Return a copy instead of writing to adata.

Return type:

AnnData | None


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)