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.1100163 <list[1]> 0.01210359
# returns best scoring evaluation
instance$result
#> x x_domain y
#> <num> <list> <num>
#> 1: -0.1100163 <list[1]> 0.01210359
# 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.6058181 0.36701552 <list[1]> 2024-12-18 10:02:48 1
#> 2: 0.8535221 0.72849993 <list[1]> 2024-12-18 10:02:48 2
#> 3: -0.5029088 0.25291723 <list[1]> 2024-12-18 10:02:48 3
#> 4: 0.6683794 0.44673099 <list[1]> 2024-12-18 10:02:48 4
#> 5: 0.2044075 0.04178244 <list[1]> 2024-12-18 10:02:48 5
#> 6: 0.6311834 0.39839248 <list[1]> 2024-12-18 10:02:48 6
#> 7: -0.1100163 0.01210359 <list[1]> 2024-12-18 10:02:48 7
#> 8: 0.3430470 0.11768123 <list[1]> 2024-12-18 10:02:48 8
#> 9: 0.4713843 0.22220315 <list[1]> 2024-12-18 10:02:48 9
#> 10: 0.6360771 0.40459405 <list[1]> 2024-12-18 10:02:48 10