Optimization via Random Search
Source:R/OptimizerBatchRandomSearch.R
mlr_optimizers_random_search.Rd
OptimizerBatchRandomSearch
class that implements a simple Random Search.
In order to support general termination criteria and parallelization, we
evaluate points in a batch-fashion of size batch_size
. Larger batches mean
we can parallelize more, smaller batches imply a more fine-grained checking
of termination criteria.
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()
:
Progress Bars
$optimize()
supports progress bars via the package progressr
combined with a Terminator. Simply wrap the function in
progressr::with_progress()
to enable them. We recommend to use package
progress as backend; enable with progressr::handlers("progress")
.
Super classes
bbotk::Optimizer
-> bbotk::OptimizerBatch
-> OptimizerBatchRandomSearch
Examples
search_space = domain = ps(x = p_dbl(lower = -1, upper = 1))
codomain = ps(y = p_dbl(tags = "minimize"))
objective_function = function(xs) {
list(y = as.numeric(xs)^2)
}
objective = ObjectiveRFun$new(
fun = objective_function,
domain = domain,
codomain = codomain)
instance = OptimInstanceBatchSingleCrit$new(
objective = objective,
search_space = search_space,
terminator = trm("evals", n_evals = 10))
optimizer = opt("random_search")
# modifies the instance by reference
optimizer$optimize(instance)
#> x x_domain y
#> <num> <list> <num>
#> 1: 0.02069745 <list[1]> 0.0004283846
# returns best scoring evaluation
instance$result
#> x x_domain y
#> <num> <list> <num>
#> 1: 0.02069745 <list[1]> 0.0004283846
# allows access of data.table of full path of all evaluations
as.data.table(instance$archive$data)
#> x y x_domain timestamp batch_nr
#> <num> <num> <list> <POSc> <int>
#> 1: -0.38728307 0.1499881785 <list[1]> 2025-10-14 15:41:36 1
#> 2: 0.72684146 0.5282985025 <list[1]> 2025-10-14 15:41:36 2
#> 3: -0.39775191 0.1582065835 <list[1]> 2025-10-14 15:41:36 3
#> 4: -0.39600806 0.1568223849 <list[1]> 2025-10-14 15:41:36 4
#> 5: 0.02069745 0.0004283846 <list[1]> 2025-10-14 15:41:36 5
#> 6: 0.23661496 0.0559866376 <list[1]> 2025-10-14 15:41:36 6
#> 7: -0.75617397 0.5717990711 <list[1]> 2025-10-14 15:41:36 7
#> 8: 0.86804544 0.7535028826 <list[1]> 2025-10-14 15:41:36 8
#> 9: -0.24157158 0.0583568303 <list[1]> 2025-10-14 15:41:36 9
#> 10: -0.51128462 0.2614119665 <list[1]> 2025-10-14 15:41:36 10