Skip to contents

A step of the cgnonl_native implementation. Called by morie_cgnonl. See the file header for the source the module follows.

Usage

cgnonl_nonlinear_cg(
  f,
  grad,
  x0,
  beta = "fletcher-reeves",
  restart = NULL,
  max_iter = NULL,
  tol = 1e-10,
  est = NULL,
  line_search = "fletcher-reeves",
  hess_vec = NULL,
  keep_path = FALSE
)

Arguments

f

Passed to cgnonl_line_search_fr.

grad

Passed to cgnonl_line_search_fr.

x0

Coerced to numeric by the body, with as.numeric.

beta

Passed to .cgnonl_beta. Defaults to "fletcher-reeves".

restart

Optional; may be NULL. Numeric; combined arithmetically in the body.

max_iter

Optional; may be NULL. Coerced to integer by the body, with as.integer.

tol

Numeric; combined arithmetically in the body. Defaults to 1e-10.

est

Passed to cgnonl_line_search_fr.

Compared against "exact-quadratic". Defaults to "fletcher-reeves".

hess_vec

Optional; may be NULL. Passed to .cgnonl_exact_quadratic_step.

keep_path

A flag; the body branches on it. Defaults to FALSE.

Value

A list with x, fun, grad, gnorm, n_iter, n_restart, n_feval, converged, betas, path, beta_rule, line_search, restart_every, method, note.

Examples

f <- function(x) sum((x - c(1, -2))^2) + x[1]^2 * x[2]^2 / 10
g <- function(x) c(2 * (x[1] - 1) + x[1] * x[2]^2 / 5, 2 * (x[2] + 2) + x[1]^2 * x[2] / 5)
r <- cgnonl_nonlinear_cg(f, g, x0 = c(0, 0), beta = "polak-ribiere")
c(r$x, r$converged)
#> [1]  0.7352836 -1.8974176  1.0000000