Set up an OptimInstance for MIES optimization.
This adds the dob and eol columns to the instance's archive, and makes sure there are at least mu survivors
(i.e. entries with eol set to NA) present. If there are already >= mu prior evaluations present, then the last
mu of these remain alive (the other's eol set to 0); otherwise, up to mu new randomly sampled configurations
are evaluated and added to the archive and have eol set to NA.
mies_init_population(
inst,
mu,
initializer = generate_design_random,
survival_selector = SelectorBest$new()$prime(inst$search_space),
budget_id = NULL,
fidelity = NULL,
fidelity_new_individuals_only = FALSE,
fidelity_monotonic = TRUE,
additional_component_sampler = NULL
)(OptimInstance)
Optimization instance to evaluate.
(integer(1))
Population target size, non-negative integer.
(function)
Function that generates a Design object, with arguments param_set and n, functioning like paradox::generate_design_random
or paradox::generate_design_lhs. Note that paradox::generate_design_grid can not be used and must be wrapped with
a custom function that ensures that only n individuals are produced. The generated design must correspond to the inst's $search_space; for
components that are not in the objective's search space, the additional_component_sampler is used.
(Selector)
Used when the given OptimInstance already contains more individuals than mu.Selector operator that selects surviving individuals depending on configuration values
and objective results, When survival_selector$operate() is called, then objectives that
are being minimized are multiplied with -1 (through mies_get_fitnesses), since Selectors always try to maximize fitness.
The Selector must be primed on inst$search_space; this includes the "budget" component
when performing multi-fidelity optimization. Default is SelectorBest.
The given Selector may not return duplicates.
(character(1) | NULL)
Budget component when doing multi-fidelity optimization. This component of the search space is added
to individuals according to fidelity. Should be NULL when no multi-fidelity optimization is performed (default).
(atomic(1) | NULL)
Atomic scalar indicating the value to be assigned to the budget_id component of offspring.
This value must be NULL if no multi-fidelity optimization is performed (the default).
(logical(1))
When fidelity is not NULL: Whether to re-evaluate individuals that are already present in inst should they have a smaller (if fidelity_monotonic is TRUE) or different
(if fidelity_monotonic is FALSE) value from the one given to fidelity. Default FALSE. Ignored when fidelity is NULL.
(logical(1))
Whether to only re-evaluate configurations for which the fidelity would increase. Default TRUE.
Ignored when fidelity is NULL or when fidelity_new_individuals_only is TRUE.
(Sampler | NULL)Sampler for components of individuals that are not part of inst's $search_space. These components
are never used for performance evaluation, but they may be useful for self-adaptive OperatorCombinations. See the description
of mies_prime_operators() on how operators need to be primed to respect additional components.
It is possible that additional_component_sampler is used for more rows than initializer, which happens
when the inst's $archive contains prior evaluations that are alive, but does not contain columns pertaining to additional columns,
or contains all these columns but there are rows that are NA valued. If only some of the columns are present, or if all these columns
are present but there are rows that are only NA valued for some columns, then an error is thrown.
Default is NULL: no additional components.
Other mies building blocks:
mies_evaluate_offspring(),
mies_generate_offspring(),
mies_get_fitnesses(),
mies_select_from_archive(),
mies_step_fidelity(),
mies_survival_comma(),
mies_survival_plus()
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
#> <Archive>
#> x y dob eol x_id Obj timestamp batch_nr
#> <num> <num> <num> <num> <num> <num> <POSc> <int>
#> 1: 1.97 -0.2384 1 NA 1 0.033 2024-05-13 04:41:08 1
#> 2: 0.44 0.7544 1 NA 2 0.503 2024-05-13 04:41:08 1
#> 3: 3.48 -0.0056 1 NA 3 0.004 2024-05-13 04:41:08 1
###
# 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 = ParamDbl$new("additional", -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
#> <Archive>
#> additional x y dob eol x_id Obj timestamp batch_nr
#> <num> <num> <num> <num> <num> <num> <num> <POSc> <int>
#> 1: -1 1.91 2 1 NA 1 1.98 2024-05-13 04:41:08 1
#> 2: -1 -0.45 2 1 NA 2 0.02 2024-05-13 04:41:08 1
#> 3: -1 0.87 2 1 NA 3 0.57 2024-05-13 04:41:08 1