From 420ccbbfcd19193461a6cfe02720b649d62eed6f Mon Sep 17 00:00:00 2001 From: topepo Date: Wed, 13 Nov 2024 13:25:18 -0500 Subject: [PATCH 1/2] Changes for #962 --- R/tune_bayes.R | 7 ++++++- tests/testthat/_snaps/bayes.md | 12 ++++++------ tests/testthat/test-bayes.R | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/R/tune_bayes.R b/R/tune_bayes.R index 8a580114..257f493d 100644 --- a/R/tune_bayes.R +++ b/R/tune_bayes.R @@ -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) { diff --git a/tests/testthat/_snaps/bayes.md b/tests/testthat/_snaps/bayes.md index d2e2f99f..4d50a185 100644 --- a/tests/testthat/_snaps/bayes.md +++ b/tests/testthat/_snaps/bayes.md @@ -393,12 +393,12 @@ Message x Fold1: preprocessor 1/1: Error in `step_spline_b()`: - Caused by error in `spline_msg()`: - ! Error in if (df < 0) : missing value where TRUE/FALSE needed + Caused by error in `prep()`: + ! `deg_free` must be a whole number, not a numeric `NA`. x Fold2: preprocessor 1/1: Error in `step_spline_b()`: - Caused by error in `spline_msg()`: - ! Error in if (df < 0) : missing value where TRUE/FALSE needed + Caused by error in `prep()`: + ! `deg_free` must be a whole number, not a numeric `NA`. Condition Warning: All models failed. Run `show_notes(.Last.tune.result)` for more information. @@ -415,10 +415,10 @@ Message x Fold1: preprocessor 1/1: Error in `get_all_predictors()`: - ! The following predictors were not found in `data`: 'z'. + ! The following predictor was not found in `data`: "z". x Fold2: preprocessor 1/1: Error in `get_all_predictors()`: - ! The following predictors were not found in `data`: 'z'. + ! The following predictor was not found in `data`: "z". Condition Warning: All models failed. Run `show_notes(.Last.tune.result)` for more information. diff --git a/tests/testthat/test-bayes.R b/tests/testthat/test-bayes.R index 59bd5ff3..f62169d6 100644 --- a/tests/testthat/test-bayes.R +++ b/tests/testthat/test-bayes.R @@ -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) +}) + + From 43c55c9d8b9cbf4faa26cb504d33068588527cd7 Mon Sep 17 00:00:00 2001 From: topepo Date: Thu, 14 Nov 2024 11:01:09 -0500 Subject: [PATCH 2/2] notes to news --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 2cc4948b..e9d5eb2e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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