mies_get_fitnesses {miesmuschel} | R Documentation |
Get Fitness Values from OptimInstance
Description
Get fitness values in the correct form as used by Selector
operators from an
OptimInstance
.
This works for both single-criterion and multi-criterion optimization, and entails multiplying
objectives with -1 if they are being minimized, since Selector
tries to maximize fitness.
Usage
mies_get_fitnesses(inst, rows)
Arguments
inst |
( |
rows |
optional ( |
Value
numeric
matrix
with length(rows)
(if rows
is given, otherwise nrow(inst$archive$data)
) rows
and one column for each objective: fitnesses to be maximized.
See Also
Other mies building blocks:
mies_evaluate_offspring()
,
mies_generate_offspring()
,
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)
)
mies_init_population(inst = oi, mu = 3)
oi$archive
mies_get_fitnesses(oi, c(2, 3))
###
# Multi-objective, and automatic maximization:
objective2 <- ObjectiveRFun$new(
fun = function(xs) list(Obj1 = xs$x^2, Obj2 = -xs$y^2),
domain = ps(x = p_dbl(-2, 4), y = p_dbl(-2, 4)),
codomain = ps(
Obj1 = p_dbl(tags = "minimize"),
Obj2 = p_dbl(tags = "maximize")
)
)
# Using MultiCrit!
oi <- OptimInstanceMultiCrit$new(objective2,
terminator = trm("evals", n_evals = 100)
)
mies_init_population(inst = oi, mu = 3)
oi$archive
# Note Obj1 has a different sign than in the archive.
mies_get_fitnesses(oi, c(2, 3))