mies_generate_offspring: Generate Offspring Through Mutation and Recombination

View source: R/mies_methods.R

mies_generate_offspringR Documentation

Generate Offspring Through Mutation and Recombination

Description

Generate new proposal individuals to be evaluated using mies_evaluate_offspring().

Parent individuals are selected using parent_selector, then mutated using mutator, and thend recombined using recombinator. If only a subset of these operations is desired, then it is possible to set mutator or recombinator to the respective "null"-operators.

Usage

mies_generate_offspring(
  inst,
  lambda,
  parent_selector = NULL,
  mutator = NULL,
  recombinator = NULL,
  budget_id = NULL
)

Arguments

inst

(OptimInstance)
Optimization instance to evaluate.

lambda

(integer(1))
Number of new individuals to generate. This is not necessarily the number with which parent_selector gets called, because recombinator could in principle need more than lambda input individuals to generate lambda output individuals.

parent_selector

(Selector | NULL)
Selector operator that selects parent individuals depending on configuration values and objective results. When parent_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. When this is NULL (default), then a SelectorBest us used.
The Selector must be primed on a superset of inst$search_space; this includes the "budget" component when performing multi-fidelity optimization. All components on which selector is primed on must occur in the archive.
The given Selector may return duplicates.

mutator

(Mutator | NULL)
Mutator operation to apply to individuals selected out of inst using parent_selector.
The Mutator must be primed on a ParamSet similar to inst$search_space, but without the "budget" component when budget_id is given (multi-fidelity optimization). Such a ParamSet can be generated for example using mies_prime_operators.
When this is NULL (default), then a MutatorNull is used, effectively disabling mutation.

recombinator

(Recombinator | NULL)
Recombinator operation to apply to individuals selected out of int using parent_selector after mutation using mutator. The Recombinator must be primed on a ParamSet similar to inst$search_space, but without the "budget" component when budget_id is given (multi-fidelity optimization). Such a ParamSet can be generated for example using mies_prime_operators.
When this is NULL (default), then a RecombinatorNull is used, effectively disabling recombination.

budget_id

(character(1) | NULL)
Budget compnent when doing multi-fidelity optimization. This component of the search space is removed from individuals sampled from the archive in inst before giving it to mutator and recombinator. Should be NULL when not doing multi-fidelity.

Value

data.table: A table of configurations proposed as offspring to be evaluated using mies_evaluate_offspring().

See Also

Other mies building blocks: mies_evaluate_offspring(), mies_get_fitnesses(), mies_init_population(), mies_select_from_archive(), mies_step_fidelity(), mies_survival_comma(), mies_survival_plus()

Examples

set.seed(1)

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)
)

# Demo operators
m = mut("gauss", sdev = 0.1)
r = rec("xounif")
s = sel("random")
# Operators must be primed
mies_prime_operators(objective$domain, list(m), list(r), list(s))

# We would normally call mies_init_population, but for reproducibility
# we are going to evaluate three given points

oi$eval_batch(data.table::data.table(x = 0:2, y = 2:0, dob = 1, eol = NA_real_))

# Evaluated points:
oi$archive

# Use default operators: no mutation, no recombination, parent_selctor is
# sel("best") --> get one individual, the one with highest performance in the
# archive (x = 1, y = 1).
# (Note 'mies_generate_offspring()' does not modify 'oi')
mies_generate_offspring(oi, lambda = 1)

# Mutate the selected individual after selection. 'm' has 'sdev' set to 0.1,
# so the (x = 1, y = 1) is slightly permuted.
mies_generate_offspring(oi, lambda = 1, mutator = m)

# Recombination, then mutation.
# Even though lambda is 1, there will be two individuals selected with
# sel("best") and recombined, because rec("xounif") needs two parents. One
# of the crossover results is discarded (respecting that 'lambda' is 1),
# the other is mutated and returned.
mies_generate_offspring(oi, lambda = 1, mutator = m, recombinator = r)

# General application: select, recombine, then mutate.
mies_generate_offspring(oi, lambda = 5, parent_selector = s, mutator = m, recombinator = r)


miesmuschel documentation built on Sept. 11, 2024, 8:23 p.m.