Package website: release | dev
A new R6 and much more modular implementation for single- and multi-objective Bayesian Optimization.
An overview and gentle introduction is given in this vignette.
mlr3mbo
is built modular relying on the following R6 classes:
Surrogate
: Surrogate ModelAcqFunction
: Acquisition FunctionAcqOptimizer
: Acquisition Function OptimizerBased 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 f(x) = x^2
via sequential single-objective BO
using a GP as surrogate and EI optimized via random search as
acquisition function:
library(bbotk)
library(mlr3mbo)
library(mlr3learners)
set.seed(1)
= ObjectiveRFun$new(
obfun fun = function(xs) list(y1 = xs$x ^ 2),
domain = ps(x = p_dbl(lower = -10, upper = 10)),
codomain = ps(y1 = p_dbl(tags = "minimize")))
= oi(
instance objective = obfun,
terminator = trm("evals", n_evals = 10))
= srlrn(lrn("regr.km", control = list(trace = FALSE)))
surrogate = acqf("ei")
acqfun = acqo(opt("random_search", batch_size = 100),
acqopt terminator = trm("evals", n_evals = 100))
= opt("mbo",
optimizer loop_function = bayesopt_ego,
surrogate = surrogate,
acq_function = acqfun,
acq_optimizer = acqopt)
$optimize(instance) optimizer
## x x_domain y1
## <num> <list> <num>
## 1: 0.03897209 <list[1]> 0.001518824
Note that you can also use bb_optimize
as a
shorthand:
library(bbotk)
library(mlr3mbo)
library(mlr3learners)
set.seed(1)
= function(xs) list(y1 = xs$x ^ 2)
fun
= srlrn(lrn("regr.km", control = list(trace = FALSE)))
surrogate = acqf("ei")
acqfun = acqo(opt("random_search", batch_size = 100),
acqopt terminator = trm("evals", n_evals = 100))
= opt("mbo",
optimizer loop_function = bayesopt_ego,
surrogate = surrogate,
acq_function = acqfun,
acq_optimizer = acqopt)
= bb_optimize(
result
fun,method = optimizer,
lower = c(x = -10),
upper = c(x = 10),
max_evals = 10)
library(mlr3)
library(mlr3learners)
library(mlr3tuning)
library(mlr3mbo)
set.seed(1)
= tsk("pima")
task
= lrn("classif.rpart", cp = to_tune(lower = 1e-04, upper = 1, logscale = TRUE))
learner
= tune(
instance tuner = tnr("mbo"),
task = task,
learner = learner,
resampling = rsmp("holdout"),
measure = msr("classif.ce"),
term_evals = 10)
$result instance
## cp learner_param_vals x_domain classif.ce
## <num> <list> <list> <num>
## 1: -4.381681 <list[2]> <list[1]> 0.2070312