| Title: | Thread-Safe C++ Trust Region Optimizers |
|---|---|
| Description: | Thread-safe C++ trust region optimizers, each exposed both as an R function and as a C-callable entry point (with function pointers registered for other packages to call without linking against this package's shared library) so they can be used from parallel C++ code such as in 'nlmixr2est'. Includes a port of the two-derivative trust region algorithm in the 'trust' package by Charles J. Geyer; a port of the Steihaug truncated conjugate-gradient trust region method from the 'basin' Rust crate (Steihaug (1983) <doi:10.1137/0720042>); and ports of M. J. D. Powell's derivative-free BOBYQA (Powell (2009), Report DAMTP 2009/NA06) and NEWUOA (Powell (2006) <doi:10.1007/0-387-30065-1_16>) Fortran 77 code <https://github.com/libprima/prima/tree/main/fortran/original>, as modified and distributed in the 'minqa' package, whose R interface is reproduced. |
| Authors: | Charles J. Geyer [aut, cph] (ORCID: <https://orcid.org/0000-0003-1471-1703>), Matthew Fidler [aut, cre] (ORCID: <https://orcid.org/0000-0001-8538-6691>), Michael J. D. Powell [aut] (BOBYQA and NEWUOA algorithms and original Fortran 77 code), Douglas Bates [ctb, cph] (minqa), Katharine M. Mullen [ctb, cph] (minqa), John C. Nash [ctb, cph] (minqa), Ravi Varadhan [ctb, cph] (minqa), Johan Larsson [ctb, cph] (basin trust-region / Steihaug implementation) |
| Maintainer: | Matthew Fidler <[email protected]> |
| License: | GPL-2 |
| Version: | 0.2.0 |
| Built: | 2026-09-17 21:39:04 UTC |
| Source: | https://github.com/nlmixr2/RcppTrust |
Returns the list of native function pointers a consuming package (e.g.
nlmixr2est) resolves via the header-only registration pattern in
inst/include/RcppTrust.h – the same pattern rxode2/n1qn1c/
lbfgsb3c use, so no linker dependency on this package's shared library
is required. Not intended to be called directly by end users.
.RcppTrustPtr().RcppTrustPtr()
An unclassed list of external pointers.
Thread-safe C++ port of minqa::bobyqa(): minimizes a function of
many variables subject to box constraints by a trust region method that
forms quadratic models by interpolation, using M. J. D. Powell's BOBYQA
algorithm. Arguments, defaults, and return value are those of
minqa::bobyqa(); see its documentation for details.
bobyqa(par, fn, lower = -Inf, upper = Inf, control = list(), ...)bobyqa(par, fn, lower = -Inf, upper = Inf, control = list(), ...)
par |
numeric vector of starting parameters. |
fn |
function to be minimized; its first argument must be the parameter vector and it must return a scalar numeric value. |
lower, upper
|
numeric vectors of lower and upper bounds (recycled when of length 1). |
control |
a list of control settings: |
... |
further arguments passed to |
A list of class c("bobyqa", "minqa") with components
par, fval, feval, ierr and msg.
M. J. D. Powell's original Fortran 77 BOBYQA code, archived at https://github.com/libprima/prima/tree/main/fortran/original/bobyqa; R interface following the minqa package.
M. J. D. Powell (2009), "The BOBYQA algorithm for bound constrained optimization without derivatives", Report No. DAMTP 2009/NA06, Centre for Mathematical Sciences, University of Cambridge.
[newuoa()], and [minqa_c_api] for calling the solvers from parallel C/C++ code.
fr <- function(x) 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 bobyqa(c(1, 2), fr, lower = c(0, 0), upper = c(4, 4))fr <- function(x) 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 bobyqa(c(1, 2), fr, lower = c(0, 0), upper = c(4, 4))
Thread-safe C++ port of minqa::newuoa(): minimizes a function of
many variables by a trust region method that forms quadratic models by
interpolation, using M. J. D. Powell's NEWUOA algorithm.
newuoa(par, fn, control = list(), ...)newuoa(par, fn, control = list(), ...)
par |
numeric vector of starting parameters. |
fn |
function to be minimized; its first argument must be the parameter vector and it must return a scalar numeric value. |
control |
a list of control settings: |
... |
further arguments passed to |
A list of class c("newuoa", "minqa") with components
par, fval, feval, ierr and msg.
M. J. D. Powell's original Fortran 77 NEWUOA code, archived at https://github.com/libprima/prima/tree/main/fortran/original/newuoa; R interface following the minqa package.
M. J. D. Powell (2006), "The NEWUOA software for unconstrained optimization without derivatives", in Large-Scale Nonlinear Optimization, Springer, 255-297. doi:10.1007/0-387-30065-1_16
[bobyqa()], [minqa_c_api]
fr <- function(x) 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 newuoa(c(1, 2), fr)fr <- function(x) 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 newuoa(c(1, 2), fr)
Print method for minqa objects
## S3 method for class 'minqa' print(x, digits = max(3, getOption("digits") - 3), ...)## S3 method for class 'minqa' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
an object inheriting from class |
digits |
unused; kept for compatibility with |
... |
unused. |
invisible(x)
Thread-safe C++ port of the trust-region Newton minimizer with the
Steihaug truncated conjugate-gradient subproblem from the Rust crate
basin (TrustRegion with
its default Steihaug subproblem, driven by basin's executor). Each
iteration approximately minimizes the quadratic model
over by conjugate gradients,
stopping at the boundary on negative curvature. Unlike [trust()] it never
factorizes the Hessian, and with hessvec it never forms it at all
(basin's matrix-free mode).
steihaug(par, fn, gr, hess = NULL, hessvec = NULL, control = list(), ...)steihaug(par, fn, gr, hess = NULL, hessvec = NULL, control = list(), ...)
par |
numeric vector of starting parameters. |
fn |
objective function of the parameter vector returning a scalar. |
gr |
gradient function returning a numeric vector of length
|
hess |
Hessian function returning a symmetric
|
hessvec |
optional Hessian-vector product |
control |
a list of control settings (defaults in brackets; a
|
... |
further arguments passed to |
Evaluation pattern (identical to basin): fn and gr once at
the start; hess once per outer iteration (exact mode) or
hessvec once per CG product (matrix-free mode); fn at each
trial point; gr after each accepted step. fn may return
Inf (or NaN) at a trial point to reject it.
A list with components par, value, gradient,
iterations, converged, status (integer),
message (the basin termination reason, e.g.
"GradientTolerance", "MaxIter"), radius (final
trust radius), counts (evaluations of fn, gr,
hess, hessvec), and, when control$trace is
TRUE, trace, a data frame with one row per subproblem
attempt.
Steihaug, T. (1983). The conjugate gradient method and trust regions in large scale optimization. SIAM Journal on Numerical Analysis, 20(3), 626-637.
Nocedal, J. and Wright, S. J. (2006). Numerical Optimization (2nd ed.), Algorithms 4.1 and 7.2. Springer.
[trust()], [bobyqa()], [newuoa()]
fr <- function(x) 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 grr <- function(x) c(-400 * x[1] * (x[2] - x[1]^2) - 2 * (1 - x[1]), 200 * (x[2] - x[1]^2)) hr <- function(x) matrix(c(1200 * x[1]^2 - 400 * x[2] + 2, -400 * x[1], -400 * x[1], 200), 2, 2) steihaug(c(-1.2, 1), fr, grr, hr) # matrix-free: only Hessian-vector products hv <- function(x, v) drop(hr(x) %*% v) steihaug(c(-1.2, 1), fr, grr, hessvec = hv)$countsfr <- function(x) 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 grr <- function(x) c(-400 * x[1] * (x[2] - x[1]^2) - 2 * (1 - x[1]), 200 * (x[2] - x[1]^2)) hr <- function(x) matrix(c(1200 * x[1]^2 - 400 * x[2] + 2, -400 * x[1], -400 * x[1], 200), 2, 2) steihaug(c(-1.2, 1), fr, grr, hr) # matrix-free: only Hessian-vector products hv <- function(x, v) drop(hr(x) %*% v) steihaug(c(-1.2, 1), fr, grr, hessvec = hv)$counts
Thread-safe C++ port of trust::trust() (Geyer). Carries out a
minimization or maximization of a function using a trust region
algorithm; see the original package's documentation for the algorithm
and argument semantics, which this function reproduces exactly.
trust( objfun, parinit, rinit, rmax, parscale, iterlim = 100, fterm = sqrt(.Machine$double.eps), mterm = sqrt(.Machine$double.eps), minimize = TRUE, blather = FALSE, ... )trust( objfun, parinit, rinit, rmax, parscale, iterlim = 100, fterm = sqrt(.Machine$double.eps), mterm = sqrt(.Machine$double.eps), minimize = TRUE, blather = FALSE, ... )
objfun |
an R function computing value, gradient, and Hessian; see
|
parinit |
starting parameter values. |
rinit |
starting trust region radius. |
rmax |
maximum allowed trust region radius. |
parscale |
optional parameter scale vector. |
iterlim |
maximum number of iterations. |
fterm |
function-value termination tolerance. |
mterm |
model-decrease termination tolerance. |
minimize |
if |
blather |
if |
... |
additional arguments passed to |
A list with the same components as trust::trust().