Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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)

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.

Value

[smoof_logging_function]

Note

Logging values, in particular logging x-values, will substantially slow down the evaluation of the function.

Examples

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

smoof

Single and Multi-Objective Optimization Test Functions

v1.6.0.2
BSD_2_clause + file LICENSE
Authors
Jakob Bossek [aut, cre], Pascal Kerschke [ctb]
Initial release
2020-02-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.