mies_select_from_archive {miesmuschel}R Documentation

Select Individuals from an OptimInstance

Description

Apply a Selector operator to a subset of configurations inside an OptimInstance and return the index within the archive (when get_indivs FALSE) or the configurations themselves (when get_indivs is TRUE).

It is not strictly necessary for the selector to select unique individuals / individuals without replacement.

Individuals are selected independently of whether they are "alive" or not. To select only from alive individuals, set rows to inst$archive$data[, which(is.na(eol))].

Usage

mies_select_from_archive(
  inst,
  n_select,
  rows,
  selector = SelectorBest$new()$prime(inst$search_space),
  group_size = 1,
  get_indivs = TRUE
)

Arguments

inst

(OptimInstance)
Optimization instance to evaluate.

n_select

(integer(1))
Number of individuals to select.

rows

optional (integer)
Indices of rows within inst to consider. If this is not given, then the entire archive is used.

selector

(Selector)
Selector operator that selects individuals depending on configuration values and objective results. When 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. Defaults to SelectorBest.
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.

group_size

(integer)
Sampling group size hint, indicating that the caller would prefer there to not be any duplicates within this group size. The Selector may or may not ignore this value, however. This may possibly happen because of certain configuration parameters, or because the input size is too small.
Must either be a scalar value or sum up to n_select. Must be non-negative. A scalar value of 0 is interpreted the same as 1.
Default is 1.

get_indivs

(logical(1))
Whether to return configuration values from within the archive (TRUE) or just the indices within the archive (FALSE). Default is TRUE.

Value

integer | data.table: Selected individuals, either index into inst or subset of archive table, depending on get_indivs.

See Also

Other mies building blocks: mies_evaluate_offspring(), mies_generate_offspring(), mies_get_fitnesses(), mies_init_population(), 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)
)

s = sel("best")
s$prime(oi$search_space)

mies_init_population(inst = oi, mu = 6)

oi$archive

# Default: get individuals
mies_select_from_archive(oi, n_select = 2, rows = 1:6, selector = s)

# Alternatively: get rows within archive
mies_select_from_archive(oi, n_select = 2, rows = 1:6, selector = s,
  get_indivs = FALSE)

# Rows gotten from archive are relative from *all* rows, not from archive[rows]:
mies_select_from_archive(oi, n_select = 2, rows = 3:6, selector = s,
  get_indivs = FALSE)

##
# When using additional components: mies_select_from_archive learns about
# additional components from primed selector.

# Get a new OptimInstance
oi <- OptimInstanceSingleCrit$new(objective,
  terminator = trm("evals", n_evals = 100)
)

mies_init_population(inst = oi, mu = 6,
  additional_component_sampler = Sampler1DRfun$new(
    param = ParamDbl$new("additional", -1, 1), rfun = function(n) -1
  )
)

oi$archive

# Wrong: using selector primed only on search space. The resulting
# individuals do not have the additional component.
mies_select_from_archive(oi, n_select = 2, rows = 1:6, selector = s)

# Correct: selector must be primed on search space + additional component
mies_prime_operators(oi$search_space, selectors = list(s),
  additional_components = ps(additional = p_dbl(-1, 1)))

mies_select_from_archive(oi, n_select = 2, rows = 1:6, selector = s)

[Package miesmuschel version 0.0.3 Index]