library("bbotk")
lgr::threshold("warn")
# Define the objective to optimize
objective <- ObjectiveRFun$new(
fun = function(xs) {
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)),
codomain = ps(Obj = p_dbl(tags = "maximize"))
)
# Get a new OptimInstance
oi <- OptimInstanceSingleCrit$new(objective,
terminator = trm("evals", n_evals = 100)
)
mies_init_population(inst = oi, mu = 3)
# 3 evaluations, archive contains 'dob' and 'eol'
oi$archive
###
# Advanced demo, making use of additional components and fidelity
##
# Get a new OptimInstance
oi <- OptimInstanceSingleCrit$new(objective,
terminator = trm("evals", n_evals = 100)
)
mies_init_population(inst = oi, mu = 3, budget_id = "y", fidelity = 2,
additional_component_sampler = Sampler1DRfun$new(
param = ps(additional = p_dbl(-1, 1)), rfun = function(n) rep(-1, n)
)
)
# 3 evaluations. We also have 'additional', sampled from rfun (always -1),
# which is ignored by the objective. Besides, we have "y", which is 2,
# according to 'fidelity'.
oi$archive
Run the code above in your browser using DataLab