twBinOptimizeFun: twBinOptimizeFun

Description Usage Arguments Details Value Author(s) See Also

View source: R/binOptimize.R

Description

Optimizing a function where first argument is an index.

Usage

1
2
twBinOptimizeFun(x, target = 0, ..., interval, lower = ceiling(min(interval)), 
    upper = floor(max(interval)), maxiter = 100, showiter = FALSE)

Arguments

x

the monotonic vectorized function to be optimized. The term abs(x(i,...)-target) is minimized.

target

Target value for x. Defaults to 0.

...

additional named or unnamed arguments to be passed to f.

interval

a vector containing the end-points of the interval to be searched for target.

lower

the lower end point of the interval to be searched.

upper

the upper end point of the interval to be searched.

maxiter

Maximum number of search iterations. Defaults to 100.

showiter

Boolean flag indicating whether the algorithm state should be printed at each iteration. Defaults to FALSE.

Details

This function can be applied similar to optimize for cases, where the argument to be optimized is an index instead of a continuous variable. A binary search over the index is performed.

The function x must be monotonic. If it is not strictly monotonic the returned index ($where) can be any of the indices with equal values.

The code is based on binsearch of the gtools package. In difference to the original code, it returns always only one best estimate.

Value

A list containing:

call

How the function was called.

numiter

The number of iterations performed

flag

One of the strings, "Found", "Between Elements", "Maximum number of iterations reached", "Reached lower boundary", or "Reached upper boundary."

where

One or two values indicating where the search terminated.

value

Value of the function x at the values of where.

Author(s)

Thomas Wutzler

See Also

twMisc


twMisc documentation built on May 2, 2019, 6:11 p.m.