Generator for single-objective target functions.

makeSingleObjectiveFunction(
  name = NULL,
  id = NULL,
  description = NULL,
  fn,
  has.simple.signature = TRUE,
  vectorized = FALSE,
  par.set,
  noisy = FALSE,
  fn.mean = NULL,
  minimize = TRUE,
  constraint.fn = NULL,
  tags = character(0),
  global.opt.params = NULL,
  global.opt.value = NULL,
  local.opt.params = NULL,
  local.opt.values = NULL
)

Arguments

name

[character(1)]
Function name. Used for the title of plots for example.

id

[character(1) | NULL]
Optional short function identifier. If provided, this should be a short name without whitespaces and now special characters beside the underscore. Default is NULL, which means no ID at all.

description

[character(1) | NULL]
Optional function description.

fn

[function]
Objective function.

has.simple.signature

[logical(1)]
Set this to TRUE if the objective function expects a vector as input and FALSE if it expects a named list of values. The latter is needed if the function depends on mixed parameters. Default is TRUE.

vectorized

[logical(1)]
Can the objective function handle “vector” input, i.~e., does it accept matrix of parameters? Default is FALSE.

par.set

[ParamSet]
Parameter set describing different aspects of the objective function parameters, i.~e., names, lower and/or upper bounds, types and so on. See makeParamSet for further information.

noisy

[logical(1)]
Is the function noisy? Defaults to FALSE.

fn.mean

[function]
Optional true mean function in case of a noisy objective function. This functions should have the same mean as fn.

minimize

[logical(1)]
Set this to TRUE if the function should be minimized and to FALSE otherwise. The default is TRUE.

constraint.fn

[function | NULL]
Function which returns a logical vector indicating whether certain conditions are met or not. Default is NULL, which means, that there are no constraints beside possible box constraints defined via the par.set argument.

tags

[character]
Optional character vector of tags or keywords which characterize the function, e.~g. “unimodal”, “separable”. See getAvailableTags for a character vector of allowed tags.

global.opt.params

[list | numeric | data.frame | matrix | NULL]
Default is NULL which means unknown. Passing a numeric vector will be the most frequent case (numeric only functions). In this case there is only a single global optimum. If there are multiple global optima, passing a numeric matrix is the best choice. Passing a list or a data.frame is necessary if your function is mixed, e.g., it expects both numeric and discrete parameters. Internally, however, each representation is casted to a data.frame for reasons of consistency.

global.opt.value

[numeric(1) | NULL]
Global optimum value if known. Default is NULL, which means unknown. If only the global.opt.params are passed, the value is computed automatically.

local.opt.params

[list | numeric | data.frame | matrix | NULL]
Default is NULL, which means the function has no local optima or they are unknown. For details see the description of global.opt.params.

local.opt.values

[numeric | NULL]
Value(s) of local optima. Default is NULL, which means unknown. If only the local.opt.params are passed, the values are computed automatically.

Value

[function] Objective function with additional stuff attached as attributes.

Examples

library(ggplot2)

fn = makeSingleObjectiveFunction(
  name = "Sphere Function",
  fn = function(x) sum(x^2),
  par.set = makeNumericParamSet("x", len = 1L, lower = -5L, upper = 5L),
  global.opt.params = list(x = 0)
)
print(fn)
#> Single-objective function
#> Name: Sphere Function
#> Description: no description
#> Tags: 
#> Noisy: FALSE
#> Minimize: TRUE
#> Constraints: TRUE
#> Number of parameters: 1
#>            Type len Def  Constr Req Tunable Trafo
#> x numericvector   1   - -5 to 5   -    TRUE     -
#> Global optimum objective value of 0.0000 at
#>   x
#> 1 0
print(autoplot(fn))


fn.num2 = makeSingleObjectiveFunction(
  name = "Numeric 2D",
  fn = function(x) sum(x^2),
  par.set = makeParamSet(
    makeNumericParam("x1", lower = -5, upper = 5),
    makeNumericParam("x2", lower = -10, upper = 20)
  )
)
print(fn.num2)
#> Single-objective function
#> Name: Numeric 2D
#> Description: no description
#> Tags: 
#> Noisy: FALSE
#> Minimize: TRUE
#> Constraints: TRUE
#> Number of parameters: 2
#>       Type len Def    Constr Req Tunable Trafo
#> x1 numeric   -   -   -5 to 5   -    TRUE     -
#> x2 numeric   -   - -10 to 20   -    TRUE     -
print(autoplot(fn.num2))


fn.mixed = makeSingleObjectiveFunction(
  name = "Mixed 2D",
  fn = function(x) x$num1^2 + as.integer(as.character(x$disc1) == "a"),
  has.simple.signature = FALSE,
  par.set = makeParamSet(
    makeNumericParam("num1", lower = -5, upper = 5),
    makeDiscreteParam("disc1", values = c("a", "b"))
  ),
  global.opt.params = list(num1 = 0, disc1 = "b")
)
print(fn.mixed)
#> Single-objective function
#> Name: Mixed 2D
#> Description: no description
#> Tags: 
#> Noisy: FALSE
#> Minimize: TRUE
#> Constraints: TRUE
#> Number of parameters: 2
#>           Type len Def  Constr Req Tunable Trafo
#> num1   numeric   -   - -5 to 5   -    TRUE     -
#> disc1 discrete   -   -     a,b   -    TRUE     -
#> Global optimum objective value of 0.0000 at
#>   num1 disc1
#> 1    0     b
print(autoplot(fn.mixed))