Define optimisers and their control parameters
mltoptim(
auglag = list(
kkt2.check = hessian, ### turn off/on numerical hessian
eps = abstol, ### absolute tolerance for _parameter_ updates
itmax = 1000L, ### max number of outer iterations
method = "BFGS", ### inner algorithm
maxit = 500L ### max number of inner (BFGS) iterations
),
spg = list(
ftol = abstol, ### absolute tolerance for _neg. logLik_
quiet = TRUE, ### don't talk
checkGrad = FALSE ### don't check analytical gradient
),
nloptr = list(
algorithm = "NLOPT_LD_MMA", ### inner algorithm
ftol_rel = reltol, ### relative change for _neg. logLik_
ftol_abs = abstol, ### absolute tolerance for _neg. logLik_
maxeval = 1000L ### max number of evaluations
),
constrOptim = list(
method = "BFGS", ### inner algorithm
maxit = 1000L, ### max number of inner (BFGS) iterations
outer.iterations = 500L, ### max number of outer iterations
mu = 1e-04, ### see ?constrOptim
outer.eps = reltol, ### relative change for _neg. logLik_
gradtol = .1, ### post-hoc check on gradient
control = list()
),
optim = list(
checkconstraints = TRUE, ### return -Inf if violated
method = "BFGS", ### inner algorithm
maxit = 1000L, ### max number of inner (BFGS) iterations
reltol = reltol, ### relative change for _neg. logLik_
gradtol = .1 ### post-hoc check on gradient
),
nlminb = list(
checkconstraints = TRUE, ### return -Inf if violated
iter.max = 200L, ### max number of iterations
eval.max = 200L, ### max number of function evaluations
rel.tol = 1e-10, ### relative change for _neg. logLik_
abs.tol = 1e-20, ### absolute tolerance (nll is not >= 0)
xf.tol = 1e-16
),
NewtonRaphson = list(
checkconstraints = TRUE, ### return -Inf if violated
iter.max = 200L, ### max number of iterations
objtol = 5e-4,
gradtol = 1e-5, #* N.global / 1000,
paramtol = 1e-5,
minstepsize = 1e-2,
tolsolve = .Machine$double.eps
),
activeset_nlminb = list(control = list(iter.max = 200L,
eps.tol = sqrt(.Machine$double.eps)),
nlminb = nlminb),
activeset_NewtonRaphson = list(control = list(iter.max = 200L,
eps.tol = sqrt(.Machine$double.eps)),
NewtonRaphson = NewtonRaphson),
abstol = 1e-07,
reltol = 1e-6,
trace = FALSE,
hessian = FALSE,
TOTP = FALSE,
verbose = FALSE)A list of functions with arguments theta (starting values), f (log-likelihood),
g (scores), h (Hessian), ui and ci (linear inequality constraints).
Adding further such functions is a way to add more optimisers to mlt.
The first one in this list converging defines the resulting model.
All procedures except optim, nlminb, and
NewtonRaphson perform constained optimisation. The
model is only defined for parameters meeting the constraints. For
parameter configurations not meeting the constraints, the resulting
log-likelihood is -Inf. This, however, does not mean that
unconstraint optimisation will always produce parameter estimates
which lead to valid models, so one should always check the unconstrained
(but probably faster obtained) result against the (slower) constrained
solution.
A list with control parameters for the auglag optimiser.
maxtry is the number of times the algorithm is re-started
in case it failed.
A list with control parameters for the BBoptim optimiser (calling
spg internally). Only available when BB is installed.
A list with control parameters for the nloptr
family of optimisers. Only available when nloptr is installed.
A list with control parameters for the constrOptim
optimiser.
A list with control parameters for the optim
optimiser producing an unconstrained fit.
A list with control parameters for the nlminb
optimiser producing an unconstrained fit.
A list with control parameters for the (now internal) NewtonRaphson stats optimiser producing an unconstrained fit.
A list with control parameters for the nlminb
optimiser producing an constrained fit via the active set method.
A list with control parameters for the (now internal) NewtonRaphson stats optimiser producing an constrained fit via the active set method.
Absolute and relative tolerances used as stopping criterion by various algorithms.
A logical switching trace reports by the optimisers on or off.
A logical indicating if a numerically differentiated Hessian matrix be returned.
A logical requesting to solve a problem by all suitable
optimisers. The resulting mlt object selects the best one (top of the
pops) and comes with a totp slot containing all results.
A logical switching printing of TOTP results on of off.
This function sets-up functions to be called in mlt internally.
### set-up linear transformation model for conditional
### distribution of dist given speed
dist <- numeric_var("dist", support = c(2.0, 100), bounds = c(0, Inf))
ctmm <- ctm(response = Bernstein_basis(dist, order = 4, ui = "increasing"),
shifting = ~ speed, data = cars)
### the numerically determined
### hessian is returned as "optim_hessian" slot
op <- mltoptim(hessian = TRUE)
mltm <- mlt(ctmm, data = cars, scale = FALSE, optim = op)
### compare analytical and numerical hessian
all.equal(c(Hessian(mltm)), c(mltm$optim_hessian), tol = 1e-4)
Run the code above in your browser using DataLab