| mies_aggregate_single_generation {miesmuschel} | R Documentation | 
Aggregate a Value for a given Generation
Description
Applies a fitness_aggregator function to the values that were alive in the archive at a given generation.
The function is supplied with the fitness values, and optionally other data, of all individuals that are alive at that point.
Usage
mies_aggregate_single_generation(
  archive,
  fitness_aggregator,
  generation = NA,
  include_previous_generations = FALSE
)
Arguments
archive | 
 (  | 
fitness_aggregator | 
 (  | 
generation | 
 (  | 
include_previous_generations | 
 (  | 
Details
The fitness_aggregator function may have any of the following arguments, which will be given the following information when
fitness_aggregator is called:
-  
fitnesses::matrix
Will contain fitnesses for each alive individual. This value has one column when doing single-crit optimization and one column for each "criterion" when doing multi-crit optimization. Fitnesses are always being maximized, so if an objective is being minimized, thefitness_aggregatorfunction is given the objective values * -1. -  
objectives_unscaled::matrix
The objective values as given tofitnesses, but not multiplied by -1 if they are being minimized. It is recommended that thecodomainargument is queried for"maximize"or"minimize"tags whenobjectives_unscaledis used. -  
budget::scalar
If multi-fidelity evaluation is being performed, then this is the "budget" value of each individual. Otherwise it is a vector containing the value 1 for each individual. -  
xdt::data.table
The configurations that were evaluated for the alive individuals. Rows are in the same order as the values given tofitnessesorobjectives_unscaled. -  
search_space::ParamSet
The search space of theArchiveunder evaluation. -  
codomain::ParamSet
The codomain of theArchiveunder evaluation. This is particularly useful when usingobjectives_unscaledto determine minimization or maximization. 
Not all of these arguments need to present, but at least one of fitnesses, objectives_unscaled, or xdt must be.
fitness_aggregator will never be called for an empty generation.
Value
The value returned by fitness_aggregator when applied to individuals alive at generation generation. If no
individuals of the requested generation are present, fitness_aggregator is not called
and mies_aggregate_single_generation() returns NULL instead.
See Also
Other aggregation methods: 
mies_aggregate_generations(),
mies_get_generation_results()
Examples
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("none"))
try(mies_aggregate_single_generation(oi$archive, identity), silent = TRUE)
mies_aggregate_single_generation(oi$archive, function(fitnesses) fitnesses)
mies_init_population(oi, 2, budget_id = "x1", fidelity = .5)
oi$archive$data
mies_aggregate_single_generation(oi$archive, function(fitnesses) fitnesses)
# Notice how fitnesses are positive, since x2 is scaled with -1.
# To get the original objective-values, use objectives_unscaled:
mies_aggregate_single_generation(oi$archive,
  function(objectives_unscaled) objectives_unscaled)
# When `...` is used, all information is passed:
mies_aggregate_single_generation(oi$archive, function(...) names(list(...)))
# Generation 10 is not present, but individuals with eol `NA` are still
# considered alive:
mies_aggregate_single_generation(oi$archive, function(fitnesses) fitnesses,
  generation = 10)
# Re-evaluating points with higher "fidelity" (x1)
mies_step_fidelity(oi, budget_id = "x1", fidelity = 0.7)
oi$archive$data
# Lower-fidelity values are considered dead now, even for generation 1:
mies_aggregate_single_generation(oi$archive, function(fitnesses) fitnesses,
  generation = 1)
# This adds two new alive individuals at generation 2.
# Also the individuals from gen 1 are reevaluated with fidelity 0.8
mies_evaluate_offspring(oi, offspring = data.frame(x2 = c(-0.1, -0.2)),
  budget_id = "x1", fidelity = 0.9, reevaluate_fidelity = 0.8)
oi$archive$data
mies_aggregate_single_generation(oi$archive, function(budget, ...) budget)
mies_aggregate_single_generation(oi$archive, function(fitnesses) fitnesses,
  generation = 1)
mies_aggregate_single_generation(oi$archive, function(fitnesses) fitnesses,
  generation = 2)
# No individuals were killed, but some were fidelity-reevaluated.
# These are not present with include_previous_generations:
mies_aggregate_single_generation(oi$archive, function(fitnesses) fitnesses,
  generation = 2, include_previous_generations = TRUE)
# Typical use-case: get dominated hypervolume
mies_aggregate_single_generation(oi$archive, function(fitnesses) domhv(fitnesses))
# Get generation-wise mean fitness values
mies_aggregate_single_generation(oi$archive, function(fitnesses) {
  apply(fitnesses, 2, mean)
})