Skip to contents

This class defines the objective that is used for optimization.

Public fields

id

(`character(1)` The id of the objective.

label

(`character(1)` The label of the objective, i.e. a.

limits_lower

(`numeric()`) The lower limits for each dimension.

limits_upper

(`numeric()`) The upper limits for each dimension.

minimize

(`logical(1)`) Is the problem a minimization problem?

Active bindings

archive

(`data.table()`) Archive of all calls to `$evalStore`.

log_funs

(`list()`) A list containing logging functions. Each function must have argument.

xdim

(`integer(1)`) Input dimension of `f`.

Methods


Method new()

Creates a new instance of this [R6][R6::R6Class] class.

Usage

Objective$new(
  id,
  fun,
  label = "f",
  xdim,
  limits_lower = NA,
  limits_upper = NA,
  xtest = NULL,
  minimize = FALSE,
  ...
)

Arguments

id

(`character(1)` The id of the objective.

fun

(`function` The objective function. The first argument must be a numerical input of length `xdim`.

label

(`character(1)` The label of the objective, i.e. a.

xdim

(`integer(1)`) The input dimension of `fun`. Use `xdim = NA` for an arbitrary input dimension.

limits_lower

(`numeric(xdim)`) The lower boundaries for inputs to `fun`. Must

limits_upper

(`numeric(xdim)`) The upper boundaries for inputs to `fun`. Must be of length `xdim`.

xtest

(`numeric()`) Test value for `fun` during initialization. If not defined, `xtest = rep(0, ifelse(is.na(xdim), 2, xdim))` is used.

minimize

(`logical(1)`) Is the problem a minimization problem? Default is no (`FALSE`).

...

Additional arguments passed to `fun`.


Method eval()

Evaluate the objective function.

Usage

Objective$eval(x)

Arguments

x

(`numeric`) The numerical input of `fun`.

Returns

The result of `fun(x)`.


Method evalStore()

Evaluate the objective function and log into the archive. Each call logs the input vector `x`, result of fun `fval`, the gradient `grad`, the norm of the gradient `gnorm`, and additional logs that were added by `$addLogFun`.

Usage

Objective$evalStore(x)

Arguments

x

(`numeric`) The numerical input of `fun`.

Returns

Invisible list of logs that are added to the archive.


Method assertX()

Assert a numeric input if it is suitable or not.

Usage

Objective$assertX(x, ...)

Arguments

x

(`numeric()`) Input value for `fun`.

...

Additional arguments passed to `checkmate::assertNumeric(...)`.


Method grad()

Evaluate the gradient of the objective function at x.

Usage

Objective$grad(x)

Arguments

x

(`numeric`) The numerical input of `fun`.


Method hess()

Evaluate the hessian of the objective function at x.

Usage

Objective$hess(x)

Arguments

x

(`numeric`) The numerical input of `fun`.

...

Additional arguments passed to `fun`.


Method addLogFun()

Method to add custom logger to the objective.

Usage

Objective$addLogFun(l, label)

Arguments

l

(`function`) Function that returns a single numerical value or a string. The arguments of `l` must be `x`, `fval` and `grad`.

label

(`character(1)`) The name of the logger.

...

Additional arguments passed to `fun`.


Method clearArchive()

Delete the archive.

Usage

Objective$clearArchive()


Method clone()

The objects of this class are cloneable with this method.

Usage

Objective$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.