snof: Helper function to create numeric single-objective...

View source: R/snof.R

snofR Documentation

Helper function to create numeric single-objective optimization test function.

Description

This is a simplifying wrapper around makeSingleObjectiveFunction. It can be used if the function to generte is purely numeric to save some lines of code.

Usage

snof(
  name = NULL,
  id = NULL,
  par.len = NULL,
  par.id = "x",
  par.lower = NULL,
  par.upper = NULL,
  description = NULL,
  fn,
  vectorized = FALSE,
  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.

par.len

[integer(1)]
Length of parameter vector.

par.id

[character(1)]
Optional name of parameter vector. Default is “x”.

par.lower

[numeric]
Vector of lower bounds. A single value of length 1 is automatically replicated to n.pars. Default is -Inf.

par.upper

[numeric]
Vector of upper bounds. A singe value of length 1 is automatically replicated to n.pars. Default is Inf.

description

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

fn

[function]
Objective function.

vectorized

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

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.

Examples

# first we generate the 10d sphere function the long way
fn = makeSingleObjectiveFunction(
  name = "Testfun",
  fn = function(x) sum(x^2),
  par.set = makeNumericParamSet(
    len = 10L, id = "a",
    lower = rep(-1.5, 10L), upper = rep(1.5, 10L)
  )
)

# ... and now the short way
fn = snof(
 name = "Testfun",
 fn = function(x) sum(x^2),
 par.len = 10L, par.id = "a", par.lower = -1.5, par.upper = 1.5
)

smoof documentation built on March 31, 2023, 11:48 p.m.