Builds the control list of inla_vanilla(): the limits of the mode
search, of the VB correction and of the skew-normal scans. The defaults suit
most fits. A plain list with some of these names works too, and is checked
by the same rules: control = list(n_grid = 31) is
control = vanilla_control(n_grid = 31).
Usage
vanilla_control(
mode_maxit = 5000L,
mode_maxeval = 5000L,
mode_tol = 1e-10,
vb_maxit = 25L,
vb_tol = 0.001,
vb_budget = 2,
n_grid = 21L,
log_threshold = -6,
nlminb = list()
)Arguments
- mode_maxit, mode_maxeval
The most iterations, and evaluations of
logpost, of the mode search bystats::nlminb()(itsiter.maxandeval.max). When the search stops short of the mode, it is restarted once, with each parameter scaled by its curvature and the same limits.- mode_tol
The relative tolerance of the mode search (the
rel.tolofstats::nlminb()).- vb_maxit, vb_tol
The iteration limit and the convergence tolerance, in posterior SDs, of the fixed-point iteration of the VB correction, with
vb_correction = "full"and when a one-step correction has to iterate. A step over 1.5 posterior SDs is cut to 1.5. Withvb_correction = "full", if two steps in a row are cut, or it has not converged aftervb_maxitsteps,stats::nlminb()takes over. They also limit the solve that follows a failed check of a one-step correction, and a first step belowvb_tolin every parameter is not checked.- vb_budget
The most that the default VB correction (
vb_correction = "onestep") may spend when its check fails and it solves the VB equation, as a multiple of the calls that the mode and Hessian took. The sweeps of the correction, the two of the check among them, are capped atvb_budgettimes those calls over 2m + 1. Withhess,stats::nlminb()usually makes fewer calls, so the cap is lower than withgradalone, and a fit that fails the check can stop its solve sooner and land elsewhere. A larger value narrows that difference, andInfremoves it. A Hessian that a package gives at the mode alone, throughhess_mode, an argument ofvanilla_core()for packages that copy the engine and not ofinla_vanilla()(seevignette("engine", package = "inlavanilla")), counts as the central differences ofgradthat it replaces, so the cap is almost always the same as without it. The engine works out the step search of those differences with no call, and near a test value of that search, rounding can make the count, and so the cap, differ slightly. The default of 2 lets the solve of most hard fits reach its root. A larger value, orInffor no cap, lets it run on untilvb_tolorvb_maxit, and 0 leaves a fit that fails the check at its mode. A fit that passes the check takes two sweeps whatever the value. See "The VB correction" ininla_vanilla().- n_grid
The number of points of each skew-normal scan, spread over \(\pm 4\) posterior SDs. At least 7.
- log_threshold
Scan points whose log-posterior falls more than this below the maximum are left out of the skew-normal fit.
- nlminb
A named list of any other controls of
stats::nlminb()for the mode search, such astrace = 1, which prints its iterations, orabs.tol. Itsiter.max,eval.maxandrel.tolstand in formode_maxit,mode_maxevalandmode_tol, which must then be left at their defaults. It does not reach the fallback optimiser of the VB correction or the conditional optimisations ofmarginal_scan = "laplace", which keep limits of their own.
Value
A list with an entry for each argument, for the control argument
of inla_vanilla().
Examples
set.seed(1)
y <- rnorm(30, mean = 5, sd = 2)
logpost <- function(theta) {
sigma <- exp(theta[["log_sigma"]])
sum(dnorm(y, theta[["mu"]], sigma, log = TRUE)) +
dnorm(theta[["mu"]], 0, 10, log = TRUE) +
dexp(sigma, log = TRUE) + theta[["log_sigma"]]
}
# A finer scan of each marginal
fit <- inla_vanilla(
logpost,
c(mu = 0, log_sigma = 0),
control = vanilla_control(n_grid = 41),
silent = TRUE
)
# The same as a plain list
fit <- inla_vanilla(
logpost,
c(mu = 0, log_sigma = 0),
control = list(n_grid = 41),
silent = TRUE
)
# Print the iterations of the mode search
vanilla_control(nlminb = list(trace = 1))
#> $mode_maxit
#> [1] 5000
#>
#> $mode_maxeval
#> [1] 5000
#>
#> $mode_tol
#> [1] 1e-10
#>
#> $vb_maxit
#> [1] 25
#>
#> $vb_tol
#> [1] 0.001
#>
#> $vb_budget
#> [1] 2
#>
#> $n_grid
#> [1] 21
#>
#> $log_threshold
#> [1] -6
#>
#> $nlminb
#> $nlminb$trace
#> [1] 1
#>
#>
