Learn R Programming

mize (version 0.2.4)

mize_init: Initialize the Optimizer.

Description

Prepares the optimizer for use with a specific function and starting point.

Usage

mize_init(
  opt,
  par,
  fg,
  max_iter = Inf,
  max_fn = Inf,
  max_gr = Inf,
  max_fg = Inf,
  abs_tol = NULL,
  rel_tol = abs_tol,
  grad_tol = NULL,
  ginf_tol = NULL,
  step_tol = NULL
)

Arguments

opt

Optimizer, created by make_mize.

par

Vector of initial values for the function to be optimized over.

fg

Function and gradient list. See the documentation of mize.

max_iter

(Optional). Maximum number of iterations. See the 'Convergence' section of mize for details.

max_fn

(Optional). Maximum number of function evaluations. See the 'Convergence' section of mize for details.

max_gr

(Optional). Maximum number of gradient evaluations. See the 'Convergence' section of mize for details.

max_fg

(Optional). Maximum number of function or gradient evaluations. See the 'Convergence' section of mize for details.

abs_tol

(Optional). Absolute tolerance for comparing two function evaluations. See the 'Convergence' section of mize for details.

rel_tol

(Optional). Relative tolerance for comparing two function evaluations. See the 'Convergence' section of mize for details.

grad_tol

(Optional). Absolute tolerance for the length (l2-norm) of the gradient vector. See the 'Convergence' section of mize for details.

ginf_tol

(Optional). Absolute tolerance for the infinity norm (maximum absolute component) of the gradient vector. See the 'Convergence' section of mize for details.

step_tol

(Optional). Absolute tolerance for the size of the parameter update. See the 'Convergence' section of mize for details.

Value

Initialized optimizer.

Details

Should be called after creating an optimizer with make_mize and before beginning any optimization with mize_step. Note that if fg and par are available at the time mize_step is called, they can be passed to that function and initialization will be carried out automatically, avoiding the need to call mize_init.

Optional convergence parameters may also be passed here, for use with check_mize_convergence. They are optional if you do your own convergence checking.

Details of the fg list can be found in the 'Details' section of mize.

Examples

Run this code
# NOT RUN {
# Create an optimizer
opt <- make_mize(method = "L-BFGS")

# Function to optimize and starting point defined after creating optimizer
rosenbrock_fg <- list(
  fn = function(x) {
    100 * (x[2] - x[1] * x[1])^2 + (1 - x[1])^2
  },
  gr = function(x) {
    c(
      -400 * x[1] * (x[2] - x[1] * x[1]) - 2 * (1 - x[1]),
      200 * (x[2] - x[1] * x[1])
    )
  }
)
rb0 <- c(-1.2, 1)

# Initialize with function and starting point before commencing optimization
opt <- mize_init(opt, rb0, rosebrock_fg)

# Finally, can commence the optimization loop
par <- rb0
for (iter in 1:3) {
  res <- mize_step(opt, par, rosenbrock_fg)
  par <- res$par
  opt <- res$opt
}
# }

Run the code above in your browser using DataLab