maxBFGS {maxLik} | R Documentation |
These functions are wrappers for optim
where the arguments are
compatible with maxNR
. Note that there is a
maxNR
-based BFGS implementation maxBFGSR
.
maxBFGS(fn, grad = NULL, hess=NULL, start, fixed = NULL, print.level = 0, iterlim = 200, constraints = NULL, tol = 1e-08, reltol=tol, finalHessian=TRUE, parscale=rep(1, length=length(start)), ... ) maxCG(fn, grad = NULL, hess = NULL, start, fixed = NULL, print.level = 0, iterlim = 500, constraints = NULL, tol = 1e-08, reltol=tol, finalHessian=TRUE, parscale = rep(1, length = length(start)), alpha = 1, beta = 0.5, gamma = 2, ...) maxSANN(fn, grad = NULL, hess = NULL, start, fixed = NULL, print.level = 0, iterlim = 10000, constraints = NULL, tol = 1e-08, reltol=tol, finalHessian=TRUE, cand = NULL, temp = 10, tmax = 10, parscale = rep(1, length = length(start)), random.seed = 123, ... ) maxNM(fn, grad = NULL, hess = NULL, start, fixed = NULL, print.level = 0, iterlim = 500, constraints = NULL, tol = 1e-08, reltol=tol, finalHessian=TRUE, 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, |
grad |
gradient of the function. Must have the parameter vector as
the first argument. If |
hess |
Hessian of the function. Not used by any of these methods, for
compatibility with |
start |
initial values for the parameters. |
fixed |
parameters that should be fixed at their starting values:
either a logical vector of the same length as argument |
print.level |
a larger number prints more working information. |
iterlim |
maximum number of iterations. |
constraints |
either |
tol, reltol |
the relative convergence tolerance (see
|
finalHessian |
how (and if) to calculate the final Hessian. Either
|
cand |
a function used in the |
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
|
random.seed |
an integer used to seed R's random number generator. This is to ensure replicability when the ‘Simulated Annealing’ method is used. Defaults to 123. |
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
|
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
|
... |
further arguments for |
The ‘state’ (or ‘seed’) of R's random number generator
is saved at the beginning of the maxSANN
function
and restored at the end of this function
so that this function does not affect the generation of random numbers
although the random seed is set to argument random.seed
and the ‘SANN’ algorithm uses random numbers.
Object of class "maxim":
maximum |
value of |
estimate |
best set of parameters found. |
gradient |
vector, gradient at parameter value |
gradientObs |
matrix of gradients at parameter value |
hessian |
value of Hessian at optimum. |
code |
integer. Success code, 0 is success (see
|
message |
character string giving any additional information returned by the optimizer, or NULL. |
fixed |
logical vector indicating which parameters are treated as constants. |
iterations |
two-element integer vector giving the number of
calls to |
type |
character string "BFGS maximisation". |
constraints |
A list, describing the constrained optimization
(
|
Ott Toomet otoomet@ut.ee, Arne Henningsen
optim
, nlm
, maxNR
,
maxBHHH
, maxBFGSR
.
# 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))