trust minimizes (or maximizes) a smooth objective function for which
value, gradient and Hessian are available. It solves a Moré-Sorensen
trust-region subproblem exactly, via the full eigendecomposition of the
Hessian.
Usage
trust(
objfun,
parinit,
rinit = 0.1,
rmax = 10,
iterlim = 1000L,
hessianMethod = c("gn", "bfgs", "sr1", "exact", "sbfgs", "ssr1", "gnsbfgs", "gnssr1"),
phases = NULL,
switches = NULL,
parupper = NULL,
parlower = NULL,
boundary = c("reflective", "clip"),
tolControl = NULL,
qnControl = NULL,
stepControl = NULL,
minimize = TRUE,
blather = FALSE,
printIter = FALSE,
traceFile = NULL,
sparse = "auto",
...
)
trustL1(
objfun,
parinit,
mu = 0 * parinit,
one.sided = FALSE,
lambda = 1,
rinit = 0.1,
rmax = 10,
iterlim = 1000L,
parupper = NULL,
parlower = NULL,
boundary = c("reflective", "clip"),
tolControl = NULL,
stepControl = NULL,
minimize = TRUE,
blather = FALSE,
printIter = FALSE,
traceFile = NULL,
gate = NULL,
fuse = NULL,
...
)Arguments
- objfun
Function whose first argument is a numeric vector of parameters, returning a list with components
value,gradientandhessian. It is called with the logical argumentsderivandhessian, and withderiv2 = TRUEwhen an exact Hessian is requested, so it must accept them or....trustL1calls it with the parameters and...only.- parinit
Named numeric starting vector. Must be finite. Values outside
[parlower, parupper]are clipped with a warning; withboundary = "reflective"they are moved just inside the box.- rinit
Initial trust-region radius. Default
0.1.- rmax
Maximum trust-region radius. Default
10.- iterlim
Maximum number of trust-region iterations over all phases. Default
1000.- hessianMethod
Source of the model Hessian of a run without
phases:"gn"the Gauss-Newton Hessian of the objective,"bfgs"or"sr1"a quasi-Newton update seeded asqnControl$hessianInitsays,"exact"the true Hessian at every iterate, which needs an objective that takesderiv2. The structured methods take the Gauss-Newton Hessian at every iterate and add a correction learned from the steps, starting at zero:"sbfgs"by a BFGS update,"ssr1"by an SR1 update, which may be indefinite;"gnsbfgs"and"gnssr1"switch at every accepted step between the Gauss-Newton Hessian alone and the structured BFGS or SR1 model. They count as quasi-Newton phases for the stops andqnEval. The correction is learned from the secant of Dennis, Martínez and Tapia on the data rows that an objective of classobjfnreturns withhessian = "structured", seeobjlist(); without them from the gradient and the Gauss-Newton Hessian. The formulas are in the methods article. All but"gn"requireboundary = "reflective". Also selects the control defaults below. Withphases, each phase names a method, and this argument is an error. Not given: the hybrid of section Default method.- phases
List of phases, each a list of settings, run one after the other and from the first again after the last. The run hands over to the next phase at a value, model, step or stagnation stop, when a phase uses up the
iterlimof that phase and when the radius stayed the same forradiusStalliterations. A handover restarts the trust region atrinit, unlesskeepRadius, and discards the quasi-Newton pairs. DefaultNULL: one phase fromhessianMethodandqnControl, evaluated with thesweepin..., or the phases of section Default method. Names of the list label the phases in the result, the Hessian source does otherwise. Not available with multiple shooting andboundary = "clip".hessianMethodHessian source of the phase, as
hessianMethod. Required.iterlimMaximum number of iterations of one run of the phase. Default
NULL: only the totaliterlim.radiusStallNumber of consecutive iterations that leave the trust radius unchanged after which the phase hands over, the switch of the hybrid method of Fides (Fröhlich and Sorger 2022), which takes 20 for a Gauss-Newton phase followed by BFGS. The count starts anew with every change of the radius and at a handover; without a handover left it ends nothing. Default
NULL: no such handover.sweep"forward"or"reverse", thesweepthe objective is evaluated with in the phase; asweepin...is an error withphases. DefaultNULL: for"bfgs"and"sr1"reverse if the objective can be evaluated backwards atparinit, as withderivMode = c("forward", "reverse")throughout the chain, forward otherwise. A Gauss-Newton Hessian is always computed forward, also in the structured methods. A handover between phases of different sweep evaluates the current iterate once more. The result reports the sweeps asphaseSweep.keepRadiusTRUEstarts the phase at the trust radius of the handover instead ofrinit. DefaultFALSE.onStopWhat a value, model, step or stagnation stop does in the phase:
"handover"(default) hands over whileswitchesremain,"end"ends the run. A phase that ends on stops hands over atiterlimandradiusStallonly.qnControlQuasi-Newton settings of the phase, merged over
qnControl; see there.hessianInitdefaults to"gn"in every phase but the first: a quasi-Newton phase starts from the Gauss-Newton Hessian at the iterate of the handover."tracked", for a"bfgs"phase after the first withqnMemory = 0, starts it from a BFGS matrix kept over the whole run instead: the Hessian atparinitof the first phase, made positive definite as a BFGS seed is, updated with the accepted steps of the phases before, under theqnCautioustest of the phase, and updated on in the phase itself. Not available on the sparse path.
- switches
Number of handovers allowed. Default
NULL: one fewer than there are phases, so each runs once. A higher value cycles through the phases again,0runs the first phase only. The result reports the count asnSwitch.- parupper, parlower
Upper and lower bounds. Unnamed: the first element applies to all parameters. Named: entries are matched by name, missing parameters are unbounded. Default
NULL, unbounded.- boundary
Box-bound handling,
"reflective"(default) or"clip". See section Box bounds.- tolControl
List of convergence thresholds, merged into the defaults.
ftolChange in objective value. Default
1e-6.mtolPredicted model decrease, of the step taken and, at a convergence stop, of the full Newton step (section Convergence).
0switches off both the model test and the condition on the full Newton step. Default1e-6.gtolFirst-order optimality measure. Default
1e-6.xtolStep norm. Default
0, disabled.rminLower limit on the trust radius; falling below it stops the run with
converged = FALSE. Default0, disabled.ctolMultiple shooting only: scaled gap size below which the trajectory counts as continuous; no other test stops the run before. Default
1e-6.
trustL1readsftol,mtol,gtol,xtolandrmin.- qnControl
List of quasi-Newton settings, merged into the defaults and read in a quasi-Newton or structured phase;
hessianInitalso in a first phase of source"gn". A structured phase takeshessianInit = "gn"andqnMemory = 0only.hessianInitSeed of the approximation:
"gn"(default) the Gauss-Newton Hessian atparinit;"identity"the identity matrix, after which the objective is asked for gradients only until a reseed;"exact"the true Hessian atparinit, then gradients only."exact"needsderiv2 = TRUEin a call, seederivModeinodemodel(). In a first phase of source"gn","exact"makes the first step use the exact Hessian atparinit.hessianReseed"never"(default): a stalled quasi-Newton phase, or one whose trust radius collapses, stops."stall": it continues from a fresh Hessian at the current iterate, the exact one withhessianInit = "exact"and the Gauss-Newton one otherwise, provided the iterate moved since the last reseed. The result reports the count asnReseed.qnMemoryNumber of
(s, y)pairs kept. Default0: every update accumulates onto the seed. A positive value rebuilds the approximation in each iteration from the lastqnMemorypairs, without the seed. On the sparse path, seesparse, BFGS keeps the lastqnMemorypairs, 10 where it is0, on top of the seed.qnCautiousA BFGS pair is used only when \(s^\top y > c\,|s|\,|y|\) with \(c\) =
qnCautious. Default1e-8,0disables the test; also read by"sbfgs", the SR1 methods are exempt. The result reports the rejected pairs asqnSkipped.qnRejectedWhether an SR1 method also updates from a rejected trial point. Default
TRUEfor a phase whose source is"sr1","ssr1"or"gnssr1",FALSEotherwise.qnScaling"none"(default) or"residual":"sbfgs"and"ssr1"scale the correction with the residual norm, the norm of the derivatives of the value in the predictions and sigmas of the data, or the square root of the value for an objective without data rows, so it vanishes with the residuals (Huschens). Read by these two methods only.qnHybridTolThreshold of the switch of
"gnsbfgs"and"gnssr1": below it the model is the Gauss-Newton Hessian. Default1e-6.qnHybridShiftTRUEadds the residual norm times the identity to the Gauss-Newton Hessian on the Gauss-Newton branch of"gnsbfgs"and"gnssr1", as Zhou and Chen; defaultFALSE.
- stepControl
List of step and acceptance settings, merged into the defaults.
thetaMaxSmallest fraction of the distance to a bound a step may use. The fraction is
max(thetaMax, 1 - m), below 1, withmthe first-order optimality measure. Default0.99995.boundary = "reflective"only.nonmonotoneZhang-Hager relaxation in
[0, 1): a step is rated against a weighted average of past objective values and may increase the objective. Default0, monotone.acceptanceMultiple shooting only:
"filter"(default), the filter of Fletcher and Leyffer on objective and gap size;"merit", the l2 exact penalty;"natural", Bock's natural level function, which needshessianMethod = "gn", a fixed sigma and no error model.twoPhaseMultiple shooting only: if
TRUE, the parameters are first fitted with the node values held fixed, then the nodes are laid out afresh and released. DefaultFALSE.restoreMultiple shooting only: if
TRUE, a run whose steps keep being rejected with open gaps enters a restoration phase, at most five times. DefaultFALSE.regularizeMultiple shooting only: directions of the condensed problem with a singular value below
regularizetimes the largest are held fixed in a step. Default0, off. Withacceptance = "natural"directions below1e-7are always held fixed.socMultiple shooting only: if
TRUE, a rejected step whose gaps did not close as predicted is retried once with a second-order correction. DefaultTRUE.annealMultiple shooting only: if
TRUE, the run first minimizes the objective plus a rising penalty on the gaps, then enforces continuity. Needs forward sensitivities and is skipped without them. DefaultTRUE.
trustL1takesthetaMaxonly.- minimize
If
TRUE(default) minimize, ifFALSEmaximize.- blather
If
TRUE, the result also contains the per-iteration trace listed under Value. DefaultFALSE.- printIter
If
TRUE, print the number of the evaluation and the objective value at each evaluation. DefaultFALSE.- traceFile
Path of a CSV file written with one row per evaluation: the number of the evaluation (column
Iteration), objective value and parameters. DefaultNULL, no file.- sparse
"auto"(default),TRUEorFALSE.TRUEcallsobjfunwithhessian = "sparse"and solves every subproblem on sparse Cholesky factors of the returnedMatrix, a low-rank partlowrank(seeobjlist()) included; on the Hessian of the objective the steps equal those of the dense path to rounding. It needshessianMethod"gn"or"exact", or"bfgs"withqnControl$hessianInit = "gn", in every phase, andboundary = "reflective". A BFGS phase there is limited-memory BFGS: the Hessian of the objective at the start of the phase plus the compact correction of the lastqnMemorypairs (Byrd, Nocedal and Schnabel 1994), a low-rank part of rank twice the number of pairs."auto"takes the sparse path where every phase takes the Hessian of the objective, outside multiple shooting, for at leastparametersentries ofparinitand a step cheaper than the dense one atparinit; the settings come fromgetOption("dMod2.sparseAuto"), see dMod2-package.- ...
Further named arguments passed to
objfun.- mu
Named numeric vector of reference values for the L1-penalized parameters. Names must be a subset of
names(parinit); only the named parameters receive a penalty. Withboundary = "reflective"each must lie strictly inside[parlower, parupper]. Defaults to a zero vector covering all ofparinit.- one.sided
Logical. If
TRUE, the penalty is one-sided,lambda * max(0, mu - p): only values belowmuare penalized. Otherwise it is the symmetriclambda * |p - mu|.- lambda
Strength of the L1 penalty. Either a scalar (broadcast to all entries of
mu) or a named numeric aligned withmu.- gate
Character, names in
muwhose penalty is the gatelambda * (p - mu)withp >= mu: the parameter can sit exactly onmuand leaves it only upward. Starts belowmuare moved onto it. Needsboundary = "reflective".- fuse
List of fusion blocks. A block penalizes
lambda * sum_{i<j} w_ij |p_i - p_j|over the parameters of the block, pluslambda * w_ia |p_i - a|toward an optional anchora. Parameters with equal values move as one and split again when the data pull them apart. A block is a character vector of parameter names or a list withpars, and optionallylambda(default: the scalarlambda),anchor(default none) andweights, an(m+1) x (m+1)matrix whose last row and column refer to the anchor (default all 1). Fused parameters must not appear inmu; iffuseis given andmuis not,muis empty. Needsboundary = "reflective".
Value
A list of class trustfit with components
argumentNamed numeric, the best iterate.
value,gradient,hessianObjective value, gradient and model Hessian at
argument.iterationsNumber of iterations.
nevalNumber of objective evaluations.
qnEvalEvaluations spent in a quasi-Newton phase.
qnSkippedPairs rejected by the cautious test, and in a structured phase pairs that left the correction unchanged.
nSwitchNumber of handovers between phases.
phaseIterationsNamed integer, the iterations of each phase run, in run order and named after the phase. The sum is
iterationswithout the iteration that ends the run on failed evaluations and without the iterations that reseed instead of taking a step.phaseSweepNamed character, the sweep of each element of
phases, present whenphasesis set and in the default hybrid.nReseedNumber of reseeds by
qnControl$hessianReseed = "stall", which allows each run of a phase the same number.hybridGNAccepted steps of a
"gnsbfgs"or"gnssr1"phase after which the model is the Gauss-Newton Hessian.evalBySourceNamed integer, evaluations per Hessian source.
convergedLogical.
atBoundNamed logical, the parameters held by a bound.
stopReasonThe test that ended the run, see section Convergence.
With blather = TRUE the list also contains the matrices
argpath (accepted iterates) and argtry (trial points), one
row per iteration, and the per-iteration vectors steptype,
stepback, accept, r (radius), rho (ratio of
actual to predicted reduction), valpath, valtry,
preddiff, stepnorm and, with
boundary = "reflective", hessianSource, which is
"gn" for an iteration of a hybrid method on the Gauss-Newton
Hessian.
boundary = "clip" returns only argument, value,
gradient, hessian, iterations, converged,
atBound and stopReason, plus the trace.
On the sparse path, see sparse, hessian is a sparse
Matrix, and lowrank where the objective returns one or a
BFGS phase adds the correction: the Hessian is then hessian plus
that part.
trustL1 returns a list without class with argument,
value, gradient, hessian, iterations,
converged, atBound and stopReason, plus the trace
without hessianSource. value and gradient include the
penalty, whose gradient counts zero on a kink; hessian is that of
objfun.
A multiple-shooting run returns argument, value,
gradient, hessian, iterations, neval,
qnSkipped, converged, stopReason, atBound and
a list multipleShooting with the final nodes, the
gaps per condition, their scaled size violation, the counts
nRelaxed (iterations with a node step below the full one),
nSOC (accepted second-order corrections), nSplit (segments
cut), nRestore (restoration phases) and nStages (annealing
stages), the cuts, the acceptance and sweep used,
mu (merit) or filterSize (filter), and trace when
blather = TRUE.
Default method
Without hessianMethod, phases, switches and a
sweep in ..., trust runs the hybrid method of Fides
(Fröhlich and Sorger 2022): Gauss-Newton until the trust radius stayed the
same for 20 consecutive iterations, then BFGS for the rest of the run. The
BFGS approximation starts from the Gauss-Newton Hessian at parinit,
made positive definite, takes every accepted step of the Gauss-Newton phase
as an update, and the trust radius stays at the switch. These are the
phases
list(gn = list(hessianMethod = "gn", radiusStall = 20, onStop = "end"),
bfgs = list(hessianMethod = "bfgs", sweep = "forward", keepRadius = TRUE,
qnControl = list(hessianInit = "tracked")))The run is Gauss-Newton alone, as with hessianMethod = "gn", where
phases are not available (multiple shooting, boundary = "clip") and
on the sparse path, see sparse.
Box bounds
boundary = "reflective" (default) uses the interior
trust-region-reflective scheme of Coleman and Li. Iterates stay strictly
inside the box and never land exactly on a bound; atBound in the
result reports which parameters a bound holds.
boundary = "clip": active-set reduction with componentwise clipping,
with a single "gn" phase. The run stops when a trial point, accepted
or not, changes the value by less than ftol or has a predicted
reduction below mtol, both reported as stopReason = "fvalue".
gtol, xtol, rmin and stagnation are not tested; three
failed evaluations in a row end the run with stopReason = "iterlim".
Convergence
With boundary = "reflective" the run stops as soon as one of the
following holds. The gradient test is
evaluated at the current iterate; the value and step tests count only on an
accepted step, the model test also on a rejected Newton step from inside the
trust region.
gtol: the first-order optimality measure \(\max_i |v_i g_i|\) is at mostgtol, with \(v_i\) the distance to the bound in the descent direction \(-g_i\), 1 if that bound is infinite. Without bounds it is \(\max_i |g_i|\).ftol: \(|f - f_{\mathrm{try}}| <\)ftol.mtol: the predicted reduction \(|g^\top p + \frac{1}{2} p^\top H p| <\)mtol.xtol: the step norm is belowxtol.stagnation: five consecutive rejected steps left the objective flat within
ftol.rmin: the trust radius is belowrmin, or a step no longer changes the parameters in floating point. Reportsconverged = FALSE.
A "gradient", "fvalue" or "preddiff" stop that ends the run
also needs the full Newton step of the model at the current iterate to
predict a decrease of at most mtol,
\(\frac{1}{2} g^\top H^{+} g \le\) mtol, in the variables scaled
for the bounds. \(H^{+}\) is the pseudoinverse of the positive part of
\(H\) in the eigenbasis; with sparse = TRUE the decrease comes
from the factorization of \(H\) where \(H\) is positive definite and
from the dense eigendecomposition elsewhere. trustL1 applies the
same condition to the model of the coordinates not held at a kink. Without
the condition the run goes on, within iterlim; mtol = 0
drops the condition. A run that goes on this way and then ends on the
radius without an accepted step that changes the value by ftol or
more ends on the stop held back, with converged = TRUE: the decrease
the model predicts is below the resolution of the objective.
stopReason in the result names the test that fired:
"gradient", "fvalue", "preddiff", "step",
"stagnation", "radius", "objfun" (three failed
evaluations in a row, ten with multiple shooting) or "iterlim".
Stagnation reports converged = TRUE where the full Newton step
predicts a decrease of at most mtol or a stop was held back as
above, and converged = FALSE otherwise.
Only gtol tests first-order optimality. While switches
remain, see phases, an "fvalue", "preddiff",
"step" or "stagnation" stop hands over to the next phase
instead of ending the run. In a quasi-Newton phase "fvalue",
"preddiff" and "step" do not end the run. A phase that
reaches the iterlim of that phase ends like a soft stop, with
stopReason = "iterlim" and converged = FALSE when no
handover is left. The total iterlim ends the run in any phase, with
stopReason = "iterlim" and converged = FALSE.
argument, value, gradient, hessian and
atBound in the result belong to the best iterate visited, which is
the last accepted one when stepControl$nonmonotone = 0.
Multiple shooting
An objective built by normL2(..., multipleShootingControl = ),
alone or in a sum, is optimized by multiple shooting with the same controls.
Not available then: hessianMethod = "exact" and the structured
methods, more than one phase,
switches, qnControl$hessianInit = "exact",
qnControl$hessianReseed, qnControl$qnMemory,
stepControl$nonmonotone,
boundary = "clip", minimize = FALSE and traceFile.
The run reports converged = TRUE only when the scaled gaps between
the segments are below tolControl$ctol. The stops follow section
Convergence, with the full step of the condensed model as the Newton step;
stagnation also needs the gaps flat within ctol. The method is
described in
the methods article
Multiple shooting.
References
Byrd, R. H., Nocedal, J. and Schnabel, R. B. (1994). Representations of quasi-Newton matrices and their use in limited memory methods. Mathematical Programming 63, 129-156.
Coleman, T. F. and Li, Y. (1996). An interior trust region approach for nonlinear minimization subject to bounds. SIAM Journal on Optimization 6(2), 418-445.
Fröhlich, F. and Sorger, P. K. (2022). Fides: Reliable trust-region optimization for parameter estimation of ODE models. PLoS Computational Biology 18(7), e1010322.
Bock, H. G. (1983). Recent advances in parameter identification techniques for ODE. In Numerical Treatment of Inverse Problems in Differential and Integral Equations, 95-121. Birkhäuser.
Fletcher, R. and Leyffer, S. (2002). Nonlinear programming without a penalty function. Mathematical Programming 91, 239-269.
Horbelt, W., Timmer, J. and Voss, H. U. (2002). Parameter estimation in nonlinear delayed feedback systems from noisy data. Physics Letters A 299, 513-521.
Voss, H. U., Timmer, J. and Kurths, J. (2004). Nonlinear dynamical system identification from uncertain and indirect measurements. International Journal of Bifurcation and Chaos 14(6), 1905-1933.
Dennis, J. E., Martínez, H. J. and Tapia, R. A. (1989). Convergence theory for the structured BFGS secant method with an application to nonlinear least squares. Journal of Optimization Theory and Applications 61(2), 161-178.
Huschens, J. (1994). On the use of product structure in secant methods for nonlinear least squares problems. SIAM Journal on Optimization 4(1), 108-129.
Zhou, W. and Chen, X. (2010). Global convergence of a new hybrid Gauss-Newton structured BFGS method for nonlinear least squares problems. SIAM Journal on Optimization 20(5), 2422-2441.
Peifer, M. and Timmer, J. (2007). Parameter estimation in ordinary differential equations for biochemical processes using the method of multiple shooting. IET Systems Biology 1(2), 78-88.
See also
mstrust() for multi-start fits, profile() for
profile likelihoods, normL2() for the objective,
the guide chapter
Optimization, the methods
article Trust-region optimization.
Examples
rosenbrock <- function(x, ...) {
a <- x[["a"]]
b <- x[["b"]]
list(value = 100 * (b - a^2)^2 + (1 - a)^2,
gradient = c(a = -400 * a * (b - a^2) - 2 * (1 - a),
b = 200 * (b - a^2)),
hessian = matrix(c(1200 * a^2 - 400 * b + 2, -400 * a, -400 * a, 200),
2, 2, dimnames = list(c("a", "b"), c("a", "b"))))
}
fit <- trust(rosenbrock, c(a = -1.2, b = 1), iterlim = 200)
fit$argument
#> a b
#> 1 1
fit$stopReason
#> [1] "fvalue"
# With an upper bound on a
fit <- trust(rosenbrock, c(a = -1.2, b = 1), parupper = c(a = 0.5),
iterlim = 200)
fit$atBound
#> a b
#> TRUE FALSE
# Gauss-Newton, then BFGS with a separate budget, then Gauss-Newton again
fit <- trust(rosenbrock, c(a = -1.2, b = 1), iterlim = 200,
phases = list(list(hessianMethod = "gn"),
list(hessianMethod = "bfgs", iterlim = 50)),
switches = 2)
fit$phaseIterations
#> gn bfgs
#> 26 0
fit$evalBySource
#> gn bfgs sr1 exact sbfgs ssr1 gnsbfgs gnssr1
#> 27 0 0 0 0 0 0 0