Learn R Programming

smoof (version 1.6.0.3)

addLoggingWrapper: Return a function which internally stores x or y values.

Description

Often it is desired and useful to store the optimization path, i.e., the evaluated function values and/or the parameters. Not all optimization algorithms offer such a trace. This wrapper makes a smoof function handle x/y-values itself.

Usage

addLoggingWrapper(fn, logg.x = FALSE, logg.y = TRUE, size = 100L)

Value

[smoof_logging_function]

Arguments

fn

[smoof_function]
Smoof function.

logg.x

[logical(1)]
Should x-values be logged? Default is FALSE.

logg.y

[logical(1)]
Should objective values be logged? Default is TRUE.

size

[integer(1)]
Initial size of the internal data structures used for logging. Default is 100. I.e., there is space reserved for 100 function evaluations. In case of an overflow (i.e., more function evaluations than space reserved) the data structures are re-initialized by adding space for another size evaluations. This comes handy if you know the number of function evaluations (or at least an upper bound thereof) a-priori and may serve to reduce the time complextity of logging values.

Examples

Run this code
# We first build the smoof function and apply the logging wrapper to it
fn = makeSphereFunction(dimensions = 2L)
fn = addLoggingWrapper(fn, logg.x = TRUE)

# We now apply an optimization algorithm to it and the logging wrapper keeps
# track of the evaluated points.
res = optim(fn, par = c(1, 1), method = "Nelder-Mead")

# Extract the logged values
log.res = getLoggedValues(fn)
print(log.res$pars)
print(log.res$obj.vals)
log.res = getLoggedValues(fn, compact = TRUE)
print(log.res)

Run the code above in your browser using DataLab