Asynchronous Optimization via Random Search
Source:R/OptimizerAsyncRandomSearch.R
mlr_optimizers_async_random_search.RdOptimizerAsyncRandomSearch class that implements a simple Random Search.
Source
Bergstra J, Bengio Y (2012). “Random Search for Hyper-Parameter Optimization.” Journal of Machine Learning Research, 13(10), 281–305. https://jmlr.csail.mit.edu/papers/v13/bergstra12a.html.
Dictionary
This Optimizer can be instantiated via the dictionary
mlr_optimizers or with the associated sugar function opt():
Super classes
bbotk::Optimizer -> bbotk::OptimizerAsync -> OptimizerAsyncRandomSearch
Examples
# example only runs if a Redis server is available
if (mlr3misc::require_namespaces(c("rush", "redux", "mirai"), quietly = TRUE) &&
redux::redis_available()) {
# define the objective function
fun = function(xs) {
list(y = - (xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10)
}
# set domain
domain = ps(
x1 = p_dbl(-10, 10),
x2 = p_dbl(-5, 5)
)
# set codomain
codomain = ps(
y = p_dbl(tags = "maximize")
)
# create objective
objective = ObjectiveRFun$new(
fun = fun,
domain = domain,
codomain = codomain,
properties = "deterministic"
)
# start workers
rush::rush_plan(worker_type = "remote")
mirai::daemons(1)
# initialize instance
instance = oi_async(
objective = objective,
terminator = trm("evals", n_evals = 20)
)
# load optimizer
optimizer = opt("async_random_search")
# trigger optimization
optimizer$optimize(instance)
# all evaluated configurations
instance$archive
# best performing configuration
instance$archive$best()
# covert to data.table
as.data.table(instance$archive)
}
#> state x1 x2 y timestamp_xs pid
#> <char> <num> <num> <num> <POSc> <int>
#> 1: finished -8.6401429 -0.22082921 -110.93643045 2025-10-24 13:28:58 9665
#> 2: finished 2.6451261 -0.47433125 3.20480965 2025-10-24 13:28:58 9665
#> 3: finished 6.6553863 -4.98604438 -15.61699363 2025-10-24 13:28:58 9665
#> 4: finished 5.0158969 -1.16851633 -2.44996658 2025-10-24 13:28:58 9665
#> 5: finished -4.2982254 4.20337792 -81.55629675 2025-10-24 13:28:58 9665
#> 6: finished -5.3318011 3.07859096 -80.70457510 2025-10-24 13:28:58 9665
#> 7: finished -1.2947935 4.44486001 -56.28160502 2025-10-24 13:28:58 9665
#> 8: finished 4.4867714 -4.92985296 0.09163568 2025-10-24 13:28:58 9665
#> 9: finished -4.1477403 2.28072295 -55.68074611 2025-10-24 13:28:58 9665
#> 10: finished -5.6137151 4.91263287 -110.57841706 2025-10-24 13:28:58 9665
#> 11: finished 0.5407374 -0.53103894 1.77478382 2025-10-24 13:28:58 9665
#> 12: finished -5.7833451 -3.39854730 -50.73930118 2025-10-24 13:28:58 9665
#> 13: finished -8.4307422 4.47890861 -154.73445725 2025-10-24 13:28:58 9665
#> 14: finished 7.1022916 -0.75569363 -21.07029075 2025-10-24 13:28:58 9665
#> 15: finished 5.9002467 -2.48642191 -5.47568658 2025-10-24 13:28:58 9665
#> 16: finished 4.0407162 -0.43184476 -0.75994399 2025-10-24 13:28:58 9665
#> 17: finished -7.4830553 -2.92798538 -79.93352300 2025-10-24 13:28:58 9665
#> 18: finished -3.9849409 -1.06526646 -29.56271169 2025-10-24 13:28:58 9665
#> 19: finished -2.3908942 0.02101378 -18.40647620 2025-10-24 13:28:58 9665
#> 20: finished 0.8103813 4.51596998 -47.90499748 2025-10-24 13:28:58 9665
#> state x1 x2 y timestamp_xs pid
#> worker_id timestamp_ys keys
#> <char> <POSc> <char>
#> 1: papery_hog 2025-10-24 13:28:58 72809b88-0f31-4db6-9801-bc977923def3
#> 2: papery_hog 2025-10-24 13:28:58 5536a2b6-fcc9-4bff-82d3-e8214a6b0f7c
#> 3: papery_hog 2025-10-24 13:28:58 326de43c-6955-4960-8c01-93b86c927ef4
#> 4: papery_hog 2025-10-24 13:28:58 a0566a5c-0f05-476d-bea4-e5e0aeac2f92
#> 5: papery_hog 2025-10-24 13:28:58 45f8cf2c-ff87-440e-b29a-9da311c46a33
#> 6: papery_hog 2025-10-24 13:28:58 bcf994b5-b5e6-43ca-827d-1822cf02c960
#> 7: papery_hog 2025-10-24 13:28:58 49422a04-4cdf-4e7a-ab8d-3a107341f0f2
#> 8: papery_hog 2025-10-24 13:28:58 63a9b9b5-cb89-452a-867f-2e708156bfa7
#> 9: papery_hog 2025-10-24 13:28:58 208556a4-394c-45b3-ab8f-ae1971a042e0
#> 10: papery_hog 2025-10-24 13:28:58 5f93070a-5067-4b88-9597-528082e58c90
#> 11: papery_hog 2025-10-24 13:28:58 3c4547cf-74d4-4174-93f2-0ed759d5a9f9
#> 12: papery_hog 2025-10-24 13:28:58 be548197-e1b0-4404-975f-85f4a4dea864
#> 13: papery_hog 2025-10-24 13:28:58 b5286db6-bca0-4824-9b96-f8389140e0f9
#> 14: papery_hog 2025-10-24 13:28:58 4c2a24c7-ec09-4d01-a5c3-064bd8545ecc
#> 15: papery_hog 2025-10-24 13:28:58 7df6c3ae-64a0-4d14-a24a-9d03fc2cbada
#> 16: papery_hog 2025-10-24 13:28:58 00500b8f-4458-42d7-b9e3-40f04dfa0e1a
#> 17: papery_hog 2025-10-24 13:28:58 3ce1306d-2850-4ccc-a414-466430e2df9d
#> 18: papery_hog 2025-10-24 13:28:58 1e2357d3-7ad7-43e5-9dc8-87ad6fb13cc9
#> 19: papery_hog 2025-10-24 13:28:58 748eab46-b039-405c-8d69-54c4bf36b981
#> 20: papery_hog 2025-10-24 13:28:58 0ed1b74b-56b2-4182-ba4c-fd49fac161ae
#> worker_id timestamp_ys keys
#> x_domain_x1 x_domain_x2
#> <num> <num>
#> 1: -8.6401429 -0.22082921
#> 2: 2.6451261 -0.47433125
#> 3: 6.6553863 -4.98604438
#> 4: 5.0158969 -1.16851633
#> 5: -4.2982254 4.20337792
#> 6: -5.3318011 3.07859096
#> 7: -1.2947935 4.44486001
#> 8: 4.4867714 -4.92985296
#> 9: -4.1477403 2.28072295
#> 10: -5.6137151 4.91263287
#> 11: 0.5407374 -0.53103894
#> 12: -5.7833451 -3.39854730
#> 13: -8.4307422 4.47890861
#> 14: 7.1022916 -0.75569363
#> 15: 5.9002467 -2.48642191
#> 16: 4.0407162 -0.43184476
#> 17: -7.4830553 -2.92798538
#> 18: -3.9849409 -1.06526646
#> 19: -2.3908942 0.02101378
#> 20: 0.8103813 4.51596998
#> x_domain_x1 x_domain_x2