Skip to content

Commit

Permalink
use a random design for size = 1 (#363)
Browse files Browse the repository at this point in the history
* use a random design for size = 1

* no need for namespacing

* add PR number

---------

Co-authored-by: Hannah Frick <[email protected]>
  • Loading branch information
topepo and hfrick authored Dec 9, 2024
1 parent ed4ecef commit caa3acc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 30 deletions.
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 (#363).

# 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 <- 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)
})

0 comments on commit caa3acc

Please sign in to comment.