e04fc {NAGFWrappers} R Documentation

## e04fc: Unconstrained minimum of a sum of squares, combined Gauss-Newton and modified Newton algorithm using function values only (comprehensive)

### Description

e04fc is a comprehensive algorithm for finding an unconstrained minimum of a sum of squares of m nonlinear functions in n variables (m >= n). No derivatives are required.

The function is intended for functions which have continuous first and second derivatives (although it will usually work even if the derivatives have occasional discontinuities).

### Usage

e04fc(m, lsqfun, lsqmon, maxcal, x,
n = nrow(x),
iprint = 1,
eta = if (n==1) 0.0 else 0.5,
xtol = 0.0,
stepmx = 100000.0)


### Arguments

 m integer lsqfun function lsqfun must calculate the vector of values f_i(x) at any point x. (However, if you do not wish to calculate the residuals at a particular x, there is the option of setting a argument to cause e04fc to terminate immediately.) (IFLAG,FVEC) = lsqfun(iflag,m,n,xc)  lsqmon function If iprint >= 0, you must supply lsqmon which is suitable for monitoring the minimization process. lsqmon must not change the values of any of its arguments. () = lsqmon(m,n,xc,fvec,fjac,ldfjac,s,igrade,niter,nf)  maxcal integer The limit you set on the number of times that lsqfun may be called by e04fc. There will be an error exit (see the Errors section in Fortran library documentation) after maxcal calls of lsqfun. x double array x[j] must be set to a guess at the jth component of the position of the minimum for j=1 . . . n. n integer: default = nrow(x) The number m of residuals, f_i(x), and the number n of variables, x_j. iprint integer: default = 1 The frequency with which lsqmon is to be called. eta double: default = if (n==1) 0.0 else 0.5 Specifies how accurately the linear minimizations are to be performed. The minimum with respect to α^(k) will be located more accurately for small values of eta (say, 0.01) than for large values (say, 0.9). Although accurate linear minimizations will generally reduce the number of iterations performed by e04fc, they will increase the number of calls of lsqfun made each iteration. On balance it is usually more efficient to perform a low accuracy minimization. xtol double: default = 0.0 The accuracy in x to which the solution is required. stepmx double: default = 100000.0 An estimate of the Euclidean distance between the solution and the starting point supplied by you. (For maximum efficiency, a slight overestimate is preferable.) e04fc will ensure that, for each iteration, ∑_j = 1^n(x_j^(k) - x_j^(k - 1))^2 <= (stepmx)^2, where k is the iteration number. Thus, if the problem has more than one solution, e04fc is most likely to find the one nearest to the starting point. On difficult problems, a realistic choice can prevent the sequence x^(k) entering a region where the problem is ill-behaved and can help avoid overflow in the evaluation of F(x). However, an underestimate of stepmx can lead to inefficiency.

### Details

R interface to the NAG Fortran routine E04FCF.

### Value

 X double array The final point x^(k). Thus, if ifail =0 on exit, x[j] is the jth component of the estimated position of the minimum. FSUMSQ double The value of F(x), the sum of squares of the residuals f_i(x), at the final point given in x. FVEC double array The value of the residual f_i(x) at the final point given in x for i=1 . . . m. FJAC double array The estimate of the first derivative ( \partial f_i)/( \partial x_j) at the final point given in x for j=1 . . . n for i=1 . . . m. S double array The singular values of the estimated Jacobian matrix at the final point. Thus s may be useful as information about the structure of your problem. V double array The matrix V associated with the singular value decomposition J = USV^T of the estimated Jacobian matrix at the final point, stored by columns. This matrix may be useful for statistical purposes, since it is the matrix of orthonormalized eigenvectors of J^TJ. NITER integer The number of iterations which have been performed in e04fc. NF integer The number of times that the residuals have been evaluated (i.e., number of calls of lsqfun). IFAIL integer ifail =0 unless the function detects an error or a warning has been flagged (see the Errors section in Fortran library documentation).

NAG

### Examples


ifail <- 0
lsqfun = function(iflag, m, n, xc) {

fvec <- as.matrix(mat.or.vec(m, 1))
for (i in c(1:m)) {
fvec[i] <- xc[1] + t[i, 1]/(xc[2] %*% t[i, 2] + xc[3] %*%
t[i, 3]) - y[i]
}
list(IFLAG = as.integer(iflag), FVEC = as.matrix(fvec))
}
lsqmon = function(m, n, xc, fvec, fjacc, ljc, s, igrade,
niter, nf) {

if (niter == 0) {

writeLines(toString(cat(sprintf(" Itn F evals SUMSQ \n",
"\n"))))

}
fsumsq <- crossprod(fvec, fvec)
writeLines(toString(cat(sprintf(" %3d %3d %12.8f\n",
niter, nf, fsumsq, "\n"))))

list()
}

m <- 15

n <- 3

maxcal <- 1200

x <- matrix(c(0.5, 1, 1.5), nrow = 3, ncol = 1, byrow = TRUE)

iw <- as.matrix(mat.or.vec(1, 1))

w <- as.matrix(mat.or.vec(6 %*% n + m %*% n + 2 %*%
m + n %*% ((n - 1)/2), 1))

y <- matrix(c(0.14, 0.18, 0.22, 0.25, 0.29, 0.32,
0.35, 0.39, 0.37, 0.58, 0.73, 0.96, 1.34, 2.1, 4.39), nrow = 1,
ncol = 15, byrow = TRUE)

t <- matrix(c(1, 15, 1, 2, 14, 2, 3, 13, 3, 4, 12,
4, 5, 11, 5, 6, 10, 6, 7, 9, 7, 8, 8, 8, 9, 7, 7, 10, 6,
6, 11, 5, 5, 12, 4, 4, 13, 3, 3, 14, 2, 2, 15, 1, 1), nrow = 15,
ncol = 3, byrow = TRUE)

e04fc(m, lsqfun, lsqmon, maxcal, x)



[Package NAGFWrappers version 24.0 Index]