logger: Function Evaluation Logger

View source: R/logging.R

loggerR Documentation

Function Evaluation Logger

Description

Wraps your objective function, to Log each function evaluation during an optimization experiment.

Usage

logger(fn, id, freq = 1, logx = FALSE, envir = .GlobalEnv)

Arguments

fn

the function to be monitored by the logger (an objective function, following the schema y=f(x)).

id

an ID that will be part of the names of the variables that store the logging information

freq

a positive integer, giving the frequency of the logging: the history of y (and possibly x) values is permanently recorded every freq evaluations. Note: the best observed value is updated in every evaluation, regardless of this value. Default: 1 (every iteration is stored by the logger).

logx

boolean, specifying whether x values will be logged as well (default: FALSE).

envir

the environment in which the logger variables are stored (default: .GlobalEnv)

Value

A function which takes the same arguments as fn, and returns the same values. In addition, it writes some variables to the specified environment.

Examples

lower <- -1
upper <- 3
fun <- function(x)sqrt(abs(x-1))
require(nloptr)
lbfgs(x0=-1,
      fn = logger(fun,"mytest",1),
      lower=lower,
      upper=upper)
## see the logged minimum value:
logger.min.mytest
## plot the progress over time
plot(logger.y.mytest[,c(1,2)])
plot(logger.y.mytest[,c(1,3)])


martinzaefferer/COBBS documentation built on July 19, 2023, 4:12 a.m.