Purpose

This Vignette shows you how to use mlrMBO for a guided optimization. In this setting mlrMBO proposes a candidate configuration and you can then decide for yourself whether you want to evaluate it or another value. You have to evaluate the objective function manually. The value and the result have to be feed back to mlrMBO. Afterwards you can request the next candidate and so on.

Introduction

Before we start the optimization you need to define the search space:

ps = makeParamSet(
  makeNumericParam("q", lower = -1, upper = 2),
  makeIntegerParam("v", lower = -2, upper = 3)
)

Furthermore we need an initial design that includes the results of the evaluated function

des = generateDesign(n = 7, par.set = ps)
des
##             q  v
## 1  1.18696772  2
## 2 -0.61436073  0
## 3 -0.03739097 -1
## 4  1.58945409  3
## 5 -0.43089112  2
## 6  0.69478728 -2
## 7  1.09551685  1

After evaluating the objective function manually we can add the results

des$y = c(1.20, 0.97, 0.91, 3.15, 0.58, 1.12, 0.50)

Now we define our mlrMBO-Control object. For this example we stick to the defaults except that we set the infill-criterion to the Expected Improvement

ctrl = makeMBOControl()
ctrl = setMBOControlInfill(ctrl, crit = crit.ei)

These information are enough to get us started and initialize the sequential MBO.

opt.state = initSMBO(par.set = ps, design = des, control = ctrl, minimize = TRUE, noisy = FALSE)

At each state the opt.state object can be plotted to visualize the predictions of the surrogate model

plot(opt.state)

The first panel shows the value of the infill criterion. The higher the value the more this area is desirable to be explored to find the optimum. In the following panels the mean prediction of the surrogate and the uncertainty estimation is plotted.

Let’s see which point MBO suggests we should evaluate in the next step:

proposePoints(opt.state)
## $prop.points
##            q  v
## 150 1.011225 -1
## 
## $propose.time
## [1] 0.265
## 
## $prop.type
## [1] "infill_ei"
## 
## $crit.vals
##            [,1]
## [1,] -0.2222111
## 
## $crit.components
##          se      mean
## 1 0.4272983 0.4049185
## 
## $errors.model
## [1] NA
## 
## attr(,"class")
## [1] "Proposal" "list"

We don’t have to stick to the suggestion and evaluate another point:

x = data.frame(q = 1.7, v = 1)

After we evaluated the objective function manually we get a return value of 2.19. We take both values to update MBO:

updateSMBO(opt.state, x = x, y = 2.19)

Now we can plot the state again and ask for a proposal:

plot(opt.state)

(prop = proposePoints(opt.state))
## $prop.points
##             q v
## 941 0.9937339 0
## 
## $propose.time
## [1] 0.131
## 
## $prop.type
## [1] "infill_ei"
## 
## $crit.vals
##            [,1]
## [1,] -0.1836443
## 
## $crit.components
##          se      mean
## 1 0.3871173 0.4447291
## 
## $errors.model
## [1] NA
## 
## attr(,"class")
## [1] "Proposal" "list"

This time we evaluated the exact proposed points and get a value of 0.13.

updateSMBO(opt.state, x = prop$prop.points, y = 0.13)

Let’s assume we want to stop here. To get to the usual MBO result you can call:

res = finalizeSMBO(opt.state)
res$x
## $q
## [1] 0.9937339
## 
## $v
## [1] 0
res$y
## [1] 0.13

Semi Automatic MBO

You can combine the human-in-the-loop MBO with a simple loop to let MBO run for a while and just interfere once in a while.

f = function(q, v) 1 + sin(q*5) + 0.1 * (q^2 + v^2)
for (i in 1:10) {
  prop = proposePoints(opt.state)
  x = dfRowsToList(df = prop$prop.points, par.set = ps)
  y = do.call(f, x[[1]])
  updateSMBO(opt.state, x = prop$prop.points, y = y)
}
proposePoints(opt.state)
## $prop.points
##              q v
## 387 -0.3000646 0
## 
## $propose.time
## [1] 0.124
## 
## $prop.type
## [1] "infill_ei"
## 
## $crit.vals
##              [,1]
## [1,] -0.002831849
## 
## $crit.components
##            se       mean
## 1 0.009017027 0.01173291
## 
## $errors.model
## [1] NA
## 
## attr(,"class")
## [1] "Proposal" "list"

Continue a normal MBO Run

You can also continue a normal call of mbo() using this manual interface:

fun = makeAlpine02Function(1)
res = mbo(fun = fun, control = ctrl)
## Computing y column(s) for design. Not provided.
## [mbo] 0: x=2.9 : y = 0.404 : 0.0 secs : initdesign
## [mbo] 0: x=0.95 : y = 0.793 : 0.0 secs : initdesign
## [mbo] 0: x=9.8 : y = -1.14 : 0.0 secs : initdesign
## [mbo] 0: x=5.7 : y = -1.32 : 0.0 secs : initdesign
## [mbo] 1: x=1.62e-05 : y = 6.5e-08 : 0.0 secs : infill_ei
## [mbo] 2: x=1.63 : y = 1.27 : 0.0 secs : infill_ei
## [mbo] 3: x=1.89 : y = 1.31 : 0.0 secs : infill_ei
## [mbo] 4: x=1.79 : y = 1.31 : 0.0 secs : infill_ei
## [mbo] 5: x=1.84 : y = 1.31 : 0.0 secs : infill_ei
## [mbo] 6: x=2.03 : y = 1.28 : 0.0 secs : infill_ei
## [mbo] 7: x=1.82 : y = 1.31 : 0.0 secs : infill_ei
## [mbo] 8: x=1.86 : y = 1.31 : 0.0 secs : infill_ei
## [mbo] 9: x=1.83 : y = 1.31 : 0.0 secs : infill_ei
## [mbo] 10: x=1.84 : y = 1.31 : 0.0 secs : infill_ei
opt.state = res$final.opt.state
plot(opt.state, scale.panels = TRUE)

(prop = proposePoints(opt.state))
## $prop.points
##            x
## 487 1.836319
## 
## $propose.time
## [1] 0.084
## 
## $prop.type
## [1] "infill_ei"
## 
## $crit.vals
##               [,1]
## [1,] -4.518056e-05
## 
## $crit.components
##             se     mean
## 1 0.0001131826 1.307619
## 
## $errors.model
## [1] NA
## 
## attr(,"class")
## [1] "Proposal" "list"
y = fun(prop$prop.points)
updateSMBO(opt.state, x = prop$prop.points, y = y)
# ...

Proposal of multiple points

Using Multi-Point MBO you can also obtain multiple suggestions at each call of proposePoints().

ctrl = makeMBOControl(propose.points = 4)
ctrl = setMBOControlInfill(ctrl, crit = makeMBOInfillCritEI())
ctrl = setMBOControlMultiPoint(ctrl, method = "cl")
opt.state = initSMBO(par.set = ps, design = des, control = ctrl, minimize = TRUE, noisy = FALSE)
(prop = proposePoints(opt.state))
## $prop.points
##               q v
## 844 -0.92029797 1
## 642  0.07998039 1
## 963 -0.99995339 2
## 447  1.99999879 0
## 
## $propose.time
## [1] 0.096 0.101 0.106 0.100
## 
## $prop.type
## [1] "infill_ei" "infill_ei" "infill_ei" "infill_ei"
## 
## $crit.vals
##             [,1]
## [1,] -0.24670322
## [2,] -0.14032897
## [3,] -0.07620927
## [4,] -0.05269038
## 
## $crit.components
##          se      mean
## 1 0.4996289 0.4114801
## 2 0.1836356 0.3909594
## 3 0.1156264 0.4487536
## 4 0.4739049 0.8999264
## 
## $errors.model
## [1] NA NA NA NA
## 
## attr(,"class")
## [1] "Proposal" "list"

It’s also okay to just evaluate a subset of these points.

updateSMBO(opt.state, x = prop$prop.points[1:2,], y = list(2.28, 1.67))
# ...