Skip to contents

This function normalizes a list of distance matrices by their top singular value so that after normalization, each distance matrix has a top singular value of 1. This ensures that the distance matrices are on similar scales, making the CoMDS optimization problem more stable and easier to optimize.

Usage

normalize_distances(D_list)

Arguments

D_list

List of distance matrices.

Value

A list of normalized distance matrices (each of class dist).

Examples

data(iris)
# remove duplicates so that tSNE can run
X <- dplyr::distinct(iris[, 1:4])

# fit various dimension reduction methods
pca_scores <- prcomp(X, center = TRUE, scale = TRUE)$x
tsne_scores <- Rtsne::Rtsne(X, dims = 2, perplexity = 30, verbose = FALSE)$Y
umap_scores <- umap::umap(X, n_components = 2, verbose = FALSE)$layout
dr_list <- list(
  pca = pca_scores,
  tsne = tsne_scores,
  umap = umap_scores
)

# convert embeddings to distance matrices
dist_list <- purrr::map(dr_list, ~ dist(.x, method = "euclidean"))
# normalize distance matrices
dist_list_norm <- normalize_distances(dist_list)