OptimizerBatchFocusSearch class that implements a Focus Search.
Focus Search starts with evaluating n_points drawn uniformly at random.
For 1 to maxit batches, n_points are then drawn uniformly at random and if the best value of a batch outperforms the previous best value over all batches evaluated so far, the search space is shrinked around this new best point prior to the next batch being sampled and evaluated.
For details on the shrinking, see shrink_ps.
Depending on the Terminator this procedure simply restarts after maxit is reached.
Dictionary
This Optimizer can be instantiated via the dictionary
mlr_optimizers or with the associated sugar function opt():
Parameters
n_pointsinteger(1)
Number of points to evaluate in each random search batch.maxitinteger(1)
Number of random search batches to run.
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 -> OptimizerBatchFocusSearch
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("focus_search", n_points = 10, maxit = 10)
# trigger optimization
optimizer$optimize(instance)
#> x1 x2 x_domain y
#> <num> <num> <list> <num>
#> 1: 2.935626 -2.575073 <list[2]> 8.944041
# 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: 8 3.35 -72 2025-10-24 13:34:30 1 8 3.35
#> 2: 8 0.01 -37 2025-10-24 13:34:30 1 8 0.01
#> 3: -6 1.02 -72 2025-10-24 13:34:30 1 -6 1.02
#> 4: 7 -0.31 -25 2025-10-24 13:34:30 1 7 -0.31
#> 5: -10 3.86 -175 2025-10-24 13:34:30 1 -10 3.86
#> 6: 8 1.71 -45 2025-10-24 13:34:30 1 8 1.71
#> 7: -2 -1.06 -11 2025-10-24 13:34:30 1 -2 -1.06
#> 8: -8 0.51 -112 2025-10-24 13:34:30 1 -8 0.51
#> 9: 3 -2.58 9 2025-10-24 13:34:30 1 3 -2.58
#> 10: 8 -2.97 -30 2025-10-24 13:34:30 1 8 -2.97
#> 11: -9 -2.43 -103 2025-10-24 13:34:30 2 -9 -2.43
#> 12: -4 1.14 -41 2025-10-24 13:34:30 2 -4 1.14
#> 13: 10 -0.59 -58 2025-10-24 13:34:30 2 10 -0.59
#> 14: -8 -1.84 -85 2025-10-24 13:34:30 2 -8 -1.84
#> 15: 4 -3.99 4 2025-10-24 13:34:30 2 4 -3.99
#> 16: -5 -2.27 -46 2025-10-24 13:34:30 2 -5 -2.27
#> 17: -7 1.54 -98 2025-10-24 13:34:30 2 -7 1.54
#> 18: 9 4.28 -86 2025-10-24 13:34:30 2 9 4.28
#> 19: 8 -4.73 -28 2025-10-24 13:34:30 2 8 -4.73
#> 20: -6 0.59 -66 2025-10-24 13:34:30 2 -6 0.59
#> x1 x2 y timestamp batch_nr x_domain_x1 x_domain_x2
# best performing configuration
instance$result
#> x1 x2 x_domain y
#> <num> <num> <list> <num>
#> 1: 2.935626 -2.575073 <list[2]> 8.944041