e04ky {NAGFWrappers} | R Documentation |
e04ky is an easy-to-use quasi-Newton algorithm for finding a minimum of a function F(x_1x_2 . . . x_n), subject to fixed upper and lower bounds on the independent variables x_1 , x_2 , . . . , x_n, when first derivatives of F are available.
It is intended for functions which are continuous and which have continuous first and second derivatives (although it will usually work even if the derivatives have occasional discontinuities).
e04ky(ibound, funct2, bl, bu, x, n = nrow(bl), liw = (n+2), lw = (max((10*n+n*(n-1)/2),11)))
ibound |
integer Indicates whether the facility for dealing with bounds of special forms is to be used. It must be set to one of the following values: ibound = 0: If you are supplying all the l_j and u_j individually. ibound = 1: If there are no bounds on any x_j. ibound = 2: If all the bounds are of the form 0 <= x_j. ibound = 3: If l_1 = l_2 = . . . = l_n and u_1 = u_2 = . . . = u_n. |
funct2 |
function You must supply funct2 to calculate the values of the function F(x) and its first derivative ( \partial F)/( \partial x_j) at any point x. It should be tested separately before being used in conjunction with e04ky (see the E04 chapter introduction in the Fortran Library documentation).
|
bl |
double array The lower bounds l_j. |
bu |
double array The upper bounds u_j. |
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. The function checks the gradient at the starting point, and is more likely to detect any error in your programming if the initial x[j] are nonzero and mutually distinct. |
n |
integer: default = nrow(bl) The number n of independent variables. |
liw |
integer: default = (n+2) |
lw |
integer: default = (max((10*n+n*(n-1)/2),11)) |
R interface to the NAG Fortran routine E04KYF.
BL |
double array The lower bounds actually used by e04ky. |
BU |
double array The upper bounds actually used by e04ky. |
X |
double array The lowest point found during the calculations. Thus, if ifail =0 on exit, x[j] is the jth component of the position of the minimum. |
F |
double The value of F(x) corresponding to the final point stored in x. |
G |
double array The value of ( \partial F)/( \partial x_j) corresponding to the final point stored in x for j=1 . . . n; the value of g[j] for variables not on a bound should normally be close to zero. |
IW |
integer array If ifail =0, ifail =3, ifail =5, the first n elements of iw contain information about which variables are currently on their bounds and which are free. Specifically, if x_i is: -: fixed on its upper bound, iw[i] is - 1; -: fixed on its lower bound, iw[i] is - 2; -: effectively a constant (i.e., l_j = u_j), iw[i] is - 3; -: free, iw[i] gives its position in the sequence of free variables. |
W |
double array If ifail =0, ifail =3, ifail =5, w[i] contains the ith element of the projected gradient vector g_z for i=1 . . . n. In addition, w[n+1] contains an estimate of the condition number of the projected Hessian matrix (i.e., k). The rest of the array is used as workspace. |
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/e04kyf.pdf
ifail<-0 funct2=function(n,xc){ gc<-as.matrix(mat.or.vec(n,1)) fc<-(xc[1]+10%*%xc[2])^2+5%*%(xc[3]-xc[4])^2+(xc[2]-2%*%xc[3])^4+10%*%(xc[1]-xc[4])^4 gc[1]<-2%*%(xc[1]+10%*%xc[2])+40%*%(xc[1]-xc[4])^3 gc[2]<-20%*%(xc[1]+10%*%xc[2])+4%*%(xc[2]-2%*%xc[3])^3 gc[3]<-10%*%(xc[3]-xc[4])-8%*%(xc[2]-2%*%xc[3])^3 gc[4]<--10%*%(xc[3]-xc[4])-40%*%(xc[1]-xc[4])^3 list(FC=fc,GC=as.matrix(gc)) } ibound<-0 bl<-matrix(c(1,-2,-1000000,1),nrow=4,ncol=1,byrow=TRUE) bu<-matrix(c(3,0,1000000,3),nrow=4,ncol=1,byrow=TRUE) x<-matrix(c(3,-1,0,1),nrow=4,ncol=1,byrow=TRUE) e04ky(ibound,funct2,bl,bu,x)