A new R6 and much more modular implementation for single- and multicriteria Bayesian optimization.
mlr3mbo
is built modular relying on the following
R6 classes:
Surrogate
: Surrogate ModelAcqFunction
: Acquisition FunctionAcqOptimizer
: Acquisition Function Optimizer
Based on these, Bayesian optimization loops can be written, see, e.g.,
bayesopt_ego
for sequential single objective BO.
mlr3mbo
also provides an OptimizerMbo
class behaving like any other
Optimizer
from the bbotk
package as well as a TunerMbo
class behaving like any other Tuner
from the mlr3tuning
package.
mlr3mbo
uses sensible defaults for the Surrogate
, AcqFunction
,
AcqOptimizer
, and even the loop function. See ?mbo_defaults
for more
details.
Minimize y = x^2
via sequential singlecriteria BO using a GP as
surrogate and EI optimized via random search as aquisition function:
set.seed(1)
library(bbotk)
library(mlr3)
library(mlr3mbo)
library(paradox)
library(mlr3learners)
obfun = ObjectiveRFun$new(
fun = function(xs) list(y1 = xs$x ^ 2),
domain = ps(x = p_dbl(lower = -5, upper = 5)),
codomain = ps(y1 = p_dbl(tags = "minimize"))
)
terminator = trm("evals", n_evals = 10)
instance = OptimInstanceSingleCrit$new(
objective = obfun,
terminator = terminator
)
design = generate_design_lhs(obfun$domain, 4)$data
instance$eval_batch(design)
surrogate = SurrogateLearner$new(lrn("regr.km", control = list(trace = FALSE)))
acqfun = AcqFunctionEI$new()
acqopt = AcqOptimizer$new(
opt("random_search", batch_size = 100),
terminator = trm("evals", n_evals = 100)
)
optimizer = opt("mbo",
loop_function = bayesopt_ego,
surrogate = surrogate,
acq_function = acqfun,
acq_optimizer = acqopt
)
optimizer$optimize(instance)
## x x_domain y1
## 1: 0.01948605 <list[1]> 0.000379706
Note that you can also use bb_optimize
as a shorthand:
set.seed(1)
fun = function(xs) list(y1 = xs$x ^ 2)
surrogate = SurrogateLearner$new(lrn("regr.km", control = list(trace = FALSE)))
acqfun = AcqFunctionEI$new()
acqopt = AcqOptimizer$new(
opt("random_search", batch_size = 100),
terminator = trm("evals", n_evals = 100)
)
optimizer = opt("mbo",
loop_function = bayesopt_ego,
surrogate = surrogate,
acq_function = acqfun,
acq_optimizer = acqopt
)
result = bb_optimize(
fun,
method = optimizer,
lower = c(x = -5),
upper = c(x = 5),
max_evals = 10
)
set.seed(1)
library(mlr3)
library(mlr3tuning)
task = tsk("pima")
learner = lrn("classif.rpart", cp = to_tune(lower = 1e-04, upper = 1e-1, logscale = TRUE))
instance = tune(
method = "mbo",
task = task,
learner = learner,
resampling = rsmp("holdout"),
measure = msr("classif.ce"),
term_evals = 10
)
instance$result