Unconstrained numerical optimization algorithms implemented in R.
mize can be used as a standalone optimizer like stats::optim(), or it can be integrated into other packages by creating a stateful optimizer and handling iterations, convergence, and logging externally.
mize includes Broyden-Fletcher-Goldfarb-Shanno (BFGS), limited-memory BFGS (L-BFGS), conjugate gradient (CG), Nesterov accelerated gradient (NAG), momentum-based methods, and related line searches.
Installation
install.packages("mize")Install the development version from GitHub with:
# install.packages("pak")
pak::pak("jlmelville/mize")Quick Start
library(mize)
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])
)
}
)
res <- mize(c(-1.2, 1), rosenbrock_fg, method = "L-BFGS")
res$par
res$fFor stateful optimization, retain the updated optimizer and stop when it reports a terminal state:
par <- c(-1.2, 1)
opt <- make_mize(
method = "L-BFGS",
par = par,
fg = rosenbrock_fg,
max_iter = 30
)
while (!opt$is_terminated) {
par_old <- par
step <- mize_step(opt, par, rosenbrock_fg)
opt <- step$opt
par <- step$par
if (opt$is_terminated) {
break
}
step_info <- mize_step_summary(
opt,
par,
rosenbrock_fg,
par_old = par_old
)
opt <- step_info$opt
if (opt$is_terminated) {
break
}
opt <- check_mize_convergence(step_info)
}
opt[c("status", "converged", "terminate")]Documentation
The package website is https://jlmelville.github.io/mize/.
Start with:
- Getting started
- Choosing methods and tuning
- Convergence
- Stateful optimization
- Metric MDS
- Function reference
The CRAN package also includes the main vignettes.
See also
The Wolfe line searches use conversions of Mark Schmidt’s minFunc routines, Carl Edward Rasmussen’s Matlab code, and Dianne O’Leary’s Matlab translation of the More-Thuente line search algorithm from MINPACK.
I also maintain the funconstrain package, which contains test problems for numerical optimization.