Skip to content

Commit

Permalink
fix: transformation functions in random search
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc committed Mar 13, 2024
1 parent 864f957 commit 25b7b1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 11 additions & 5 deletions R/OptimizerRandomSearchV2.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,25 @@ OptimizerRandomSearchV2 = R6Class("OptimizerRandomSearchV2",

private = list(
.optimize = function(inst) {
search_space = inst$search_space
rush = inst$rush

while(!inst$is_terminated) {
# ask
sampler = SamplerUnif$new(inst$search_space)
sampler = SamplerUnif$new(search_space)
xdt = sampler$sample(1)$data
xs = transform_xdt_to_xss(xdt, inst$search_space)[[1]]
key = inst$rush$push_running_task(list(xs))
xss = transpose_list(xdt)
xs = xss[[1]][inst$archive$cols_x]
xs_trafoed = trafo_xs(xs, search_space)
keys = inst$rush$push_running_task(list(xs), extra = list(list(timestamp_xs = Sys.time())))

# eval
ys = inst$objective$eval(xs)
ys = inst$objective$eval(xs_trafoed)

# tell
inst$rush$push_results(key, list(ys))
rush$push_results(keys, yss = list(ys), extra = list(list(
x_domain = list(xs_trafoed),
timestamp_ys = Sys.time())))
}
}
)
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_OptimInstanceRushSingleCrit.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ test_that("starting workers and evaluating points works in a decentralized netwo
test_that("random search v2 works", {
skip_on_cran()
flush_redis()
options(bbotk_local = TRUE)

rush_plan(n_workers = 2)

instance = OptimInstanceRushSingleCrit$new(
objective = OBJ_2D,
search_space = PS_2D,
terminator = trm("evals", n_evals = 1L),
terminator = trm("evals", n_evals = 20L),
)

optimizer = opt("random_search_v2")
instance$rush = RushWorker$new(instance$rush$network_id, host = "local")
get_private(optimizer)$.optimize_remote(instance)
optimizer$optimize(instance)
})


Expand Down

0 comments on commit 25b7b1b

Please sign in to comment.