mlrMBO icon indicating copy to clipboard operation
mlrMBO copied to clipboard

Objective function cares what you call its argument!?

Open zkurtz opened this issue 7 years ago • 1 comments
trafficstars

Can anyone replicate this?

library(mlrMBO)

# Copied straight from `makeSingleObjectiveFunction` examples
fn.mixed = makeSingleObjectiveFunction(
  name = "Mixed 2D",
  fn = function(x) x$num1^2 + as.integer(as.character(x$disc1) == "a"),
  has.simple.signature = FALSE,
  par.set = makeParamSet(
    makeNumericParam("num1", lower = -5, upper = 5),
    makeDiscreteParam("disc1", values = c("a", "b"))
  ),
  global.opt.params = list(num1 = 0, disc1 = "b")
)

# Same as above, but replacing "x" with "z" in the objective
fn.mixed.z = makeSingleObjectiveFunction(
  name = "Mixed 2D",
  fn = function(z) z$num1^2 + as.integer(as.character(z$disc1) == "a"),
  has.simple.signature = FALSE,
  par.set = makeParamSet(
    makeNumericParam("num1", lower = -5, upper = 5),
    makeDiscreteParam("disc1", values = c("a", "b"))
  ),
  global.opt.params = list(num1 = 0, disc1 = "b")
)

# Works as expected
mlrMBO::mbo(fn.mixed,
    control = mlrMBO::makeMBOControl(),
    show.info = FALSE)

# Crashes:
mlrMBO::mbo(fn.mixed.z,
    control = mlrMBO::makeMBOControl(),
    show.info = FALSE)

The error:

Error in (function (z)  : 
  unused argument (x = list(0.753873288049363, "b"))

Is this desired behavior? If so, maybe the error could be made more descriptive?

Details: OSX 10.13.6 R 3.5.1 mlrMBO version 1.1.2

zkurtz avatar Sep 16 '18 11:09 zkurtz

Let me ping @jakobbossek to see what is his opinion. How is it supposed to be in smoof?

jakob-r avatar Sep 16 '18 15:09 jakob-r