| maxBFGS {maxLik} | R Documentation |
These functions are wrappers for optim where the arguments are
compatible with maxNR
maxBFGS(fn, grad = NULL, hess=NULL, start, print.level = 0, iterlim = 200, constraints, tol = 1e-08, reltol=tol, ... ) maxSANN(fn, grad = NULL, hess = NULL, start, print.level = 0, iterlim = 10000, constraints, tol = 1e-08, reltol=tol, temp = 10, tmax = 10, parscale = rep(1, length = length(start)), ...) maxNM(fn, grad = NULL, hess = NULL, start, print.level = 0, iterlim = 500, constraints, tol = 1e-08, reltol=tol, parscale = rep(1, length = length(start)), alpha = 1, beta = 0.5, gamma = 2, ...)
fn |
function to be maximised. Must have the parameter vector as
the first argument. In order to use numeric gradient
and BHHH method, fn must return vector of
observation-specific likelihood values. Those are summed by maxNR
if necessary. If the parameters are out of range, fn should
return NA. See details for constant parameters. |
grad |
gradient of the function. Must have the parameter vector as
the first argument. If NULL, numeric
gradient is used (only maxBFGS uses gradient). Gradient may return
a matrix, where columns correspond to the parameters and rows to the
observations (useful for maxBHHH). The columns are summed internally. |
hess |
Hessian of the function. Not used by any of these methods, for
compatibility with maxNR. |
start |
initial values for the parameters. |
print.level |
a larger number prints more working information. |
iterlim |
maximum number of iterations. |
constraints |
either NULL for unconstrained optimization
or a list with two components. The components may be either
eqA and eqB for equality-constrained optimization
A %*% theta + B = 0; or ineqA and
ineqB for inequality constraints A
%*% theta + B >= 0. The equality-constrained problem is forwarded
to sumt, the inequality-constrained case to
constrOptim.
|
tol, reltol |
the relative convergence tolerance (see
optim). tol is for compatibility with maxNR. |
temp |
controls the '"SANN"' method. It is the starting temperature for the cooling schedule. Defaults to '10'. |
tmax |
is the number of function evaluations at each temperature
for the '"SANN"' method. Defaults to '10'. (see
optim) |
parscale |
A vector of scaling values for the parameters.
Optimization is performed on 'par/parscale' and these should
be comparable in the sense that a unit change in any element
produces about a unit change in the scaled value. (see
optim) |
alpha, beta, gamma |
Scaling parameters for the
'"Nelder-Mead"' method. 'alpha' is the reflection factor
(default 1.0), 'beta' the contraction factor (0.5) and
'gamma' the expansion factor (2.0). (see
optim) |
... |
further arguments for fn and grad. |
Object of class "maxim":
maximum |
value of fn at maximum. |
estimate |
best set of parameters found. |
gradient |
gradient at parameter value estimate. |
hessian |
value of Hessian at optimum. |
code |
integer. Success code, 0 is success (see
optim). |
message |
character string giving any additional information returned by the optimizer, or NULL. |
activePar |
logical vector indicating which parameters are treated as free (currently all parameters). |
iterations |
two-element integer vector giving the number of
calls to fn and gr, respectively.
This excludes those calls needed to
compute the Hessian, if requested, and any calls to fn to compute a
finite-difference approximation to the gradient. |
type |
character string "BFGS maximisation". |
constraints |
A list, describing the constrained optimization
(NULL if unconstrained). Includes the following components:
|
Ott Toomet otoomet@ut.ee
# Maximum Likelihood estimation of the parameter of Poissonian distribution
n <- rpois(100, 3)
loglik <- function(l) n*log(l) - l - lfactorial(n)
# we use numeric gradient
summary(maxBFGS(loglik, start=1))
# you would probably prefer mean(n) instead of that ;-)
# Note also that maxLik is better suited for Maximum Likelihood
###
### Now an example of constrained optimization
###
f <- function(theta) {
x <- theta[1]
y <- theta[2]
exp(-(x^2 + y^2))
## Note: you may want to use exp(- theta %*% theta) instead ;-)
}
## use constraints: x + y >= 1
A <- matrix(c(1, 1), 1, 2)
B <- -1
res <- maxNM(f, start=c(1,1), constraints=list(ineqA=A, ineqB=B),
print.level=1)
print(summary(res))