| Title: | 'C++' Reimplementation of the 'ucminf' Unconstrained Nonlinear Optimizer |
|---|---|
| Description: | A modern 'C++17' reimplementation of the 'UCMINF' algorithm for unconstrained nonlinear optimization (Nielsen and Mortensen, 2011, <doi:10.32614/CRAN.package.ucminf>), offering full API compatibility with the original 'ucminf' R package but developed independently. The optimizer core has been rewritten in 'C' with a modern header-only 'C++17' interface, zero-allocation line search, and an 'Rcpp' interface. The goal is numerical equivalence with improved performance, reproducibility, and extensibility. Includes extensive test coverage, performance regression tests, and compatibility checks against 'ucminf'. This package is not affiliated with the original maintainers but acknowledges their authorship of the algorithm and the original R interface. |
| Authors: | Angel Luis Robles Fernández [aut, cre] |
| Maintainer: | Angel Luis Robles Fernández <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.1 |
| Built: | 2026-05-21 16:53:05 UTC |
| Source: | https://github.com/alrobles/ucminfcpp |
Print method for ucminf objects
## S3 method for class 'ucminf' print(x, digits = max(3L, getOption("digits") - 3L), ...)## S3 method for class 'ucminf' print(x, digits = max(3L, getOption("digits") - 3L), ...)
x |
A |
digits |
Number of significant digits to print. |
... |
Unused. |
The input object x is returned invisibly (called for side
effects).
An implementation of the UCMINF algorithm translated from Fortran to C and wrapped with Rcpp. The algorithm uses a quasi-Newton method with BFGS updating of the inverse Hessian and a soft line search with trust-region radius monitoring.
ucminf( par, fn = NULL, gr = NULL, ..., fdfun = NULL, control = list(), hessian = 0 )ucminf( par, fn = NULL, gr = NULL, ..., fdfun = NULL, control = list(), hessian = 0 )
par |
Initial estimate of the minimum (numeric vector). |
fn |
Objective function to be minimized. Must return a scalar.
Ignored when |
gr |
Gradient function. If |
... |
Optional arguments passed to |
fdfun |
Optional combined value+gradient function
|
control |
A list of control parameters (see Details), or a
|
hessian |
Integer controlling Hessian output:
|
This package is a two-phase migration of the original ucminf R package:
Phase 1: The Fortran core is translated to C
(src/ucminf_core.c).
Phase 2: The C core is wrapped with an Rcpp interface
(src/ucminf_rcpp.cpp).
The interface is designed to be interchangeable with the original
ucminf::ucminf and with
optim.
The control argument accepts:
traceIf positive, print convergence info after optimization.
Default 0.
grtolStop when grtol.
Default 1e-6.
xtolStop when
xtol*(xtol + ). Default 1e-12.
stepmaxInitial trust-region radius. Default 1.
maxevalMaximum function evaluations. Default 500.
gradFinite-difference type when gr = NULL:
"forward" (default) or "central".
gradstepLength-2 vector; step is
.
Default c(1e-6, 1e-8).
invhessian.ltA vector containing the lower triangle of the initial inverse Hessian (packed column-major). Default: identity.
A list of class "ucminf" with elements:
par |
Computed minimizer. |
value |
Objective value at the minimizer. |
convergence |
Termination code:
|
message |
Human-readable termination message. |
invhessian.lt |
Lower triangle of the final inverse-Hessian approximation (packed). |
invhessian |
Full inverse-Hessian matrix (when |
hessian |
Hessian matrix, inverse of |
info |
Named vector:
|
Nielsen, H. B. (2000). UCMINF – An Algorithm for Unconstrained, Nonlinear Optimization. Report IMM-REP-2000-19, DTU.
## Rosenbrock Banana function fR <- function(x) (1 - x[1])^2 + 100 * (x[2] - x[1]^2)^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])) ## Find minimum with analytic gradient ucminf(par = c(2, 0.5), fn = fR, gr = gR) ## Find minimum with finite-difference gradient ucminf(par = c(2, 0.5), fn = fR)## Rosenbrock Banana function fR <- function(x) (1 - x[1])^2 + 100 * (x[2] - x[1]^2)^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])) ## Find minimum with analytic gradient ucminf(par = c(2, 0.5), fn = fR, gr = gR) ## Find minimum with finite-difference gradient ucminf(par = c(2, 0.5), fn = fR)
Returns a named list of control parameters that can be passed directly
to ucminf(), ucminf_xptr(), etc.
ucminf_control( trace = 0, grtol = 1e-06, xtol = 1e-12, stepmax = 1, maxeval = 500L, grad = c("forward", "central"), gradstep = c(1e-06, 1e-08), invhessian.lt = NULL )ucminf_control( trace = 0, grtol = 1e-06, xtol = 1e-12, stepmax = 1, maxeval = 500L, grad = c("forward", "central"), gradstep = c(1e-06, 1e-08), invhessian.lt = NULL )
trace |
Integer. If > 0, print convergence info. Default 0. |
grtol |
Gradient tolerance. Default 1e-6. |
xtol |
Step tolerance. Default 1e-12. |
stepmax |
Initial trust-region radius. Default 1. |
maxeval |
Maximum function evaluations. Default 500. |
grad |
Finite-difference type: "forward" or "central". Default "forward". |
gradstep |
Length-2 step vector. Default c(1e-6, 1e-8). |
invhessian.lt |
Packed lower-triangle of initial inverse Hessian. Default NULL. |
A list of class "ucminf_control".
Calls the UCMINF optimizer with a compiled C++ objective function
that has been wrapped in an Rcpp::XPtr<ucminf::ObjFun>.
This path bypasses the R interpreter on every function evaluation,
giving maximum performance for non-trivial objectives.
ucminf_xptr(par, xptr, control = list(), hessian = 0)ucminf_xptr(par, xptr, control = list(), hessian = 0)
par |
Numeric starting vector. |
xptr |
An |
control |
A named list of control parameters (see |
hessian |
Integer: 0 = none, 2 = inv-Hessian, 3 = both. |
A list of class "ucminf" (same structure as ucminf).