Skip to contents

OptimizerAsyncRandomSearch 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():

mlr_optimizers$get("async_random_search")
opt("async_random_search")

Super classes

bbotk::Optimizer -> bbotk::OptimizerAsync -> OptimizerAsyncRandomSearch

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.


Method clone()

The objects of this class are cloneable with this method.

Usage

OptimizerAsyncRandomSearch$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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:34:25  9760
#>  2: finished  2.6451261 -0.47433125    3.20480965 2025-10-24 13:34:25  9760
#>  3: finished  6.6553863 -4.98604438  -15.61699363 2025-10-24 13:34:25  9760
#>  4: finished  5.0158969 -1.16851633   -2.44996658 2025-10-24 13:34:25  9760
#>  5: finished -4.2982254  4.20337792  -81.55629675 2025-10-24 13:34:25  9760
#>  6: finished -5.3318011  3.07859096  -80.70457510 2025-10-24 13:34:25  9760
#>  7: finished -1.2947935  4.44486001  -56.28160502 2025-10-24 13:34:25  9760
#>  8: finished  4.4867714 -4.92985296    0.09163568 2025-10-24 13:34:25  9760
#>  9: finished -4.1477403  2.28072295  -55.68074611 2025-10-24 13:34:25  9760
#> 10: finished -5.6137151  4.91263287 -110.57841706 2025-10-24 13:34:25  9760
#> 11: finished  0.5407374 -0.53103894    1.77478382 2025-10-24 13:34:25  9760
#> 12: finished -5.7833451 -3.39854730  -50.73930118 2025-10-24 13:34:25  9760
#> 13: finished -8.4307422  4.47890861 -154.73445725 2025-10-24 13:34:25  9760
#> 14: finished  7.1022916 -0.75569363  -21.07029075 2025-10-24 13:34:25  9760
#> 15: finished  5.9002467 -2.48642191   -5.47568658 2025-10-24 13:34:25  9760
#> 16: finished  4.0407162 -0.43184476   -0.75994399 2025-10-24 13:34:26  9760
#> 17: finished -7.4830553 -2.92798538  -79.93352300 2025-10-24 13:34:26  9760
#> 18: finished -3.9849409 -1.06526646  -29.56271169 2025-10-24 13:34:26  9760
#> 19: finished -2.3908942  0.02101378  -18.40647620 2025-10-24 13:34:26  9760
#> 20: finished  0.8103813  4.51596998  -47.90499748 2025-10-24 13:34:26  9760
#>        state         x1          x2             y        timestamp_xs   pid
#>      worker_id        timestamp_ys                                 keys
#>         <char>              <POSc>                               <char>
#>  1: papery_hog 2025-10-24 13:34:25 9b734495-fd3e-4fc6-8138-577c097d0e5d
#>  2: papery_hog 2025-10-24 13:34:25 d316281e-644d-4718-9e6a-c87407f138b6
#>  3: papery_hog 2025-10-24 13:34:25 e71ab7a0-e0bb-4bfb-8d1b-7c9d9eb15774
#>  4: papery_hog 2025-10-24 13:34:25 493feb58-84af-4a86-a5d6-b54159ce1c61
#>  5: papery_hog 2025-10-24 13:34:25 f804026b-7854-4254-9739-59748e154651
#>  6: papery_hog 2025-10-24 13:34:25 ad3da273-432d-4f52-949a-82808f8d3c56
#>  7: papery_hog 2025-10-24 13:34:25 c77d5d91-520d-4540-8509-6166011a165d
#>  8: papery_hog 2025-10-24 13:34:25 debf4a0b-8abb-49d3-b538-1aa0d478451e
#>  9: papery_hog 2025-10-24 13:34:25 4b8e75e8-3a77-4414-847e-1df935bfff7f
#> 10: papery_hog 2025-10-24 13:34:25 01bde442-c450-4af1-9314-90b57cb108c7
#> 11: papery_hog 2025-10-24 13:34:25 a8c96e17-3a66-4d58-8da1-71ad522e23fb
#> 12: papery_hog 2025-10-24 13:34:25 c98b0774-eedd-4ced-bd7b-e6570fdbb0f6
#> 13: papery_hog 2025-10-24 13:34:25 a6ce2308-2e62-48c3-b423-b3811ce711b7
#> 14: papery_hog 2025-10-24 13:34:25 ae9d9d2c-1d34-4002-8252-5549084624fa
#> 15: papery_hog 2025-10-24 13:34:25 e998dffd-98a7-48fd-952b-d5ecc5902d8d
#> 16: papery_hog 2025-10-24 13:34:26 f1a8a838-fa79-4e02-8a4c-47837dc1ad3c
#> 17: papery_hog 2025-10-24 13:34:26 42564844-b5a9-42db-a418-be21d7343917
#> 18: papery_hog 2025-10-24 13:34:26 f1308bcc-716a-4240-a50c-22de6b6243cb
#> 19: papery_hog 2025-10-24 13:34:26 1b4ba92d-3bd0-4623-bd26-f6477986956b
#> 20: papery_hog 2025-10-24 13:34:26 6386be23-49f5-4ba4-8bbd-79e8b77abeb1
#>      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