Learn R Programming

vws (version 0.3.0)

optimize_hybrid: Hybrid Univariate Optimization

Description

Use Brent's method if a bounded search interval is specified. Otherwise use BFGS method.

Usage

optimize_hybrid(f, init, lower, upper, maximize = FALSE, maxiter = 10000L)

Value

A list with the following elements.

par

Value of optimization variable.

value

Value of optimization function.

method

Description of result.

status

Status code from BFGS or 0 otherwise.

Arguments

f

Objective function. Should take a scalar as an argument.

init

Initial value for optimization variable.

lower

Lower bound for search; may be \(-\infty\).

upper

Upper bound for search; may be \(+\infty\).

maximize

logical; if TRUE, optimization will be a maximization. Otherwise, it will be a minimization.

maxiter

Maximum number of iterations.

Examples

Run this code
f = function(x) { x^2 }
optimize_hybrid(f, init = 0, lower = -1, upper = 2, maximize = FALSE)
optimize_hybrid(f, init = 0, lower = -1, upper = Inf, maximize = FALSE)
optimize_hybrid(f, init = 0, lower = -Inf, upper = 1, maximize = FALSE)
optimize_hybrid(f, init = 0, lower = 0, upper = Inf, maximize = FALSE)
optimize_hybrid(f, init = 0, lower = -Inf, upper = 0, maximize = FALSE)

f = function(x) { 1 - x^2 }
optimize_hybrid(f, init = 0, lower = -1, upper = 1, maximize = TRUE)
optimize_hybrid(f, init = 0, lower = -1, upper = 0, maximize = TRUE)
optimize_hybrid(f, init = 0, lower = 0, upper = 1, maximize = TRUE)

Run the code above in your browser using DataLab