mlr-org / miesmuschel

Flexible Mixed Integer Evolutionary Strategies
Other
15 stars 4 forks source link

dependency checks after recombination #65

Open pfistfl opened 3 years ago

pfistfl commented 3 years ago

Sorry if this is already mentioned somewhere, could not find anything.

I adapted the code from the README slightly to add a dependency. The code now breaks at private$.primed_ps$assert_dt(values) during recombination because a value should suddenly be NA.

library("bbotk")
library("paradox")
lgr::threshold("warn")

objective <- ObjectiveRFun$new(
  fun = function(xs) {
    if(is.null(xs$y)) xs$y = 2
    z <- exp(-xs$x^2 - xs$y^2) + 2 * exp(-(2 - xs$x)^2 - (2 - xs$y)^2)
    list(Obj = z)
  },
  domain = ps(
    x = p_dbl(-2, 4),
    y = p_dbl(-2, 4, depends = d == 1),
    d = p_int(lower = 0, upper = 1)
  ),
  codomain = ps(Obj = p_dbl(tags = "maximize"))
)
# Get a new OptimInstance
oi <- OptimInstanceSingleCrit$new(objective,
  terminator = trm("evals", n_evals = 100)
)

library("miesmuschel")

# Get operators
op.m <- mut("gauss")
op.r <- rec("xounif", p = .3)
op.parent <- sel("random")
op.survival <- sel("best")

# Create OptimizerMies object
mies <- opt("mies", mutator = op.m, recombinator = op.r,
  parent_selector = op.parent, survival_selector = op.survival,
  mu = 3, lambda = 2)

mies$optimize(oi)