Learn R Programming

svcm (version 0.1.2)

cleversearch: Optimization over a parameter grid

Description

This function allows greedy/full grid search in any dimension.

Usage

cleversearch(fn, lower, upper, ngrid, startvalue, logscale = TRUE, clever = TRUE, verbose = FALSE)

Arguments

fn
a function to be minimized (or maximized), with the only argument being the parameter over which minimization is to take place. The return value must be scalar.
lower
numeric vector containing the lower bounds on the parameter grid
upper
numeric vector containing the upper bounds on the parameter grid
ngrid
integer number determining the grid length in every dimension
startvalue
optional initial value for the parameter to be optimized over
logscale
logical, whether to construct the grid on logarithmic scale
clever
logical, whether to perform a greedy grid search with lookup-table or a full grid evaluation. The latter is only available up to 3d.
verbose
logical. Should the search process be monitored?

Value

A list with components
par
optimal parameter value that was found.
value
fn value corresponding to par.
counts
number of calls to 'fn'.

Details

Unless startvalue is specified, the search starts at the lower bound of the 1d parameter space or at the middle of the 2d/3d grid.

See Also

optim

Examples

Run this code
simplefun <- function(vec) { return(sum(vec^2)) }
opt <- cleversearch(simplefun, c(-1, -1), c(1, 1), 51, logscale=FALSE)

Run the code above in your browser using DataLab