e04us {NAGFWrappers} | R Documentation |
e04us is designed to minimize an arbitrary smooth sum of squares function subject to constraints (which may include simple bounds on the variables, linear constraints and smooth nonlinear constraints) using a sequential quadratic programming (SQP) method. As many first derivatives as possible should be supplied by you; any unspecified derivatives are approximated by finite differences. See the description of the optional argument derivativelevel, in the Fortran library documentation. It is not intended for large sparse problems.
e04us may also be used for unconstrained, bound-constrained and linearly constrained optimization.
e04us(a, bl, bu, y, confun, objfun, istate, cjac, fjac, clamda, r, x, optlist, m = nrow(y), n = nrow(x), nclin = nrow(a), ncnln = nrow(cjac))
a |
double array The ith row of a contains the ith row of the matrix A_L of general linear constraints in eqn1. That is, the ith row contains the coefficients of the ith general linear constraint for i=1 . . . nclin. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bl |
double array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bu |
double array Must contain the lower bounds and bu the upper bounds, for all the constraints in the following order. The first n elements of each array must contain the bounds on the variables, the next n_L elements the bounds for the general linear constraints (if any) and the next n_N elements the bounds for the general nonlinear constraints (if any). To specify a nonexistent lower bound (i.e., l_j = - infinity), set bl[j] <= - bigbnd, and to specify a nonexistent upper bound (i.e., u_j = + infinity), set bu[j] >= bigbnd; the default value of bigbnd is 10^20, but this may be changed by the optional argument infiniteboundsize. To specify the jth constraint as an equality, set bl[j] = bu[j] = β, say, where abs(β) < bigbnd. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
y |
double array The coefficients of the constant vector y of the objective function. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
confun |
function confun must calculate the vector c(x) of nonlinear constraint functions and (optionally) its Jacobian ( = ( \partial c)/( \partial x)) for a specified n element vector x. If there are no nonlinear constraints (i.e., ncnln = 0), confun will never be called by e04us and confun may be the dummy function e04udm. (e04udm is included in the NAG Library.) If there are nonlinear constraints, the first call to confun will occur before the first call to objfun.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
objfun |
function objfun must calculate either the ith element of the vector f(x) = (f_1(x)f_2(x) . . . f_m(x))^T or all m elements of f(x) and (optionally) its Jacobian ( = ( \partial f)/( \partial x)) for a specified n element vector x.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
istate |
integer array Need not be set if the (default) optional argument coldstart is used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cjac |
double array In general, cjac need not be initialized before the call to e04us. However, if derivativelevel=3, you may optionally set the constant elements of cjac (see argument nstate in the description of confun). Such constant elements need not be re-assigned on subsequent calls to confun. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fjac |
double array In general, fjac need not be initialized before the call to e04us. However, if derivativelevel=3, you may optionally set the constant elements of fjac (see argument nstate in the description of objfun). Such constant elements need not be re-assigned on subsequent calls to objfun. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
clamda |
double array Need not be set if the (default) optional argument coldstart is used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
r |
double array Need not be initialized if the (default) optional argument coldstart is used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
x |
double array An initial estimate of the solution. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
optlist |
options list Optional parameters may be listed, as shown in the following table:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
m |
integer: default = nrow(y) m, the number of subfunctions associated with F(x). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
n |
integer: default = nrow(x) n, the number of variables. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nclin |
integer: default = nrow(a) n_L, the number of general linear constraints. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ncnln |
integer: default = nrow(cjac) n_N, the number of nonlinear constraints. |
R interface to the NAG Fortran routine E04USF.
ITER |
integer The number of major iterations performed. |
ISTATE |
integer array The status of the constraints in the QP working set at the point returned in x. The significance of each possible value of istate[j] is as follows: |
C |
double array If ncnln > 0, c[i] contains the value of the ith nonlinear constraint function c_i at the final iterate for i=1 . . . ncnln. |
CJAC |
double array If ncnln > 0, cjac contains the Jacobian matrix of the nonlinear constraint functions at the final iterate, i.e., cjac[i, j] contains the partial derivative of the ith constraint function with respect to the jth variable for j=1 . . . n for i=1 . . . ncnln. (See the discussion of argument cjac under confun.) |
F |
double array f[i]contains the value of the ith function f_i at the final iterate for i=1 . . . m. |
FJAC |
double array The Jacobian matrix of the functions f_1 , f_2 , . . . , f_m at the final iterate, i.e., fjac[i, j] contains the partial derivative of the ith function with respect to the jth variable for j=1 . . . n for i=1 . . . m. (See also the discussion of argument fjac under objfun.) |
CLAMDA |
double array The values of the QP multipliers from the last QP subproblem. clamda[j] should be non-negative if istate[j] = 1 and non-positive if istate[j] = 2. |
OBJF |
double The value of the objective function at the final iterate. |
R |
double array If hessian=NO, r contains the upper triangular Cholesky factor R of Q^TtildeHQ, an estimate of the transformed and reordered Hessian of the Lagrangian at x (see eqn6). If hessian=YES, r contains the upper triangular Cholesky factor R of H, the approximate (untransformed) Hessian of the Lagrangian, with the variables in the natural order. |
X |
double array The final estimate of the solution. |
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/e04usf.pdf
optlist <- list() ifail <- 0 confun = function(mode, ncnln, n, needc, x, cjac, nstate) { ldcj <- nrow(cjac) c <- as.matrix(mat.or.vec(ncnln, 1)) if (nstate == 1) { cjac <- as.matrix(mat.or.vec(ncnln, n)) } if (needc[1] > 0) { if (mode == 0 || mode == 2) { c[1] <- -0.09 - x[1] %*% x[2] + 0.49 %*% x[2] } if (mode == 1 || mode == 2) { cjac[1, 1] <- -x[2] cjac[1, 2] <- -x[1] + 0.49 } } list(MODE = as.integer(mode), C = as.matrix(c), CJAC = as.matrix(cjac)) } objfun = function(mode, m, n, needfi, x, fjac, nstate) { ldfj <- nrow(fjac) f <- as.matrix(mat.or.vec(m, 1)) a <- matrix(c(8, 8, 10, 10, 10, 10, 12, 12, 12, 12, 14, 14, 14, 16, 16, 16, 18, 18, 20, 20, 20, 22, 22, 22, 24, 24, 24, 26, 26, 26, 28, 28, 30, 30, 30, 32, 32, 34, 36, 36, 38, 38, 40, 42), nrow = 1, ncol = 44, byrow = TRUE) for (i in c(1:m)) { temp <- exp(-x[2] %*% (a[i] - 8)) if (mode == 0 || mode == 2) { f[i] <- x[1] + (0.49 - x[1]) %*% temp } if (mode == 1 || mode == 2) { fjac[i, 1] <- 1 - temp fjac[i, 2] <- -(0.49 - x[1]) %*% (a[i] - 8) %*% temp } } list(MODE = as.integer(mode), F = as.matrix(f), FJAC = as.matrix(fjac)) } a <- matrix(c(1, 1), nrow = 1, ncol = 2, byrow = TRUE) bl <- matrix(c(0.4, -4, 1, 0), nrow = 4, ncol = 1, byrow = TRUE) bu <- matrix(c(1e+25, 1e+25, 1e+25, 1e+25), nrow = 4, ncol = 1, byrow = TRUE) y <- matrix(c(0.49, 0.49, 0.48, 0.47, 0.48, 0.47, 0.46, 0.46, 0.45, 0.43, 0.45, 0.43, 0.43, 0.44, 0.43, 0.43, 0.46, 0.45, 0.42, 0.42, 0.43, 0.41, 0.41, 0.4, 0.42, 0.4, 0.4, 0.41, 0.4, 0.41, 0.41, 0.4, 0.4, 0.4, 0.38, 0.41, 0.4, 0.4, 0.41, 0.38, 0.4, 0.4, 0.39, 0.39), nrow = 44, ncol = 1, byrow = TRUE) istate <- as.matrix(mat.or.vec(4, 1)) cjac <- matrix(c(0, 0), nrow = 1, ncol = 2, byrow = TRUE) fjac <- matrix(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), nrow = 44, ncol = 2, byrow = TRUE) clamda <- as.matrix(mat.or.vec(4, 1)) r <- matrix(c(0, 0, 0, 0), nrow = 2, ncol = 2, byrow = TRUE) x <- matrix(c(0.4, 0), nrow = 2, ncol = 1, byrow = TRUE) e04us(a, bl, bu, y, confun, objfun, istate, cjac, fjac, clamda, r, x, optlist)