e05jb {NAGFWrappers} R Documentation

## e05jb: Global optimization by multi-level coordinate search, simple bounds, using function values only

### Description

e05jb is designed to find the global minimum or maximum of an arbitrary function, subject to simple bound-constraints using a multi-level coordinate search method. Derivatives are not required, but convergence is only guaranteed if the objective function is continuous in a neighbourhood of a global optimum. It is not intended for large problems.

The initialization function e05ja must have been called before calling e05jb.

### Usage

e05jb(objfun, ibound, iinit, bl, bu, list, numpts, initpt, monit, optlist,
n = nrow(bl),
sdlist = ncol(list))


### Arguments

objfun

function

objfun must evaluate the objective function F(x) for a specified n-vector x.

(F,INFORM) = objfun(n,x,nstate) 

ibound

integer

Indicates whether the facility for dealing with bounds of special forms is to be used. ibound must be set to one of the following values.

ibound=0

: You will supply \ell and u individually.

ibound=1

: There are no bounds on x.

ibound=2

: There are semi-infinite bounds 0 <= x.

ibound=3

: There are constant bounds \ell = \ell_1 and u = u_1.

iinit

integer

Selects which initialization method to use.

iinit=0

: Simple initialization (boundary and midpoint), with numpts[i] = 3, initpt[i] = 2 and list[i, j] = (bl[i](bl[i] + bu[i]) / 2bu[i]), for i = 1 , 2 , . . . , n and j = 1 , 2 , 3.

iinit=1

: Simple initialization (off-boundary and midpoint), with numpts[i] = 3, initpt[i] = 2 and list[i, j] = ((5bl[i] + bu[i]) / 6(bl[i] + bu[i]) / 2(bl[i] + 5bu[i]) / 6), for i = 1 , 2 , . . . , n and j = 1 , 2 , 3.

iinit=2

: Initialization using linesearches.

iinit=3

: You are providing your own initialization list.

iinit=4

: Generate a random initialization list.

bl

double array

bu

double array

bl

is \ell, the array of lower bounds. bu is u, the array of upper bounds.

list

double array

This argument need not be set on entry if you wish to use one of the preset initialization methods (iinit != 3).

numpts

integer array

This argument need not be set on entry if you wish to use one of the preset initialization methods (iinit != 3).

initpt

integer array

This argument need not be set on entry if you wish to use one of the preset initialization methods (iinit != 3).

monit

function

monit may be used to monitor the optimization process. It is invoked upon every successful completion of the procedure in which a sub-box is considered for splitting. It will also be called just before e05jb exits if that splitting procedure was not successful.

(INFORM) = monit(n,ncall,xbest,icount,ninit,list,numpts,initpt,nbaskt,xbaskt,boxl,boxu,nstate) 

optlist

options list

Optional parameters may be listed, as shown in the following table:

 Name Type Default Defaults Function Evaluations Limit integer Default = 100n_r^2 Infinite Bound Size double Default = r_max^(1)/(4) Local Searches string Default = sQuoteON Local Searches Limit integer Default = 50 Local Searches Tolerance double Default = 2ε Minimize Default Maximize Nolist Default List Repeatability string Default = sQuoteOFF Splits Limit integer Default = \lfloord(n_r + 2) / 3\rfloor Static Limit integer Default = 3n_r Target Objective Error double Default = ε^(1)/(4) Target Objective Safeguard double Default = ε^(1)/(2) Target Objective Value double
n

integer: default = nrow(bl)

n

, the number of variables.

sdlist

integer: default = ncol(list)

. sdlist is, at least, the maximum over i of the number of points in coordinate i at which to split according to the initialization list list; that is, sdlist >= max_inumpts[i].

### Details

R interface to the NAG Fortran routine E05JBF.

### Value

 BL double array BU double array Unless ifail =1, ifail =2 on exit, bl and bu are the actual arrays of bounds used by e05jb. LIST double array Unless ifail =1, ifail =2, ifail =-999 on exit, the actual initialization data used by e05jb. If you wish to monitor the contents of list you are advised to do so solely through monit, not through the output value here. NUMPTS integer array Unless ifail =1, ifail =2, ifail =-999 on exit, the actual initialization data used by e05jb. INITPT integer array Unless ifail =1, ifail =2, ifail =-999 on exit, the actual initialization data used by e05jb. X double array If ifail =0, contains an estimate of the global optimum (see also the Accuracy section in the Fortran library documentation). OBJ double If ifail =0, contains the function value at x. 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


optlist <- list()

ifail <- 0
peaks <- function(x1, x2) {

f = 3 * (1 - x1)^2 * exp(-(x1^2) - (x2 + 1)^2) - 10 * (x1/5 -
x1^3 - x2^5) * exp(-x1^2 - x2^2) - 1/3 * exp(-(x1 + 1)^2 -
x2^2)

}

objective = function(n, x, nstate) {

print(x[1])
print(x[2])
if (n == 2) {

inform <- 0

}
else {

inform <- -1
}

if (inform >= 0) {

if (nstate == 1) {

writeLines(toString(cat(sprintf("\n", "\n"))))

writeLines(toString(cat(sprintf("OBJFUN was just called for the first time",
"\n"))))

}
f <- peaks(x[1], x[2])

}
list(F = f, INFORM = as.integer(inform))
}
monitor = function(n, ncall, xbest, icount, ninit,
list, numpts, initpt, nbaskt, xbaskt, boxl, boxu, nstate) {

inform <- 0

if (nstate == 0 || nstate == 1) {

writeLines(toString(cat(sprintf("\n", "\n"))))

writeLines(toString(cat(sprintf("*** Begin monitoring information ***",
"\n"))))

writeLines(toString(cat(sprintf("\n", "\n"))))

}

if (nstate <= 0) {

writeLines(toString(cat(sprintf("Total sub-boxes = %s",
toString(icount[1]), "\n"))))

writeLines(toString(cat(sprintf("Total function evaluations = %s",
toString(ncall), "\n"))))

writeLines(toString(cat(sprintf("Total function evaluations used in local searches = %s",
toString(icount[2]), "\n"))))

writeLines(toString(cat(sprintf("Total points used in local search = %s",
toString(icount[3]), "\n"))))

writeLines(toString(cat(sprintf("Total sweeps through levels = %s",
toString(icount[4]), "\n"))))

writeLines(toString(cat(sprintf("Total splits by init. list = %s",
toString(icount[5]), "\n"))))

writeLines(toString(cat(sprintf("Lowest level with nonsplit boxes = %s",
toString(icount[6]), "\n"))))

writeLines(toString(cat(sprintf("Number of candidate minima in the %s",
"\n"))))

writeLines(toString(cat(sprintf("\n", "\n"))))

writeLines(toString(cat(sprintf("*** End monitoring information ***",
"\n"))))

writeLines(toString(cat(sprintf("\n", "\n"))))

}
list(INFORM = as.integer(inform))
}

prob <- "peaks"

xres <- 100

yres <- 100

bl <- matrix(c(-3, -3), nrow = 2, ncol = 1, byrow = TRUE)

bu <- -bl

fglob <- -6.55

xglob <- matrix(c(0.23, -1.63), nrow = 2, ncol = 1,
byrow = TRUE)

n <- length(bl)

if (ifail == 0) {

writeLines(toString(cat(sprintf("\n", "\n"))))

writeLines(toString(cat(sprintf("Solve with no options or init.-list data",
"\n"))))

ibound <- 0

iinit <- 0

list <- as.matrix(mat.or.vec(n, 3))

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

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

ans <- e05jb(objective, ibound, iinit, bl, bu, list, numpts,
initpt, monitor, optlist)
bl <- ans$BL bu <- ans$BU
list <- ans$LIST numpts <- ans$NUMPTS
initpt <- ans$INITPT x <- ans$X
obj <- ans$OBJ ifail <- ans$IFAIL

ifail <- ans$IFAIL writeLines(toString(cat(sprintf("e05jbno options exited with ifail = %s", toString(ifail), "\n")))) if (ifail == 0) { writeLines(toString(cat(sprintf("xbest:", "\n")))) xbest <- ans$XBEST

print(xbest)
writeLines(toString(cat(sprintf("\n"))))

obj <- ans$OBJ writeLines(toString(cat(sprintf("obj = %s", toString(obj), "\n")))) } writeLines(toString(cat(sprintf("\n", "\n")))) writeLines(toString(cat(sprintf("Solve with options and init.-list data", "\n")))) infbnd <-1.1579+077 iinit <- 3 list <- as.matrix(mat.or.vec(n, 3)) list[, 1] <- bl list[, 3] <- bu list[, 2] <- matrix(c(-1, 0), nrow = 2, ncol = 1, byrow = TRUE) numpts <- 3 * matrix(1, n, 1) initpt <- 2 * matrix(1, n, 1) ans <- e05jb(objective, ibound, iinit, bl, bu, list, numpts, initpt, monitor, optlist) ifail <- ans$IFAIL

writeLines(toString(cat(sprintf("e05jboptions exited with ifail = %s",
toString(ifail), "\n"))))

if (ifail == 0) {

writeLines(toString(cat(sprintf("xbest:", "\n"))))

xbest <- ans$X print(xbest) writeLines(toString(cat(sprintf("\n")))) obj <- ans$OBJ

writeLines(toString(cat(sprintf("obj = %s", toString(obj),
"\n"))))

}
}



[Package NAGFWrappers version 24.0 Index]