Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use a random design for size = 1 #363

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

* All messages, warnings and errors has been translated to use {cli} package (#311).

* For space-filling designs for $p$ parameters, there is a higher likelihood of finding a space-filling design for `1 < size <= p`. Also, single-point designs now default to a random grid.

# dials 1.3.0

## Improvements
Expand Down
10 changes: 4 additions & 6 deletions R/space_filling.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#' `"audze_eglais"`, `"max_min_l1"`, `"max_min_l2"`, `"uniform"`,
#' `"max_entropy"`, or `"latin_hypercube"`. A value of `"any"` will choose the
#' first design available (in the order listed above, excluding
#' `"latin_hypercube"`). If the design is extremely small, the function may
#' change the type to `"latin_hypercube"` (with a warning).
#' `"latin_hypercube"`). For a single-point design, a random grid is created.
#' @param variogram_range A numeric value greater than zero. Larger values
#' reduce the likelihood of empty regions in the parameter space. Only used
#' for `type = "max_entropy"`.
Expand Down Expand Up @@ -193,10 +192,9 @@ make_sfd <- function(...,
params <- map(param_quos, eval_tidy)
p <- length(params)

if (size < p | size == 1) {
cli::cli_warn("Due to the small size of the grid, a Latin hypercube \\
design will be used.")
type <- "latin_hypercube"
if (size == 1) {
res <- dials::grid_random(params, size = size)
return(res)
}

if (type %in% c("any", "audze_eglais", "max_min_l1", "max_min_l2", "uniform")) {
Expand Down
3 changes: 1 addition & 2 deletions man/grid_space_filling.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions tests/testthat/_snaps/space_filling.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,3 @@
`levels` is not an argument to `grid_space_filling()`.
i Did you mean `size`?

# very small designs

Due to the small size of the grid, a Latin hypercube design will be used.

---

Due to the small size of the grid, a Latin hypercube design will be used.

20 changes: 6 additions & 14 deletions tests/testthat/test-space_filling.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,11 @@ test_that("S3 methods for space-filling", {

})

test_that("very small designs", {

expect_snapshot_warning({
set.seed(1)
small_1 <- grid_space_filling(parameters(neighbors()), size = 1)
})
expect_equal(dim(small_1), c(1L, 1L))

expect_snapshot_warning({
set.seed(1)
small_2 <- grid_space_filling(parameters(neighbors(), mixture(), penalty()),
size = 2)
test_that("1-point grid", {
expect_silent({
set.seed(1)
grid <- grid_space_filling(parameters(neighbors()), size = 1)
})
expect_equal(dim(small_2), c(2L, 3L))

expect_equal(nrow(grid), 1L)
})