From fd5f337bbd24586c05dcf6370004dc61364c0192 Mon Sep 17 00:00:00 2001 From: James Melville Date: Fri, 6 Sep 2024 23:48:43 -0700 Subject: [PATCH] #118 and #129 fix uwot_transform's fgraph dimensions --- NEWS.md | 9 +++++++-- R/transform.R | 5 +++++ tests/testthat/test_transform.R | 30 +++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3a026679..460d0b8a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,8 +2,13 @@ ## Bug fixes and minor improvements -* Setting `num_threads` directly in `umap2` did not result in the sgd threads -being updated to that value when `batch = TRUE`, which it should have been. +* Setting `num_threads` directly in `umap2` did not result in the number of SGD +threads being updated to that value when `batch = TRUE`, which it should have +been. +* Despite assertions to the contrary in version 0.2.1, `umap_transform` +continued to return the fuzzy graph in transposed form. Thank you +[PedroMilanezAlmeida](https://github.com/PedroMilanezAlmeida) for +reopening the issue (). # uwot 0.2.2 diff --git a/R/transform.R b/R/transform.R index 87544228..161bd286 100644 --- a/R/transform.R +++ b/R/transform.R @@ -832,6 +832,11 @@ umap_transform <- function(X = NULL, model = NULL, res <- list(embedding = embedding) for (name in ret_extra) { if (name == "fgraph") { + if (batch) { + # #129: we transposed graph in the batch=TRUE case (#118) but need to + # transpose back for export + graph <- Matrix::t(graph) + } res$fgraph <- graph } if (name == "sigma") { diff --git a/tests/testthat/test_transform.R b/tests/testthat/test_transform.R index 14af1443..2fc61aa2 100644 --- a/tests/testthat/test_transform.R +++ b/tests/testthat/test_transform.R @@ -406,5 +406,33 @@ test_that("graph dim is consistent when n_epochs = 0", { dim(iris_transform_10$fgraph), dim(iris_transform_0$fgraph) ) - expect_equal(dim(iris_transform_10$fgraph), c(100, 50)) + expect_equal(dim(iris_transform_10$fgraph), c(50, 100)) + + + #118/129 and also without batch + iris_model_no_batch <- + umap( + iris_species_12, + ret_model = TRUE, + n_epochs = 0, + batch = FALSE + ) + + iris_transform_10_no_batch <- umap_transform(iris_species_3, + iris_model_no_batch, + n_epochs = 10, + ret_extra = "fgraph" + ) + + iris_transform_0_no_batch <- umap_transform(iris_species_3, + iris_model_no_batch, + n_epochs = 0, + ret_extra = "fgraph" + ) + + expect_equal( + dim(iris_transform_10_no_batch$fgraph), + dim(iris_transform_0_no_batch$fgraph) + ) + expect_equal(dim(iris_transform_10_no_batch$fgraph), c(50, 100)) })