# example only runs if irace is available
if (mlr3misc::require_namespaces("irace", quietly = TRUE)) {
# runtime of the example is too long
# \donttest{
library(data.table)
# set domain
domain = ps(
x1 = p_dbl(-5, 10),
x2 = p_dbl(0, 15)
)
# set codomain
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 = oi(
objective = objective,
terminator = trm("evals", n_evals = 96))
# create instances of branin function
instances = rnorm(10, mean = 0, sd = 0.1)
# load optimizer and set branin instances
optimizer = opt("irace", instances = instances)
# trigger optimization
optimizer$optimize(instance)
# all evaluated configurations
instance$archive
# best performing configuration
instance$result
# }
}
Run the code above in your browser using DataLab