R: Objective interface with custom R function

ObjectiveRFun {bbotk} | R Documentation

## Objective interface with custom R function

### Description

Objective interface where the user can pass a custom R function that expects a list as input.

### Super class

`bbotk::Objective` -> `ObjectiveRFun`

### Active bindings

`fun`

  (`function`)
  Objective function.

### Methods

#### Public methods

- `ObjectiveRFun$new()`

- `ObjectiveRFun$eval()`

- `ObjectiveRFun$clone()`

Inherited methods

- `bbotk::Objective$eval_dt()`

- `bbotk::Objective$eval_many()`

- `bbotk::Objective$format()`

- `bbotk::Objective$print()`

#### Method `new()`

Creates a new instance of this R6 class.

##### Usage

    ObjectiveRFun$new(
      fun,
      domain,
      codomain = NULL,
      id = "function",
      properties = character(),
      constants = ParamSet$new(),
      check_values = TRUE
    )

##### Arguments

`fun`

  (`function`)
  R function that encodes objective and expects a list with the input for a single point (e.g. `list(x1 = 1, x2 = 2)`) and returns the result either as a numeric vector or a list (e.g. `list(y = 3)`).

`domain`

  (paradox::ParamSet)
  Specifies domain of function. The paradox::ParamSet should describe all possible input parameters of the objective function. This includes their `id`, 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()`

Evaluates input value(s) on the objective function. Calls the R function supplied by the user.

##### Usage

    ObjectiveRFun$eval(xs)

##### Arguments

`xs`

  Input values.

#### Method `clone()`

The objects of this class are cloneable with this method.

##### Usage

    ObjectiveRFun$clone(deep = FALSE)

##### Arguments

`deep`

  Whether to make a deep clone.

### Examples

    library(paradox)
    # Define objective function
    fun = function(xs) {
      - (xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10
    }

    # Set domain
    domain = ParamSet$new(list(
      ParamDbl$new("x1", -10, 10),
      ParamDbl$new("x2", -5, 5)
    ))

    # Set codomain
    codomain = ParamSet$new(list(
      ParamDbl$new("y", tags = "maximize")
    ))

    # Create Objective object
    obfun = ObjectiveRFun$new(
      fun = fun,
      domain = domain,
      codomain = codomain,
      properties = "deterministic"
    )

[Package bbotk version 0.3.1 Index]