rapids_singlecell.tl.tsne#

rapids_singlecell.tl.tsne(adata, n_pcs=None, *, use=None, perplexity=30, early_exaggeration=12, learning_rate=200, method='barnes_hut', metric='euclidean', rng=None, out=False, key_added=None, copy=False, use_rep=None)[source]#

t-SNE [vdMH08] [CRHC18].

Performs t-distributed stochastic neighborhood embedding (tSNE) using cuml library.

Parameters:
adata AnnData

Annotated data matrix.

n_pcs int (default: None)

Use this many PCs. If n_pcs==0 use .X if use_rep is None.

use LayerAcc | MultiAcc | str | None (default: None)

The representation to embed, e.g. A.obsm['pca'], A.X or A.layers['k']. Strings are resolved by anndata.acc.AdAcc.resolve(), e.g. 'obsm.pca'. If None, the representation is chosen automatically: For .n_vars < 50, .X is used, otherwise the PCA embedding, under whichever key the active rapids_singlecell.settings.preset uses. If no PCA embedding is present, it’s computed with default parameters or n_pcs if present.

perplexity int (default: 30)

The perplexity is related to the number of nearest neighbors that is used in other manifold learning algorithms. Larger datasets usually require a larger perplexity. Consider selecting a value between 5 and 50. The choice is not extremely critical since t-SNE is quite insensitive to this parameter.

early_exaggeration int (default: 12)

Controls how tight natural clusters in the original space are in the embedded space and how much space will be between them. For larger values, the space between natural clusters will be larger in the embedded space. Again, the choice of this parameter is not very critical. If the cost function increases during initial optimization, the early exaggeration factor or the learning rate might be too high.

learning_rate int (default: 200)

Note that the R-package “Rtsne” and cuML uses a default of 200. The learning rate can be a critical parameter. It should be between 100 and 1000. If the cost function increases during initial optimization, the early exaggeration factor or the learning rate might be too high. If the cost function gets stuck in a bad local minimum increasing the learning rate helps sometimes.

method str (default: 'barnes_hut')

‘barnes_hut’ and ‘fft’ are fast approximations. ‘exact’ is more accurate but slower.

metric str (default: 'euclidean')

Distance metric to use. Supported distances are [‘l1, ‘cityblock’, ‘manhattan’, ‘euclidean’, ‘l2’, ‘sqeuclidean’, ‘minkowski’, ‘chebyshev’, ‘cosine’, ‘correlation’]

rng int | integer | Sequence[int] | SeedSequence | Generator | BitGenerator | None (default: None)

Random seed or Generator seeding cuML’s t-SNE. Note that cuML’s t-SNE is not fully deterministic, so a fixed seed narrows but does not eliminate run-to-run variation. The superseded random_state argument is still accepted.

out MultiAcc | str | bool (default: False)

Where to write the embedding, e.g. A.obsm['k'] (or 'obsm.k'); the parameters then go to .uns['k']. If True, the embedding is returned instead of written. If False, it is written to .obsm['X_tsne'] and the parameters to .uns['tsne'] ('tsne' for both under the scanpy v2 preset).

Return type:

AnnData | ndarray | None

Returns:

The embedding if out=True, else None. By default sets the following fields:

adata.obsm['X_tsne']ndarray (dtype float)

tSNE coordinates of data.

adata.uns['tsne']['params']dict

tSNE parameters perplexity, early_exaggeration, learning_rate, method, metric, and use_rep.