Learn R Programming

soobench (version 1.9.18)

recording_function: Recording functions

Description

Return a new function which is identical to the soofunction passed in except that evaluated parameter settings and function values are recorded.

Usage

recording_function(fn, record_pars = TRUE, record_values = TRUE, predicate)

Arguments

fn

A test function (class soo_function or wrapped_soo_function).

record_pars

[boolean(1)] If TRUE, parameter values (x) will be recorded.

record_values

[boolean(1)] If TRUE, function values (y) will be recorded.

predicate

[function(par, value, time)] Predicate function that returns TRUE if recording should take place for the given parameter setting par, function value value and evaluation time. Note that time is measured in function evaluations.

See Also

recorded_values to retrieve the recorded parameter and function values.

Examples

Run this code
# NOT RUN {
fn <- recording_function(generate_sphere_function(2))
X <- random_parameters(10, fn)
y <- fn(X)
rv <- recorded_values(fn)
all.equal(rv$par, X)
all.equal(rv$value, y)

## With a predicate
pv <- function(par, value, time)
  time %% 3 == 0
fn <- recording_function(generate_sphere_function(2), predicate=pv)
X <- random_parameters(10, fn)
y <- fn(X)
rv <- recorded_values(fn)
all(rv$time %% 3 == 0)
all.equal(rv$par, X[, rv$time])
all.equal(rv$value, y[rv$time])

# }

Run the code above in your browser using DataLab