sceua(OFUN, pars, lower, upper, maxn = 10000, kstop = 5, pcento = 0.01, ngs = 5, npg = 5, nps = 5, nspl = 5, mings = 5, iniflg = 1, iprint = 0, iround = 3, peps = 0.0001, plog = rep(FALSE,length(pars)), implicit = NULL, ...)This implementation follows the Fortran implementation relatively close, but adds the possibility of searching in log-space for one or more of the parameters, and it uses the capability of R to pass functions as arguments, making it possible to pass implicit conditions to the parameter selection.
The objective function OFUN is a function which should give an error value for each parameter set.
It should never return non-numeric values such as NA, NULL, or Inf. If some parameter combinations can
give such values, the return value should rather be a large number.
The function works with fixed upper and lower boundaries for the parameters. If the possible range of
a parameter might span several orders of magnitude, it might be better to search in log-space for the optimal parameter,
to reduce the risk of being trapped in local optima. This can be set with the argument plog, which is either
a single value (FALSE/TRUE) or a vector for all parameters.
plog = c(TRUE, FALSE, FALSE, TRUE, TRUE) means that the search for parameters 1,4 and 5 should be in log10-space,
whereas the search for parameters 2 and 3 are in normal space.
Implicit boundaries can be evoked by passing a function implicit to sceua.
This function should give 0 when parameters are acceptable
and 1 if not. If, for example, the condition is that the following sum of parameters four and five should be limited:
sum(pars[4]+pars[5]) <= 1<="" p="">
then the function will be implicit = function(pars) (2*pars[4] + pars[5]) > 1
=>Holland, H.H., 1975. Adaptation in natural and artificial systems, University of Michigan Press, Ann Arbor.
Nelder, J.A. and Mead, R., 1965. A simplex method for function minimization, Comput. J., 7(4), 308-313.
Price, W.L., 1987. Global optimization algorithms for a CAD workstation, J. Optim. Theory Appl., 55(1), 133-146.
set.seed(1)
# generate example data from a function with three parameters
# with some random noise
fun = function(x, pars) pars[2]*sin(x*pars[1])+pars[3]
x = rnorm(50, sd = 3)
y = fun(x, pars = c(5, 2, 3)) + rnorm(length(x), sd = 0.3)
plot(x,y)
# Objective function, summing up squared differences
OFUN = function(pars, x, yobs) {
yvals = fun(x, pars)
sum((yvals-yobs)^2)
}
sceuares = sceua(OFUN, pars = c(0.1,0.1,0.1), lower = c(-10,0,-10),
upper = c(10,10,10), x = x, yobs = y)
sceuares
xx = seq(min(x), max(x), 0.1)
lines(xx, fun(xx, pars = sceuares$par))
Run the code above in your browser using DataLab