Skip to content

Commit

Permalink
finalize parameters with unknown ranges in tune_sim_anneal()
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Jan 19, 2024
1 parent 4d0fda5 commit dfcd6d7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# finetune (development version)

* Fixed bug where `tune_sim_anneal()` would fail when supplied parameters needing finalization. The function will now finalize needed parameter ranges internally (#39).

* `autoplot()` methods for racing objects will now use integers in x-axis breaks (#75).

* Enabling the `verbose_elim` control option for `tune_race_anova()` will now additionally introduce a message confirming that the function is evaluating against the burn-in resamples.
Expand Down
12 changes: 6 additions & 6 deletions R/tune_sim_anneal.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,12 @@ tune_sim_anneal_workflow <-
}

# In case mtry or other parameters with missing ranges need finalization
# param_info <- tune::check_parameters(
# workflow = object,
# pset = param_info,
# data = resamples$splits[[1]]$data,
# grid_names = param_info$id
# )
param_info <- tune::check_parameters(
wflow = object,
pset = param_info,
data = resamples$splits[[1]]$data,
grid_names = character(0)
)

tune::check_workflow(object, check_dials = !is.null(param_info), pset = param_info)

Expand Down
43 changes: 32 additions & 11 deletions tests/testthat/_snaps/sa-overall.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,37 @@
set.seed(40)
rf_res_finetune <- wf_rf %>% tune_sim_anneal(resamples = bt, initial = rf_res)
Message
i Creating pre-processing data to finalize unknown parameter: mtry
Optimizing roc_auc
Initial best: 0.86248
1 ( ) accept suboptimal roc_auc=0.86132 (+/-0.007045)
2 ( ) accept suboptimal roc_auc=0.85987 (+/-0.007598)
3 + better suboptimal roc_auc=0.86155 (+/-0.007228)
4 + better suboptimal roc_auc=0.86193 (+/-0.007212)
5 ( ) accept suboptimal roc_auc=0.86108 (+/-0.00727)
6 ( ) accept suboptimal roc_auc=0.85992 (+/-0.007641)
7 + better suboptimal roc_auc=0.86045 (+/-0.007405)
8 x restart from best roc_auc=0.85863 (+/-0.007596)
9 ( ) accept suboptimal roc_auc=0.8623 (+/-0.007265)
10 <3 new best roc_auc=0.86273 (+/-0.007569)
Initial best: 0.84856
1 ( ) accept suboptimal roc_auc=0.84375 (+/-0.007727)
2 <3 new best roc_auc=0.84943 (+/-0.007036)
3 ( ) accept suboptimal roc_auc=0.84371 (+/-0.007903)
4 + better suboptimal roc_auc=0.84825 (+/-0.008036)
5 ( ) accept suboptimal roc_auc=0.84479 (+/-0.00814)
6 + better suboptimal roc_auc=0.84816 (+/-0.007283)
7 ( ) accept suboptimal roc_auc=0.84381 (+/-0.007999)
8 <3 new best roc_auc=0.85014 (+/-0.007172)
9 ( ) accept suboptimal roc_auc=0.84344 (+/-0.007818)
10 + better suboptimal roc_auc=0.84802 (+/-0.007281)

---

Code
set.seed(40)
rf_res_finetune <- wf_rf %>% tune_sim_anneal(resamples = bt)
Message
i Creating pre-processing data to finalize unknown parameter: mtry
Optimizing roc_auc
Initial best: 0.84829
1 ( ) accept suboptimal roc_auc=0.84326 (+/-0.007765)
2 <3 new best roc_auc=0.84843 (+/-0.007903)
3 ( ) accept suboptimal roc_auc=0.84438 (+/-0.007904)
4 <3 new best roc_auc=0.84881 (+/-0.007951)
5 ( ) accept suboptimal roc_auc=0.84404 (+/-0.007787)
6 <3 new best roc_auc=0.84912 (+/-0.007272)
7 ( ) accept suboptimal roc_auc=0.84333 (+/-0.007685)
8 + better suboptimal roc_auc=0.84867 (+/-0.007152)
9 - discard suboptimal roc_auc=0.84525 (+/-0.007793)
10 ( ) accept suboptimal roc_auc=0.84383 (+/-0.00773)

9 changes: 8 additions & 1 deletion tests/testthat/test-sa-overall.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test_that("unfinalized parameters", {
rec_example <- recipe(Class ~ ., data = two_class_dat)

# RF
model_rf <- rand_forest(min_n = tune()) %>%
model_rf <- rand_forest(mtry = tune()) %>%
set_mode("classification") %>%
set_engine("ranger")

Expand All @@ -118,6 +118,13 @@ test_that("unfinalized parameters", {
rf_res_finetune <- wf_rf %>%
tune_sim_anneal(resamples = bt, initial = rf_res)
})

# don't supply an initial grid (#39)
expect_snapshot({
set.seed(40)
rf_res_finetune <- wf_rf %>%
tune_sim_anneal(resamples = bt)
})
})

test_that("set event-level", {
Expand Down

0 comments on commit dfcd6d7

Please sign in to comment.