OptimizerBatchIrace
class that implements iterated racing. Calls
irace::irace()
from package irace.
instances
list()
A list of instances where the configurations executed on.
targetRunnerParallel
function()
A function that executes the objective function with a specific parameter
configuration and instance. A default function is provided, see section
"Target Runner and Instances".
For the meaning of all other parameters, see irace::defaultScenario()
. Note
that we have removed all control parameters which refer to the termination of
the algorithm. Use TerminatorEvals instead. Other terminators do not work
with OptimizerBatchIrace
.
In contrast to irace::defaultScenario()
, we set digits = 15
.
This represents double parameters with a higher precision and avoids rounding errors.
The irace package uses a targetRunner
script or R function to evaluate a
configuration on a particular instance. Usually it is not necessary to
specify a targetRunner
function when using OptimizerBatchIrace
. A default
function is used that forwards several configurations and instances to the
user defined objective function. As usually, the user defined function has
a xs
, xss
or xdt
parameter depending on the used Objective class.
For irace, the function needs an additional instances
parameter.
fun = function(xs, instances) {
# function to evaluate configuration in `xs` on instance `instances`
}
The Archive holds the following additional columns:
"race"
(integer(1)
)
Race iteration.
"step"
(integer(1)
)
Step number of race.
"instance"
(integer(1)
)
Identifies instances across races and steps.
"configuration"
(integer(1)
)
Identifies configurations across races and steps.
The optimization result (instance$result
) is the best performing elite of
the final race. The reported performance is the average performance estimated
on all used instances.
This Optimizer can be instantiated via the dictionary
mlr_optimizers or with the associated sugar function opt()
:
mlr_optimizers$get("irace")
opt("irace")
$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")
.
bbotk::Optimizer
-> bbotk::OptimizerBatch
-> OptimizerBatchIrace
# runtime of the example is too long
# \donttest{
library(data.table)
search_space = domain = ps(
x1 = p_dbl(-5, 10),
x2 = p_dbl(0, 15)
)
codomain = ps(y = p_dbl(tags = "minimize"))
# branin function with noise
# the noise generates different instances of the branin function
# the noise values are passed via the `instances` parameter
fun = function(xdt, instances) {
ys = branin(xdt[["x1"]], xdt[["x2"]], noise = as.numeric(instances))
data.table(y = ys)
}
# define objective with instances as a constant
objective = ObjectiveRFunDt$new(
fun = fun,
domain = domain,
codomain = codomain,
constants = ps(instances = p_uty()))
instance = OptimInstanceBatchSingleCrit$new(
objective = objective,
search_space = search_space,
terminator = trm("evals", n_evals = 96))
# create instances of branin function
instances = rnorm(10, mean = 0, sd = 0.1)
# load optimizer irace and set branin instances
optimizer = opt("irace", instances = instances)
# modifies the instance by reference
optimizer$optimize(instance)
# best scoring configuration
instance$result
# all evaluations
as.data.table(instance$archive)
# }
Run the code above in your browser using DataLab