OptimizerBatchGridSearch class that implements grid search. The grid is
constructed as a Cartesian product over discretized values per parameter, see
paradox::generate_design_grid(). The points of the grid are evaluated in a
random order.
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.
Dictionary
This Optimizer can be instantiated via the dictionary
mlr_optimizers or with the associated sugar function opt():
Parameters
resolutioninteger(1)
Resolution of the grid, seeparadox::generate_design_grid().param_resolutionsnamed
integer()
Resolution per parameter, named by parameter ID, seeparadox::generate_design_grid().batch_sizeinteger(1)
Maximum number of points to try in a batch.
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 -> OptimizerBatchGridSearch
Examples
# 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"
)
# initialize instance
instance = oi(
objective = objective,
terminator = trm("evals", n_evals = 20)
)
# load optimizer
optimizer = opt("grid_search", resolution = 10)
# trigger optimization
optimizer$optimize(instance)
#> x1 x2 x_domain y
#> <num> <num> <list> <num>
#> 1: 3.333333 -1.666667 <list[2]> 6.444444
# all evaluated configurations
instance$archive
#>
#> ── <ArchiveBatch> - Data Table Storage ─────────────────────────────────────────
#> x1 x2 y timestamp batch_nr x_domain_x1 x_domain_x2
#> <num> <num> <num> <POSc> <int> <num> <num>
#> 1: -1 -3.9 -0.5 2026-03-20 06:19:33 1 -1 -3.9
#> 2: 8 5.0 -87.4 2026-03-20 06:19:33 2 8 5.0
#> 3: 3 3.9 -39.2 2026-03-20 06:19:33 3 3 3.9
#> 4: -1 0.6 -12.3 2026-03-20 06:19:33 4 -1 0.6
#> 5: -6 3.9 -94.5 2026-03-20 06:19:33 5 -6 3.9
#> 6: -10 1.7 -155.8 2026-03-20 06:19:33 6 -10 1.7
#> 7: -8 0.6 -98.2 2026-03-20 06:19:33 7 -8 0.6
#> 8: 3 2.8 -25.2 2026-03-20 06:19:33 8 3 2.8
#> 9: -8 3.9 -133.1 2026-03-20 06:19:33 9 -8 3.9
#> 10: -6 -1.7 -48.9 2026-03-20 06:19:33 10 -6 -1.7
#> 11: -3 -5.0 -22.4 2026-03-20 06:19:33 11 -3 -5.0
#> 12: 10 2.8 -87.4 2026-03-20 06:19:33 12 10 2.8
#> 13: -6 1.7 -68.9 2026-03-20 06:19:33 13 -6 1.7
#> 14: -10 -3.9 -134.8 2026-03-20 06:19:34 14 -10 -3.9
#> 15: -3 1.7 -40.2 2026-03-20 06:19:34 15 -3 1.7
#> 16: 3 -1.7 6.4 2026-03-20 06:19:34 16 3 -1.7
#> 17: 6 -0.6 -8.6 2026-03-20 06:19:34 17 6 -0.6
#> 18: 10 -0.6 -60.0 2026-03-20 06:19:34 18 10 -0.6
#> 19: 3 -5.0 4.2 2026-03-20 06:19:34 19 3 -5.0
#> 20: 1 5.0 -54.8 2026-03-20 06:19:34 20 1 5.0
#> x1 x2 y timestamp batch_nr x_domain_x1 x_domain_x2
#> <num> <num> <num> <POSc> <int> <num> <num>
# best performing configuration
instance$result
#> x1 x2 x_domain y
#> <num> <num> <list> <num>
#> 1: 3.333333 -1.666667 <list[2]> 6.444444