% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nlm_track.R, R/optim_track.R,
%   R/trackopt_methods.R
\name{nlm_track}
\alias{nlm_track}
\alias{optim_track}
\alias{summary.trackopt}
\alias{autoplot.trackopt}
\title{Track numerical optimization}
\usage{
nlm_track(
  f,
  p,
  target = NULL,
  npar = NULL,
  gradient = NULL,
  hessian = NULL,
  ...,
  iterations_max = 100,
  tolerance = 1e-06,
  typsize = rep(1, length(p)),
  fscale = 1,
  ndigit = 12,
  stepmax = max(1000 * sqrt(sum((p/typsize)^2)), 1000),
  steptol = 1e-06,
  minimize = TRUE,
  verbose = FALSE
)

optim_track(
  f,
  p,
  target = NULL,
  npar = NULL,
  gradient = NULL,
  ...,
  iterations_max = 100,
  tolerance = 1e-06,
  lower = NULL,
  upper = NULL,
  method = c("Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN", "Brent"),
  control = list(),
  minimize = TRUE,
  verbose = FALSE
)

\method{summary}{trackopt}(object, ...)

\method{autoplot}{trackopt}(object, iteration = NULL, xlim = NULL, xlim2 = NULL, ...)
}
\arguments{
\item{f}{[\code{function}]\cr
A \code{function} to optimize. It must return a single \code{numeric} value.

By default, the first argument of \code{f} is optimized. That argument should
be a \code{numeric} vector of the same length as \code{p}. Additional arguments can
be supplied through \code{...}.

Use \code{target} when \code{f} should be optimized over another argument or over
multiple arguments.}

\item{p}{[\code{numeric()}]\cr
The starting parameter values for the target argument(s).}

\item{target}{[\code{character()} | \code{NULL}]\cr
The names of the numeric argument(s) to optimize.

If \code{NULL} (default), the first argument of \code{f} is used.}

\item{npar}{[\code{integer()}]\cr
The length of each target argument.

Specify \code{npar} when optimizing over multiple target arguments so \code{p} can
be split correctly.

If \code{target} contains a single argument and \code{npar} is \code{NULL}, \code{length(p)}
is used.}

\item{gradient}{[\code{function} | \code{NULL}]\cr
Optionally a \code{function} that returns the gradient of \code{f}.

Its arguments must match the arguments of \code{f}.}

\item{hessian}{[\code{function} | \code{NULL}]\cr
Optionally a \code{function} that returns the Hessian of \code{f}.

Its arguments must match the arguments of \code{f}.}

\item{...}{Additional arguments passed to \code{f}, and to \code{gradient} and \code{hessian} when
they are specified.}

\item{iterations_max}{[\code{integer(1)}]\cr
The maximum number of tracked optimization steps before termination.}

\item{tolerance}{[\code{numeric(1)}]\cr
Tracking stops when the absolute change in function value between two
consecutive iterations is less than this value.}

\item{typsize, fscale, ndigit, stepmax, steptol}{Arguments passed on to \code{\link[stats]{nlm}}.}

\item{minimize}{[\code{logical(1)}]\cr
If \code{TRUE}, minimize \code{f}; otherwise maximize it.}

\item{verbose}{[\code{logical(1)}]\cr
If \code{TRUE}, print progress after each iteration.}

\item{lower, upper}{[\code{numeric()} | \code{NULL}]\cr
Optional lower and upper parameter bounds. Scalars are recycled to the
number of parameters.}

\item{method, control}{Arguments passed on to \code{\link[stats]{optim}}.

Elements \code{trace} and \code{maxit} are ignored in \code{control} because
\code{optim_track()} controls tracing and iteration limits directly.}

\item{object}{[\code{trackopt}]\cr
A \code{trackopt} object.}

\item{iteration}{[\code{integer(1)}]\cr
The iteration to plot.

If \code{NULL}, the last iteration is plotted.

This option is useful for creating animations with the R Markdown
\code{animation} chunk option.}

\item{xlim, xlim2}{[\code{numeric(2)}]\cr
Ranges for the first and second parameter to plot.

If \code{NULL}, they are derived from the parameter ranges in \code{object}.}
}
\value{
A \code{tibble} with one row per stored iteration, including the starting point.
}
\description{
\itemize{
\item \code{nlm_track()}: track \code{\link[stats]{nlm}} iterations
\item \code{optim_track()}: track \code{\link[stats]{optim}} iterations
\item \code{summary()}: summarize an optimization track
\item \code{autoplot()}: visualize a track with one or two parameters
}
}
\examples{
himmelblau <- function(x) {
  (x[1]^2 + x[2] - 11)^2 + (x[1] + x[2]^2 - 7)^2
}
track <- nlm_track(f = himmelblau, p = c(0, 0))
summary(track)
ggplot2::autoplot(track)
}
