OptimizerBatchChain
allows to run multiple OptimizerBatch sequentially.
For each OptimizerBatch an (optional) additional Terminator can be specified during construction. While the original Terminator of the OptimInstanceBatch guards the optimization process as a whole, the additional Terminators guard each individual OptimizerBatch.
The optimization process works as follows: The first OptimizerBatch is run on the OptimInstanceBatch relying on a TerminatorCombo of the original Terminator of the OptimInstanceBatch and the (optional) additional Terminator as passed during construction. Once this TerminatorCombo indicates termination (usually via the additional Terminator), the second OptimizerBatch is run. This continues for all optimizers unless the original Terminator of the OptimInstanceBatch indicates termination.
OptimizerBatchChain can also be used for random restarts of the same Optimizer (if applicable) by setting the Terminator of the OptimInstanceBatch to TerminatorNone and setting identical additional Terminators during construction.
Dictionary
This Optimizer can be instantiated via the dictionary
mlr_optimizers or with the associated sugar function opt()
:
Parameters
Parameters are inherited from the individual OptimizerBatch and collected as a
paradox::ParamSetCollection (with set_id
s potentially postfixed via _1
, _2
,
..., if the same OptimizerBatch are used multiple times).
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
-> OptimizerBatchChain
Methods
Method new()
Creates a new instance of this R6 class.
Usage
OptimizerBatchChain$new(
optimizers,
terminators = rep(list(NULL), length(optimizers))
)
Arguments
optimizers
(list of Optimizers).
terminators
(list of Terminators | NULL).
Examples
library(paradox)
domain = ps(x = p_dbl(lower = -1, upper = 1))
search_space = 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
)
terminator = trm("evals", n_evals = 10)
# run optimizers sequentially
instance = OptimInstanceBatchSingleCrit$new(
objective = objective,
search_space = search_space,
terminator = terminator
)
optimizer = opt("chain",
optimizers = list(opt("random_search"), opt("grid_search")),
terminators = list(trm("evals", n_evals = 5), trm("evals", n_evals = 5))
)
optimizer$optimize(instance)
#> x x_domain y
#> <num> <list> <num>
#> 1: 0.08496082 <list[1]> 0.00721834
# random restarts
instance = OptimInstanceBatchSingleCrit$new(
objective = objective,
search_space = search_space,
terminator = trm("none")
)
optimizer = opt("chain",
optimizers = list(opt("gensa"), opt("gensa")),
terminators = list(trm("evals", n_evals = 10), trm("evals", n_evals = 10))
)
optimizer$optimize(instance)
#> x x_domain y
#> <num> <list> <num>
#> 1: -3.266831e-13 <list[1]> 1.067219e-25