Skip to content

Commit

Permalink
Changes for #11
Browse files Browse the repository at this point in the history
  • Loading branch information
topepo committed Sep 13, 2020
1 parent 6161326 commit e1167b6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Fixed two bugs in the acquisition function calculations.

* Better control the random number streams in parallel for `tune_grid()` and `fit_resamples()` (#11)

# tune 0.1.1

## Breaking Changes
Expand Down
4 changes: 4 additions & 0 deletions R/grid_code_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tune_nothing_with_formula <- function(resamples, grid, workflow, metrics, contro
# ------------------------------------------------------------------------------

iter_rec_and_mod <- function(rs_iter, resamples, grid, workflow, metrics, control) {
set.seed(resamples$.seed[[rs_iter]])
load_pkgs(workflow)
load_namespace(control$pkgs)

Expand Down Expand Up @@ -189,6 +190,7 @@ tune_rec_and_mod <- function(resamples, grid, workflow, metrics, control) {
# ------------------------------------------------------------------------------

iter_rec <- function(rs_iter, resamples, grid, workflow, metrics, control) {
set.seed(resamples$.seed[[rs_iter]])
load_pkgs(workflow)
load_namespace(control$pkgs)

Expand Down Expand Up @@ -330,6 +332,7 @@ tune_mod_with_recipe <- function(resamples, grid, workflow, metrics, control) {
}

iter_mod_with_recipe <- function(rs_iter, resamples, grid, workflow, metrics, control) {
set.seed(resamples$.seed[[rs_iter]])
load_pkgs(workflow)
load_namespace(control$pkgs)

Expand Down Expand Up @@ -470,6 +473,7 @@ tune_mod_with_formula <- function(resamples, grid, workflow, metrics, control) {
}

iter_mod_with_formula <- function(rs_iter, resamples, grid, workflow, metrics, control) {
set.seed(resamples$.seed[[rs_iter]])
load_pkgs(workflow)
load_namespace(control$pkgs)

Expand Down
6 changes: 5 additions & 1 deletion R/resample.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ resample_workflow <- function(workflow, resamples, metrics, control) {

has_formula <- has_preprocessor_formula(workflow)

resamples <- dplyr::mutate(resamples, .seed = sample.int(10^5, nrow(resamples)))

# Save rset attributes, then fall back to a bare tibble
rset_info <- pull_rset_attributes(resamples)
resamples <- new_bare_tibble(resamples)
Expand All @@ -161,7 +163,7 @@ resample_workflow <- function(workflow, resamples, metrics, control) {
workflow_output <- set_workflow(workflow, control)

new_resample_results(
x = resamples,
x = resamples %>% dplyr::select(-.seed),
parameters = parameters(workflow),
metrics = metrics,
outcomes = outcomes,
Expand Down Expand Up @@ -205,6 +207,7 @@ resample_with_recipe <- function(resamples, workflow, metrics, control) {
}

iter_resample_with_recipe <- function(rs_iter, resamples, workflow, metrics, control) {
set.seed(resamples$.seed[[rs_iter]])
load_pkgs(workflow)
load_namespace(control$pkgs)

Expand Down Expand Up @@ -337,6 +340,7 @@ resample_with_formula <- function(resamples, workflow, metrics, control) {
}

iter_resample_with_formula <- function(rs_iter, resamples, workflow, metrics, control) {
set.seed(resamples$.seed[[rs_iter]])
load_pkgs(workflow)
load_namespace(control$pkgs)

Expand Down
5 changes: 4 additions & 1 deletion R/tune_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ tune_grid_workflow <- function(object,
data = resamples$splits[[1]]$data,
grid_names = names(grid))
check_workflow(object, pset = pset)

resamples <- dplyr::mutate(resamples, .seed = sample.int(10^5, nrow(resamples)))

grid <- check_grid(grid, object, pset)

# Save rset attributes, then fall back to a bare tibble
Expand All @@ -340,7 +343,7 @@ tune_grid_workflow <- function(object,
workflow_output <- set_workflow(object, control)

new_tune_results(
x = resamples,
x = resamples %>% dplyr::select(-.seed),
parameters = pset,
metrics = metrics,
outcomes = outcomes,
Expand Down

0 comments on commit e1167b6

Please sign in to comment.