Optimization via Covariance Matrix Adaptation Evolution Strategy
Source:R/OptimizerBatchCmaes.R
mlr_optimizers_cmaes.RdOptimizerBatchCmaes class that implements CMA-ES.
Calls libcmaesr::cmaes() from package libcmaesr, which is a lightweight interface to the libcmaes C++
library.
The algorithm is typically applied to search space dimensions between three and fifty.
Dictionary
This Optimizer can be instantiated via the dictionary
mlr_optimizers or with the associated sugar function opt():
Parameters
start_valuescharacter(1)
Create"random"start values or based on"center"of search space? In the latter case, it is the center of the parameters before a trafo is applied. If set to"custom", the start values can be passed via thestartparameter.startnumeric()
Custom start values. Only applicable ifstart_valuesparameter is set to"custom".seedinteger(1)
Seed of the random number generator oflibcmaes. Unset by default, in which case the generator is seeded from R and the optimization is reproducible withset.seed().
All remaining parameters are passed to libcmaesr::cmaes_control(), see there for their meaning.
Note that we have removed all control parameters which refer to the termination of the algorithm and where our
terminators allow to obtain the same behavior, i.e. max_fevals, max_iter, and ftarget.
The internal convergence criteria of the algorithm still apply, so the optimization can stop before the
Terminator is triggered.
Batch evaluation
The optimizer evaluates a whole generation of lambda points in one batch.
The Terminator is only checked between generations, so the number of evaluations can exceed the budget of
TerminatorEvals by up to lambda - 1 points.
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
Optimizer -> OptimizerBatch -> OptimizerBatchCmaes
Examples
# example only runs if libcmaesr is available
if (mlr3misc::require_namespaces("libcmaesr", quietly = TRUE)) {
# define the objective function
fun = function(xs) {
list(y = - (xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 - (xs[[3]] + 4)^2 + 10)
}
# set domain
domain = ps(
x1 = p_dbl(-10, 10),
x2 = p_dbl(-5, 5),
x3 = 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("cmaes")
# trigger optimization
optimizer$optimize(instance)
# all evaluated configurations
instance$archive
# best performing configuration
instance$result
}
#> x1 x2 x3 x_domain y
#> <num> <num> <num> <list> <num>
#> 1: 2.018607 2.802398 -3.736987 <list[3]> -23.73735