Skip to contents

Perform t-distributed Stochastic Neighbor Embedding on the matrix, adding t-SNE coordinates to metadata and optionally storing the full Rtsne object.

Usage

compute_tsne(x, name = NULL, dims = 2, store = TRUE, perplexity = 30, ...)

Arguments

x

A tidymatrix object

name

Name for this analysis. Default is "row_tsne" or "column_tsne" depending on active component.

dims

Number of dimensions for t-SNE embedding. Default is 2.

store

If TRUE, stores the full Rtsne object for later retrieval with get_analysis(). Default is TRUE.

perplexity

Perplexity parameter (default 30). Should be less than the number of samples. Typical values are between 5 and 50.

...

Additional arguments passed to Rtsne::Rtsne(), such as theta, max_iter, verbose, etc.

Value

A tidymatrix object with t-SNE coordinates added to metadata

Details

This function wraps Rtsne::Rtsne() and passes all additional parameters directly to it. Note that t-SNE is stochastic, so use set.seed() before calling for reproducible results.

Examples

if (requireNamespace("Rtsne", quietly = TRUE)) {
mat <- matrix(rnorm(500), nrow = 50, ncol = 10)
row_data <- data.frame(id = 1:50)
tm <- tidymatrix(mat, row_data)

# t-SNE on rows
set.seed(42)  # For reproducibility
tm <- tm |>
  activate(rows) |>
  compute_tsne(dims = 2, perplexity = 10)

# Now row_data has row_tsne_1, row_tsne_2 columns

# Get full Rtsne object
tsne_obj <- get_analysis(tm, "row_tsne")
}