| mlr_optimizers_cmaes | R Documentation |
OptimizerBatchCmaes 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.
This Optimizer can be instantiated via the dictionary
mlr_optimizers or with the associated sugar function opt():
mlr_optimizers$get("cmaes")
opt("cmaes")
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 the start parameter.
startnumeric()
Custom start values. Only applicable if start_values parameter is set to "custom".
seedinteger(1)
Seed of the random number generator of libcmaes.
Unset by default, in which case the generator is seeded from R and the optimization is reproducible with
set.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.
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.
$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").
Optimizer -> OptimizerBatch -> OptimizerBatchCmaes
OptimizerBatchCmaes$new()Creates a new instance of this R6 class.
OptimizerBatchCmaes$new()
OptimizerBatchCmaes$clone()The objects of this class are cloneable with this method.
OptimizerBatchCmaes$clone(deep = FALSE)
deepWhether to make a deep clone.
# 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
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.