Calls $eval_batch of a given OptimInstance on a set of configurations as part of a MIES operation. The dob extra-info in the archive is also set properly to indicate a progressed generation.

This function can be used directly, but it is easier to use it within the OptimizerMies Optimizer if standard GA operation is desired.

Multifidelity evaluation is supported as described in vignette("mies-multifid"). For this, an extra component named after budget_id is appended to each individual, chosen from the fidelity argument and depending on the value of survivor_budget. budget_id should have the same values as given to the other mies_* functions.

mies_evaluate_offspring(
  inst,
  offspring,
  budget_id = NULL,
  fidelity = NULL,
  reevaluate_fidelity = NULL,
  fidelity_monotonic = TRUE
)

Arguments

inst

(OptimInstance)
Optimization instance to evaluate.

offspring

(data.frame)
Proposed configurations to be evaluated, must have columns named after the inst's search space, minus budget_id if not NULL.

budget_id

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

fidelity

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

reevaluate_fidelity

(atomic(1))
Fidelity with which to evaluate alive individuals from previous generations that have a budget value below (if fidelity_monotonic is TRUE) or different from the current fidelity value. Default NULL: Do not re-evaluate. Must be NULL when budget_id and fidelity are NULL. See also mies_step_fidelity.

fidelity_monotonic

(logical(1))
When reevaluate_fidelity is non-NULL, then this indicates whether individuals should only ever be re-evaluated when fidelity would be increased. Default TRUE. Ignored when reevaluate_fidelity is NULL

Value

invisible

data.table: the performance values returned when evaluating the offspring values through eval_batch.

Examples

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)
# Initial state:
oi$archive
#> <Archive>
#>        x       y   dob   eol  x_id   Obj           timestamp batch_nr
#>    <num>   <num> <num> <num> <num> <num>              <POSc>    <int>
#> 1:  3.48 -0.0056     1    NA     1 0.004 2024-05-13 04:41:05        1
#> 2: -0.24  1.9052     1    NA     2 0.038 2024-05-13 04:41:05        1
#> 3:  0.75 -0.4519     1    NA     3 0.463 2024-05-13 04:41:05        1

# 'offspring' is just a data.frame of values to evaluate.
# In general it should be created using 'mies_generate_offspring()'.
offspring = data.frame(x = 1:2, y = 2:1)

mies_evaluate_offspring(oi, offspring = offspring)

# This evaluated the given points and assigned them 'dob' 2.
oi$archive
#> <Archive>
#>        x       y   dob   eol  x_id   Obj           timestamp batch_nr
#>    <num>   <num> <num> <num> <num> <num>              <POSc>    <int>
#> 1:  3.48 -0.0056     1    NA     1 0.004 2024-05-13 04:41:05        1
#> 2: -0.24  1.9052     1    NA     2 0.038 2024-05-13 04:41:05        1
#> 3:  0.75 -0.4519     1    NA     3 0.463 2024-05-13 04:41:05        1
#> 4:  1.00  2.0000     2    NA     4 0.742 2024-05-13 04:41:05        2
#> 5:  2.00  1.0000     2    NA     5 0.742 2024-05-13 04:41:05        2

# Note that at this point one would ordinarily call a 'mies_survival_*()'
# function.

###
# Advanced demo, making use of additional components and doing multi-fidelity
##

# declare 'y' the budget parameter. It will not be in the 'offspring'
# table any more.
budget_id = "y"
# but: offspring may contain any other value that is appended to 'oi'. These
# are ignored by the objective.
offspring = data.frame(x = 0:1, z = 3)

mies_evaluate_offspring(oi, offspring = offspring, budget_id = budget_id,
  fidelity = 1)

# This now has the additional column 'z'. Values of y for the new evaluations
# are 1.
oi$archive
#> <Archive>
#>        x       y   dob   eol  x_id   Obj           timestamp batch_nr     z
#>    <num>   <num> <num> <num> <num> <num>              <POSc>    <int> <num>
#> 1:  3.48 -0.0056     1    NA     1 0.004 2024-05-13 04:41:05        1    NA
#> 2: -0.24  1.9052     1    NA     2 0.038 2024-05-13 04:41:05        1    NA
#> 3:  0.75 -0.4519     1    NA     3 0.463 2024-05-13 04:41:05        1    NA
#> 4:  1.00  2.0000     2    NA     4 0.742 2024-05-13 04:41:05        2    NA
#> 5:  2.00  1.0000     2    NA     5 0.742 2024-05-13 04:41:05        2    NA
#> 6:  0.00  1.0000     3    NA     6 0.381 2024-05-13 04:41:05        3     3
#> 7:  1.00  1.0000     3    NA     7 0.406 2024-05-13 04:41:05        3     3

offspring = data.frame(x = 2, z = 3)
# Increasing the fidelity will not cause re-evaluation of existing individuals
# when `reevaluate_fidelity` is not given.
mies_evaluate_offspring(oi, offspring = offspring, budget_id = budget_id,
  fidelity = 2)
oi$archive
#> <Archive>
#>        x       y   dob   eol  x_id   Obj           timestamp batch_nr     z
#>    <num>   <num> <num> <num> <num> <num>              <POSc>    <int> <num>
#> 1:  3.48 -0.0056     1    NA     1 0.004 2024-05-13 04:41:05        1    NA
#> 2: -0.24  1.9052     1    NA     2 0.038 2024-05-13 04:41:05        1    NA
#> 3:  0.75 -0.4519     1    NA     3 0.463 2024-05-13 04:41:05        1    NA
#> 4:  1.00  2.0000     2    NA     4 0.742 2024-05-13 04:41:05        2    NA
#> 5:  2.00  1.0000     2    NA     5 0.742 2024-05-13 04:41:05        2    NA
#> 6:  0.00  1.0000     3    NA     6 0.381 2024-05-13 04:41:05        3     3
#> 7:  1.00  1.0000     3    NA     7 0.406 2024-05-13 04:41:05        3     3
#> 8:  2.00  2.0000     4    NA     8 2.000 2024-05-13 04:41:05        4     3

offspring = data.frame(x = 3, z = 3)
# Depending on the effect of fidelity, this may however have a biasing effect,
# so it may be desirable to re-evaluate surviving individuals from previous
# generations. The 'reevaluate_fidelity' may even be different from 'fidelity'
mies_evaluate_offspring(oi, offspring = offspring, budget_id = budget_id,
  fidelity = 3, reevaluate_fidelity = 2)

# In this example, only individuals with 'y = 1' were re-evaluated, since
# 'fidelity_monotonic' is TRUE.
oi$archive
#> <Archive>
#>         x       y   dob   eol  x_id   Obj           timestamp batch_nr     z
#>     <num>   <num> <num> <num> <num> <num>              <POSc>    <int> <num>
#>  1:  3.48 -0.0056     1     5     1 0.004 2024-05-13 04:41:05        1    NA
#>  2: -0.24  1.9052     1     5     2 0.038 2024-05-13 04:41:05        1    NA
#>  3:  0.75 -0.4519     1     5     3 0.463 2024-05-13 04:41:05        1    NA
#>  4:  1.00  2.0000     2    NA     4 0.742 2024-05-13 04:41:05        2    NA
#>  5:  2.00  1.0000     2     5     5 0.742 2024-05-13 04:41:05        2    NA
#>  6:  0.00  1.0000     3     5     6 0.381 2024-05-13 04:41:05        3     3
#>  7:  1.00  1.0000     3     5     7 0.406 2024-05-13 04:41:05        3     3
#>  8:  2.00  2.0000     4    NA     8 2.000 2024-05-13 04:41:05        4     3
#>  9:  3.00  3.0000     5    NA     9 0.271 2024-05-13 04:41:05        5     3
#> 10:  3.48  2.0000     5    NA     1 0.226 2024-05-13 04:41:05        5    NA
#> 11: -0.24  2.0000     5    NA     2 0.031 2024-05-13 04:41:05        5    NA
#> 12:  0.75  2.0000     5    NA     3 0.434 2024-05-13 04:41:05        5    NA
#> 13:  2.00  2.0000     5    NA     5 2.000 2024-05-13 04:41:05        5    NA
#> 14:  0.00  2.0000     5    NA     6 0.055 2024-05-13 04:41:05        5     3
#> 15:  1.00  2.0000     5    NA     7 0.742 2024-05-13 04:41:05        5     3