Description Usage Arguments Value Requirements for the optimizer function Details for progress handler function Author(s) See Also Examples
Global optimization by partial gridding where the actual optimization is done transparently
by calls to optim
.
1 2 3 4 |
theta |
A |
par |
A |
min,max |
Two |
width |
A |
steps |
A |
depth |
The depth, or the number of "generations", to grid search
over. When all |
shrink |
A |
... |
Other arguments passed to the optimizer function. |
optimizer |
An optimizer |
maximize |
If |
.checkArgs |
If |
progressHandler |
A |
verbose |
If |
Return a list
with information about the optimal settings:
theta |
The grid point |
optim |
The result returned by |
gridCount |
Total number of grid points tested. |
callCount |
Total number of calls to the objective (and the gradient) function. |
The optimizer function specified by the optimizer
argument must
accept the argument par
as the first argument, cf.
optim
, followed by ...
, followed by the named
argument theta
at any position.
The optimizer function must return a list
with the element
value
containing the optimal numerical value given the
current gridpoint (passed to the function by an argument named
theta
).
Optionally, it may return the number of internal optimization steps
using the count
element (a numeric
scalar or vector
), which
is then summed up together over the whole grid (including recursive
grid) by this function.
For instance, the optim
function returns the number of
calls to the objective and the gradient functions.
The progressHandler
function must accept the following arguments:
eventA character
string specifying what type of event has occured.
argsA list
of arguments used to call this function.
optimumA list
specifying the current optimum. Due to the
recursive nature of this function, this does not have to be the
optimum found by all optimizers, but only in the child optimizers.
Henrik Bengtsson
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | objective <- function(par, ..., theta=theta, verbose=FALSE) {
if (verbose) {
args <- list(
theta=theta,
par=par,
...
);
str(args);
}
sum(theta);
}
theta <- c(1,1)
par <- 0
min <- theta - 2
max <- theta + 2
depth <- 2
steps <- 3
opt <- gridOptim(theta=theta, par=par, min=min, max=max, steps=steps,
depth=depth, fn=objective, maximize=FALSE)
print(opt)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.