Objective interface where the user can pass a custom R function that expects a list of configurations as input. If the return of the function is unnamed, it is named with the ids of the codomain.
Super class
bbotk::Objective
-> ObjectiveRFunMany
Methods
Method new()
Creates a new instance of this R6 class.
Usage
ObjectiveRFunMany$new(
fun,
domain,
codomain = NULL,
id = "function",
properties = character(),
constants = ps(),
check_values = TRUE
)
Arguments
fun
(
function
)
R function that encodes objective and expects a list of lists that contains multiple x values, e.g.list(list(x1 = 1, x2 = 2), list(x1 = 3, x2 = 4))
. The function must return adata.table::data.table()
that contains one y-column for single-criteria functions and multiple y-columns for multi-criteria functions, e.g.data.table(y = 1:2)
ordata.table(y1 = 1:2, y2 = 3:4)
.domain
(paradox::ParamSet)
Specifies domain of function. The paradox::ParamSet should describe all possible input parameters of the objective function. This includes theirid
, their types and the possible range.codomain
(paradox::ParamSet)
Specifies codomain of function. Most importantly the tags of each output "Parameter" define whether it should be minimized or maximized. The default is to minimize each component.id
(
character(1)
).properties
(
character()
).constants
(paradox::ParamSet)
Changeable constants or parameters that are not subject to tuning can be stored and accessed here.check_values
(
logical(1)
)
Should points before the evaluation and the results be checked for validity?
Method eval_many()
Evaluates input value(s) on the objective function. Calls the R function supplied by the user.
Arguments
xss
(
list()
)
A list of lists that contains multiple x values, e.g.list(list(x1 = 1, x2 = 2), list(x1 = 3, x2 = 4))
.
Returns
data.table::data.table()
that contains one y-column for single-criteria functions and multiple y-columns for multi-criteria functions, e.g. data.table(y = 1:2)
or data.table(y1 = 1:2, y2 = 3:4)
.
It may also contain additional columns that will be stored in the archive if called through the OptimInstance.
These extra columns are referred to as extras.
Examples
# define objective function
fun = function(xss) {
res = lapply(xss, function(xs) -(xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10)
data.table(y = as.numeric(res))
}
# set domain
domain = ps(
x1 = p_dbl(-10, 10),
x2 = p_dbl(-5, 5)
)
# set codomain
codomain = ps(y = p_dbl(tags = "maximize"))
# create Objective object
obfun = ObjectiveRFunMany$new(
fun = fun,
domain = domain,
codomain = codomain,
properties = "deterministic"
)