recording_function: Recording functions

Description Usage Arguments See Also Examples

View source: R/recording_function.R

Description

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

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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])

soobench documentation built on Feb. 9, 2020, 5:08 p.m.