Skip to content

Commit

Permalink
Updating superseded map_dfr to map %>% list_rbind. Fixes #115.
Browse files Browse the repository at this point in the history
  • Loading branch information
SokolovAnatoliy committed Aug 15, 2024
1 parent 75f0e15 commit 2d7daa7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion R/plot_race.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ plot_race <- function(x) {


.order <- sort(unique(rs$.order))
purrr::map_dfr(.order, ~ stage_results(.x, rs)) %>%
purrr::map(.order, ~ stage_results(.x, rs)) %>%
purrr::list_rbind() %>%
ggplot2::ggplot(ggplot2::aes(x = stage, y = mean, group = .config, col = .config)) +
ggplot2::geom_line(alpha = .5, show.legend = FALSE) +
ggplot2::xlab("Analysis Stage") +
Expand Down
5 changes: 3 additions & 2 deletions R/sim_anneal_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ random_discrete_neighbor <- function(current, pset, prob, change) {

random_integer_neighbor <- function(current, hist_values, pset, prob, change, retain = 1, tries = 500) {
candidates <-
purrr::map_dfr(
purrr::map(
1:tries,
~ random_integer_neighbor_calc(current, pset, prob, change)
)
) %>%
purrr::list_rbind()

rnd <- tune::encode_set(candidates, pset, as_matrix = TRUE)
sample_by_distance(rnd, hist_values, retain = retain, pset = pset)
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-race-s3.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test_that("racing S3 methods", {
expect_equal(nrow(collect_metrics(anova_race, summarize = FALSE)), 2 * 20)
expect_equal(
nrow(collect_metrics(anova_race, summarize = FALSE, all_configs = TRUE)),
nrow(map_dfr(anova_race$.metrics, ~ .x))
nrow(map(anova_race$.metrics, ~ .x) %>% list_rbind())
)

# ------------------------------------------------------------------------------
Expand All @@ -47,15 +47,15 @@ test_that("racing S3 methods", {
)
expect_equal(
nrow(collect_predictions(anova_race, all_configs = TRUE, summarize = TRUE)),
map_dfr(anova_race$.predictions, ~ .x) %>% distinct(.config, .row) %>% nrow()
map(anova_race$.predictions, ~ .x) %>% list_rbind() %>% distinct(.config, .row) %>% nrow()
)
expect_equal(
nrow(collect_predictions(anova_race, all_configs = FALSE, summarize = FALSE)),
nrow(mtcars) * 1 * 2 # 1 config x 2 repeats x nrow(mtcars)
)
expect_equal(
nrow(collect_predictions(anova_race, all_configs = TRUE, summarize = FALSE)),
nrow(map_dfr(anova_race$.predictions, ~ .x))
nrow(map(anova_race$.predictions, ~ .x) %>% list_rbind())
)

# ------------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-random-integer-neighbors.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ test_that("random integers in range", {
set.seed(123)
parameters <- dials::parameters(list(dials::tree_depth(range = c(2, 3))))
random_integer_neigbors <-
purrr::map_dfr(
purrr::map(
1:500,
~ finetune:::random_integer_neighbor_calc(
tibble::tibble(tree_depth = 3),
parameters, 0.75, FALSE
)
)
) %>%
purrr::list_rbind()


expect_true(all(random_integer_neigbors$tree_depth >= 2))
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-sa-perturb.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ test_that("categorical value switching", {
vals <- tibble::tibble(activation = "relu", weight_func = "biweight")
set.seed(1)
new_vals <-
purrr::map_dfr(
purrr::map(
1:1000,
~ finetune:::random_discrete_neighbor(vals, cat_prm, prob = 1 / 4, change = FALSE)
)
) %>%
purrr::list_rbind()
relu_same <- mean(new_vals$activation == "relu")
biweight_same <- mean(new_vals$weight_func == "biweight")

Expand Down

0 comments on commit 2d7daa7

Please sign in to comment.