e04jc {NAGFWrappers} | R Documentation |
e04jc is an easy-to-use algorithm that uses methods of quadratic approximation to find a minimum of an objective function F over x \in R^n, subject to fixed lower and upper bounds on the independent variables x_1 , x_2 , . . . , x_n. Derivatives of F are not required.
The function is intended for functions that are continuous and that have continuous first and second derivatives (although it will usually work even if the derivatives have occasional discontinuities). Efficiency is maintained for large n.
e04jc(objfun, npt, x, bl, bu, rhobeg, rhoend, monfun, maxcal, n = nrow(x))
objfun |
function objfun must evaluate the objective function F at a specified vector x.
|
npt |
integer m, the number of interpolation conditions imposed on the quadratic approximation at each iteration. |
x |
double array An estimate of the position of the minimum. If any component is out-of-bounds it is replaced internally by the bound it violates. |
bl |
double array |
bu |
double array The fixed vectors of bounds: the lower bounds \ell and the upper bounds u, respectively. To signify that a variable is unbounded you should choose a large scalar r appropriate to your problem, then set the lower bound on that variable to - r and the upper bound to r. For well-scaled problems r = r_max^(1)/(4) may be suitable, where r_max denotes the largest positive model number (see x02al). |
rhobeg |
double An initial lower bound on the value of the trust-region radius. |
rhoend |
double A final lower bound on the value of the trust-region radius. |
monfun |
function monfun may be used to monitor the optimization process. It is invoked every time a new trust-region radius is chosen.
|
maxcal |
integer The maximum permitted number of calls to objfun. |
n |
integer: default = nrow(x) n, the number of independent variables. |
R interface to the NAG Fortran routine E04JCF.
X |
double array The lowest point found during the calculations. Thus, if ifail =0 on exit, x is the position of the minimum. |
F |
double The function value at the lowest point found (x). |
NF |
integer Unless ifail =1, ifail =-999 on exit, the total number of calls made to objfun. |
IFAIL |
integer ifail =0unless the function detects an error or a warning has been flagged (see the Errors section in Fortran library documentation). |
NAG
http://www.nag.co.uk/numeric/FL/nagdoc_fl23/pdf/E04/e04jcf.pdf
ifail <- 0 maxcal <- 500 rhobeg <- 0.1 rhoend <- 1e-06 n <- 4 npt <- 2 * n + 1 infbnd <- sqrt(sqrt(x02al()[["result"]])) bl <- matrix(c(1, -2, -infbnd, 1), nrow = 4, ncol = 1, byrow = TRUE) bu <- matrix(c(3, 0, infbnd, 3), nrow = 4, ncol = 1, byrow = TRUE) x <- matrix(c(3, -1, 0, 1), nrow = 4, ncol = 1, byrow = TRUE) e04jc_objfun = function(n, x) { inform <- 0 f <- (x[1] + 10 %*% x[2])^2 + 5 %*% (x[3] - x[4])^2 + (x[2] - 2 %*% x[3])^4 + 10 %*% (x[1] - x[4])^4 list(F = f, INFORM = as.integer(inform)) } e04jc_monfun = function(n, nf, x, f, rho) { inform <- 0 writeLines(sprintf("\nNew rho = %13.5e, number of function evaluations = %d\n", rho, nf)) writeLines(sprintf("Current function value = %13.5en", f)) writeLines(sprintf("The corresponding X is:", "\n")) writeLines(sprintf(" %13.5e", x, "\n")) writeLines(sprintf("\n", "\n")) list(INFORM = as.integer(inform)) } ans <- e04jc(e04jc_objfun, npt, x, bl, bu, rhobeg, rhoend, e04jc_monfun, maxcal) print(ans$X) print(ans$F) print(ans$NF) print(ans$IFAIL)