jakobbossek/smoof

smoof and vector parameters

jakob-r opened this issue · 2 comments

How should we handle such functions?

fun_vec = function(x) {
  x1 = x$x1
  x2 = x$x2
  checkmate::assert_numeric(x1, len = 3)
  checkmate::assert_integerish(x2, len = 3)
  sum(x1^2 * x2)
}

ps = makeParamSet(
  makeNumericVectorParam("x1", len = 3, lower = -1, upper = 1),
  makeIntegerVectorParam("x2", len = 3, lower = 1, upper = 10)
)

obj_f = makeSingleObjectiveFunction(
  name = "vec_test",
  fn = fun_vec, 
  par.set = ps, 
  noisy = FALSE, 
  vectorized = FALSE) 

fun_vec(list(x1 = c(-1,0,1), x2 = 1:3))
obj_f(list(x1 = c(-1,0,1), x2 = 1:3)) #does not work

The problem is that smoof calls unlist on the first function argument (x).

Another option is to not define fun_vec with lists

fun_vec = function(x1, x2) {
  checkmate::assert_numeric(x1, len = 3)
  checkmate::assert_integerish(x2, len = 3)
  sum(x1^2 * x2)
}

ps = makeParamSet(
  makeNumericVectorParam("x1", len = 3, lower = -1, upper = 1),
  makeIntegerVectorParam("x2", len = 3, lower = 1, upper = 10)
)

obj_f = makeSingleObjectiveFunction(
  name = "vec_test",
  fn = fun_vec, 
  par.set = ps, 
  noisy = FALSE, 
  vectorized = FALSE) 

fun_vec(x1 = c(-1,0,1), x2 = 1:3)
obj_f(x = c(-1,0,1), x2 = 1:3)

Ugly because:

  • would change slightly how mlrMBO works
  • obj_f has another signatur: The first argument of fun_vec becomes x and the rest is dotted.

Hi J.R.,

this should work

obj_f = makeSingleObjectiveFunction(
  name = "vec_test",
  fn = fun_vec,
  has.simple.signature = FALSE,
  par.set = ps,
  noisy = FALSE,
  vectorized = FALSE)

You need to tell the function that the function signature is not simple, i.e., requires lists.

Indeed. Forgot that option. Sorry!