mies_generation_apply {miesmuschel} | R Documentation |
Aggregate Values for All Generations Present
Description
Applies a fitness_aggregator
function to the values that were alive in the archive at at any generation.
mies_aggregate_single_generation()
is used, see there for more information about fitness_aggregator
.
Generations for which fitness_aggregator
returns NULL
, or which are not present in any dob
in the archive,
or which contain no alive individuals (e.g. because eol
is smaller or equal dob
for all of them) are ignored.
as.list()
is applied to the values returned by fitness_aggregator
, and data.table::rbindlist()
is called on
the list of resulting values. If the first non-NULL
-value returned by fitness_aggregator
, then data.table::rbindlist()
is called with fill = TRUE
and use.names = TRUE
.
If no non-empty generations are present, or fitness_aggregator
returns NULL
on every call, then the return value
is data.table(dob = numeric(0))
.
In contrast with mies_aggregate_generations()
, mies_generate_apply()
can construct aggregated values for
entire fitness matrices, not only individual objectives (see examples). However, mies_aggregate_generations()
is simpler
if per-objective aggregates are desired.
Usage
mies_generation_apply(
archive,
fitness_aggregator,
include_previous_generations = FALSE
)
Arguments
archive |
( |
fitness_aggregator |
( |
include_previous_generations |
( |
Value
data.table
with columns dob
, next to the columns constructed from the return values of fitness_aggregator
.
Examples
set.seed(1)
library("bbotk")
lgr::threshold("warn")
objective <- ObjectiveRFun$new(
fun = function(xs) {
list(y1 = xs$x1, y2 = xs$x2)
},
domain = ps(x1 = p_dbl(0, 1), x2 = p_dbl(-1, 0)),
codomain = ps(y1 = p_dbl(0, 1, tags = "maximize"),
y2 = p_dbl(-1, 0, tags = "minimize"))
)
oi <- OptimInstanceMultiCrit$new(objective,
terminator = trm("evals", n_evals = 40))
op <- opt("mies",
lambda = 4, mu = 4,
mutator = mut("gauss", sdev = 0.1),
recombinator = rec("xounif"),
parent_selector = sel("random"),
survival_selector = sel("best", scl("hypervolume"))
)
op$optimize(oi)
# Aggregated hypervolume of individuals alive in each gen:
mies_generation_apply(oi$archive, function(fitnesses) {
domhv(fitnesses)
})
# Aggregated hypervolume of all points evaluated up to each gen
# (may be slightly more, since the domhv of more points is evaluated).
# This would be the dominated hypervolume of the result set at each
# generation:
mies_generation_apply(oi$archive, function(fitnesses) {
domhv(fitnesses)
}, include_previous_generations = TRUE)
# The following are simpler with mies_aggregate_single_generations():
mies_generation_apply(oi$archive, function(fitnesses) {
apply(fitnesses, 2, mean)
})
# Compare:
mies_aggregate_generations(oi, aggregations = list(mean = mean))
mies_generation_apply(oi$archive, function(objectives_unscaled) {
apply(objectives_unscaled, 2, mean)
})
# Compare:
mies_aggregate_generations(oi, aggregations = list(mean = mean),
as_fitnesses = FALSE)