mlr-org / bbotk

Black-box optimization framework for R.
https://bbotk.mlr-org.com
GNU Lesser General Public License v3.0
20 stars 9 forks source link

archive$best() no longer has deterministic behavior #219

Closed sumny closed 9 months ago

sumny commented 9 months ago
library(bbotk)
library(data.table)
instance = OptimInstanceSingleCrit$new(
  objective = ObjectiveRFun$new(fun = function(xs) xs$x^2,
  domain = ps(x = p_dbl(-1, 1)),
  codomain = ps(y = p_dbl(tags = "maximize"))),
  terminator = trm("evals", n_evals = 3)
)
instance$eval_batch(data.table(x = c(-1, 0, 1)))
instance$archive$best()
   x y  x_domain           timestamp batch_nr
1: 1 1 <list[1]> 2024-01-20 20:35:12        1
instance$archive$best()
    x y  x_domain           timestamp batch_nr
1: -1 1 <list[1]> 2024-01-20 20:35:12        1

so if the optimum is not unique, archive$best() will return any optimal point at random. Not sure if this is intended behavior but this used to be different and might be somewhat problematic if people program around archive$best() instead of storing the best and then using this value.

sumny commented 9 months ago

fixed by https://github.com/mlr-org/bbotk/commit/61fa3783b1669833e4bd841e07bb3e652a63ff12