Learn R Programming

soobench (version 1.9.18)

with_fixed_budget: Fixed budget expression evaluation

Evaluate expr with a fixed budget for the number of times any test function in expr may be evaluated.

Description

Fixed budget expression evaluation

Evaluate expr with a fixed budget for the number of times any test function in expr may be evaluated.

Usage

with_fixed_budget(expr, budget)

Arguments

expr

[expression] Expression to evaluate

budget

[integer(1)] Maximum number of test function evaluations that may be performed by expr.

Value

A list with elements ‘par’, ‘value’ and ‘counts’ with contents that are identical to the return value of optim

Details

The main use of this function is in benchmarking (optimization) algorithms. It ensures that the algorithm does not perform more than budget function evaluations by tracking the number of evaluations performed and raising a condition if the budget is reached. For this to work, the function must find one and only one soofunction object in expr which will be replaced by a modified test function that performs the tracking and signaling.

While elegant from a users perspective, this function is not fool proof. It is possible to construct situations were it will fail. For example, if the employed optimization algorithm is written in C and does not use the memory allocation routines provided by R, then this will certainly lead to memory leaks. You have been warned.

Examples

Run this code
# NOT RUN {
fn <- generate_sphere_function(10)
res <- with_fixed_budget(optim(random_parameter(fn), fn), 25)
print(res)

# }

Run the code above in your browser using DataLab