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 grid for a one point design #965

Open
wants to merge 3 commits 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: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

* The package will now log a backtrace for errors and warnings that occur during tuning. When a tuning process encounters issues, see the new `trace` column in the `collect_notes(.Last.tune.result)` output to find precisely where the error occurred (#873).

* When automatic grids are used, `dials::grid_space_filling()` is now used (instead of `dials::grid_latin_hypercube()`). Overall, the new function produces optimized designs (not depending on random numbers). When using Bayesian models, we will use a Latin Hypercube since we produce 5,000 candidates, which is too slow to do with pre-optimized designs.
* When automatic grids are used, `dials::grid_space_filling()` is now used (instead of `dials::grid_latin_hypercube()`). There is an exception: when `grid = 1`, `dials::grid_random()` is used to avoid warnings. Overall, the new function produces optimized designs (not depending on random numbers). When using Bayesian models, we will use a Latin Hypercube since we produce 5,000 candidates, which is too slow to do with pre-optimized designs. (#962)

# tune 1.2.1

Expand Down
7 changes: 6 additions & 1 deletion R/tune_bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,12 @@ create_initial_set <- function(param, n = NULL, checks) {
if (any(checks == "bayes")) {
check_bayes_initial_size(nrow(param), n)
}
dials::grid_space_filling(param, size = n)
if (n == 1) {
res <- dials::grid_random(param, size = n)
} else {
res <- dials::grid_space_filling(param, size = n)
}
res
}

check_iter <- function(iter, call) {
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,19 @@ test_that("tune_bayes() output for `iter` edge cases (#721)", {
tune_bayes(wf, boots, iter = NULL)
)
})

test_that("1-point grid (#962)", {
skip_if_not_installed("dials", minimum_version = "1.3.0")

expect_silent({
set.seed(1)
grid <- tune:::create_initial_set(
dials::parameters(dials::penalty(), dials::deg_free()),
n = 1,
checks = "none"
)
})
expect_equal(nrow(grid), 1L)
})