Skip to content

Commit

Permalink
#118 and #129 fix uwot_transform's fgraph dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmelville committed Sep 7, 2024
1 parent 70caefe commit fd5f337
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
9 changes: 7 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<https://github.com/jlmelville/uwot/issues/118>).

# uwot 0.2.2

Expand Down
5 changes: 5 additions & 0 deletions R/transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
30 changes: 29 additions & 1 deletion tests/testthat/test_transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})

0 comments on commit fd5f337

Please sign in to comment.