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.01732109 <list[1]> 0.00030002
# returns best scoring evaluation
instance$result
#> x x_domain y
#> <num> <list> <num>
#> 1: 0.01732109 <list[1]> 0.00030002
# 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.08088632 0.006542596 <list[1]> 2025-05-30 08:00:35 1
#> 2: 0.25353401 0.064279492 <list[1]> 2025-05-30 08:00:35 2
#> 3: 0.89142133 0.794631994 <list[1]> 2025-05-30 08:00:35 3
#> 4: -0.30020786 0.090124760 <list[1]> 2025-05-30 08:00:35 4
#> 5: 0.33042004 0.109177406 <list[1]> 2025-05-30 08:00:35 5
#> 6: 0.90841513 0.825218046 <list[1]> 2025-05-30 08:00:35 6
#> 7: -0.31388190 0.098521845 <list[1]> 2025-05-30 08:00:35 7
#> 8: 0.01732109 0.000300020 <list[1]> 2025-05-30 08:00:35 8
#> 9: -0.10746871 0.011549523 <list[1]> 2025-05-30 08:00:35 9
#> 10: -0.42470099 0.180370932 <list[1]> 2025-05-30 08:00:35 10