Skip to content

Commit

Permalink
more warnings on min_dist and spread;
Browse files Browse the repository at this point in the history
update on a test that was failing on solaris
  • Loading branch information
tkonopka committed May 10, 2019
1 parent 77bb42e commit 48fc94e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: umap
Title: Uniform Manifold Approximation and Projection
Version: 0.2.1.0
Version: 0.2.2.0
Authors@R:
person("Tomasz", "Konopka", , "tokonopka@gmail.com", role = c("aut", "cre"))
Author: Tomasz Konopka [aut, cre]
Expand Down
8 changes: 7 additions & 1 deletion R/umap_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ umap.check.config = function(config=umap.defaults, ...) {
"parameter 'spread' will be ignored.\n", abcontrol)
}
}

if (config$min_dist >= config$spread) {
umap.error("setting 'min_dist' must be smaller than 'spread'")
}
if (config$min_dist <=0) {
umap.error("setting 'min_dist' must be > 0")
}


## force some data types
for (x in c("n_epochs", "n_neighbors", "n_components",
"random_state", "negative_sample_rate", "transform_state")) {
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ test_that("config checks detect missing items", {
## ############################################################################
## Tests for settings a/b vs min_dist/spread


test_that("check gives warningg if a has a value but b is NA", {
conf = umap.defaults
conf$a = 1
Expand Down Expand Up @@ -215,6 +216,18 @@ test_that("check gives warning if attempting to over-specify spread", {
expect_warning(umap.check.config(conf), "non-default")
})

test_that("check gives error when min_dist is too large", {
conf = umap.defaults
conf$min_dist = conf$spread = 1
expect_error(umap.check.config(conf), "smaller")
})

test_that("check gives error when min_dist is too small", {
conf = umap.defaults
conf$min_dist = 0
expect_error(umap.check.config(conf), "min_dist")
})




Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test_naive.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ test_that("predicted layout is reasonable", {
distances.to.medoids = distances[1:nrow(result), rownames(cluster.centers)]
nearest.medoid = apply(distances.to.medoids, 1, which.min)
expected = setNames(rep(1:3, each=nrow(result)/3), rownames(result))
expect_equal(nearest.medoid, expected)
# in principle, nearest.medoid and expected should be exactly equal
# but due to randomness and some OS- or architecture-dependent minutae,
# sometimes one component can be off. So allow some discrepancies in the test.
expect_lte(sum(abs(nearest.medoid-expected)), 1)
})


Expand Down

0 comments on commit 48fc94e

Please sign in to comment.