nlminb(start, objective, gradient=NULL, hessian=NULL,
scale=1, control=NULL, lower=-Inf, upper=Inf, ...)
NAs) are not allowed.
f(x, <<additional arguments>>), where
x is the vector of parameters over
which the minimization takes place. Users can accumulate information through
attributes of the value of
objective. If the attributes include any
additional arguments for
objective, the next call to
objective uses the new values of those arguments.
g(x, <<additional arguments>>),
where
x is the vector of parameters over which the minimization takes place. As for
objective, users can accumulate information through attributes of the
value of
gradient. It cannot be assumed that the value of
x on a given
call to
gradient is the same as the value of
x used in the previous call
to
objective. If
gradient is not supplied, the gradient is estimated by
finite differences. Entries of the Hessian matrix may also be supplied
by
gradient. In this case, the value of
gradient should be a list
with components named
gradient and
hessian, where the
hessian
components is a numeric vector representing the lower triangle of the
Hessian matrix with entries in the following order: (1,1), (2,1), (2,2),
(3,1), (3,2), (3,3), ... That is, the ijth (and jith) entry of the Hessian
appears in the
(max(i,j)*(max(i,j)-1))/2 + min(i,j) position of the array.
gradient.
If
hessian is a function, it must be of the form
h(x, <<additional arguments>>), where
x is the vector of parameters over
which the minimization takes place;
x should return a numeric vector
representing the lower triangle of the Hessian matrix with entries in the
order as given above under
gradient. As for
objective and
gradient,
users can accumulate information through attributes of the value of
hessian.
The function
hessian is always called immediately after a call to
gradient
with the same value of
x, and will not be used if
gradient is not
specified. If
gradient==NULL,
hessian==NULL, or
hessian==F, the
algorithm uses a quasi-Newton method to approximate curvature.
scale can have
a great effect on the performance of the algorithm, it is not known how to
choose it optimally. If
hessian is not supplied,
scale remains
constant throughout the optimization. If
hessian is supplied, automatic
updating of the
scale vector can be selected through
control. The default value
is unscaled:
scale=1.
nlminb.control.
NA or
NULL, or by
-Inf and
Inf. The default is unconstrained minimization:
lower=-Inf and
upper=Inf.
objective,
gradient and/or
hessian functions
successive parameter values are within a specified tolerance of each other.
hessian is supplied
initially.
The
nlminb command is intended for functions that have at least two continuous
derivatives on all of the feasible region, including the boundary. For best results, the gradient of the objective should be supplied whenever
possible. Supplying the Hessian matrix as well will sometimes, but not always,
lead to a substantial decrease in the number of iterations required
to reach a minimum. If the Hessian matrix is supplied, it is recommended
that it be computed within
gradient for greater efficiency. Function and derivative values should be computed in C or Fortran within
the outer S-PLUS function for greater efficiency.
The
nlminb function is based on the Fortran functions
dmnfb,
dmngb, and
dmnhb
(Gay (1983; 1984), A T & T (1984)) from NETLIB (Dongarra and Grosse (1987)).
A.T.&T. Bell Laboratories (1984). PORT Mathematical Subroutine Library Manual.
Dongarra, J.J. and Grosse, E. (1987). Distribution of mathematical software via electronic mail. Communications of the ACM 30: 403-407.
Gay, D.M. (1983). Algorithm 611. Subroutines for Unconstrained Minimization using a Model/Trust-Region Approach. ACM Transactions on Mathematical Software 9: 503-524.
Gay, D.M. (1984). A trust region approach to linearly constrained optimization. Numerical Analysis. Proceedings, Dundee 1983. Springer: Berlin.
# This example minimizes a sum of squares
# with known solution y.
sumsq <- function(x,y) {sum((x-y)^2)}
y <- rep(1,5)
x0 <- rnorm(length(y))
nlminb(start=x0, obj=sumsq, y=y)
# Now use bounds with a y that has some components
# outside the bounds.
y <- c( 0, 2, 0, -2, 0)
nlminb(start=x0, obj=sumsq, lower=-1, upper=1,
y=y)
# Try using the gradient.
sumsq.g <- function(x,y) {2*(x-y)}
nlminb(start=x0, obj=sumsq, grad=sumsq.g, lo=-1,
up=1, y=y)
# Now use the hessian, too.
sumsq.gh <- function(x,y)
{
n <- length(y)
i <- 1:n
ii <- (i*(i-1))/2 + i
l <- (n*(n+1))/2
list(gradient = 2*(x-y),
hessian = replace( rep(0,l), ii, 2))
}
nlminb(st=x0, obj=sumsq, grad=sumsq.gh, hes=T,
lo=-1, up=1, y=y)