From 78c27a63ccb2dc9739ea134f5fc3a5fb63e232dc Mon Sep 17 00:00:00 2001 From: William Ryan Date: Fri, 2 Feb 2024 00:20:42 -0500 Subject: [PATCH] Suppress NAN warnings when computing MDS of each cluster In general, inspection and convention supports the sqrt trasnformation of cosine dissimilarity matrix for MDS, to reduce the relative impact of very high dissimilarity scores and increases the relative impact of lower scores. Planning on a feature request to make this configurable. --- R/generate_themes.R | 2 +- R/utils.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/generate_themes.R b/R/generate_themes.R index d441279..bc91f31 100644 --- a/R/generate_themes.R +++ b/R/generate_themes.R @@ -92,7 +92,7 @@ generate_themes <- mds = avg_cluster_embeddings %>% tibble::column_to_rownames("Cluster") %>% as.matrix() %>% - cosine_dissimilarity(root = T) %>% + cosine_dissimilarity(root = TRUE) %>% smacof::mds(type = "ordinal") #Generate distinct categorical colors for plotting diff --git a/R/utils.R b/R/utils.R index 4acca7f..951dc72 100644 --- a/R/utils.R +++ b/R/utils.R @@ -16,7 +16,7 @@ cosine_dissimilarity <- function(mat, root = FALSE) { sim = sim %*% t(sim) if(root == T) { - D_sim = stats::as.dist(sqrt(1 - sim)) + D_sim = stats::as.dist(suppressWarnings(sqrt(1 - sim))) } else { D_sim = stats::as.dist(1 - sim) }