Join us for
RADAR: AI Edition

adagio (version 0.8.5)

Historize: Historize function

Description

Provides storage for function calls.

Usage

Historize(fun, len = 0, ...)

Value

Returns a function identical to the original function, but the new function will now store its function calls in a vector or matrix.

Arguments

fun

Function of one or several variables.

len

Allowed length of the input variables.

...

Additional parameters to be handed to the function.

Author

Hans W. Borchers

Details

Historize() adds storage to the function. If len=0 then only function values will be stored in a vector, if len>0 then variables and function values will be stored in a matrix, one line for every function call.

If Fn = Historize(...) is the 'historized' function, then the storage can be retrieved with Fn() and can be cleared with Fn(NULL).

Filling the storage will take extra time and can slow down the function calls. Especially also storing the variables used in the call (with len>0) will make it considerably slower.

Functions can have multivariate output; the user is asked to take care of handling the output vector or matrix correctly. The function may even require additional parameters.

See Also

trace

Examples

Run this code
Fn <- Historize(fnRastrigin)
dm <- 10
lb <- rep(-5.2, dm); ub <- -lb

# Fn(NULL)
sol <- simpleDE(Fn, lower = lb, upper = ub)
fvalues <- Fn()
fvals <- cummin(fvalues)

if (FALSE) {
plot(fvalues, type = 'p', col = 7, pch = '.', cex = 2,
     main = "Simple DE optimization", xlab = '', ylab = '')
lines(fvals, col = 2, lwd = 1)
legend(length(fvalues), max(fvalues),
       c("Intermediate values", "cummulated min"),
       xjust = 1, col = c(7, 1), lwd = 2)
grid()}

Run the code above in your browser using DataLab