loggedExperiment: Logged Experimental Runs

View source: R/logging.R

loggedExperimentR Documentation

Logged Experimental Runs

Description

This function performs optimization experiments (described by the expression expr), where the objective function evaluations are logged as prescribed by the given arguments.

Usage

loggedExperiment(expr, fun, seeds, freq = 1, logx = FALSE)

Arguments

expr

this R expression will be run (with eval), to perform a single optimization experiment. Importantly, the expression should contain a call to a solver, which includes as an argument the objective function, with the exact name fnlog. This function will be wrapped by logger. See the examples.

fun

the actual objective function (class(fun) = function).

seeds

the random number seeds to be set before each experiment. expr will be called as often as length(seeds). Each call is preceded by a call to set.seed, with the respective element of this vector.

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).

Value

a data.frame containing the logged results: column 'it' gives iteration numbers, 'y' gives observations, 'cy' is the cumulated minimum of the observations over iterations, and 'seed' gives the rng seed of the corresponding experiment.

Examples

lower <- -1
upper <- 1
require(nloptr)
expr <- expression(
  res <- lbfgs(x0=runif(1,lower,upper),
               fn = fnlog, #important: use this same variable name 'fnlog'
               lower=lower,upper=upper)
)
res <- loggedExperiment(expr, function(x)sqrt(abs(x)), 1:20)
plot(res[,c(1,3)],col=res$seed)


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