| mize_step_summary {mize} | R Documentation |
Mize Step Summary
Description
Produces a result summary for an optimization iteration. Information such as function value, gradient norm and step size may be returned.
Usage
mize_step_summary(opt, par, fg, par_old = NULL, calc_fn = NULL)
Arguments
opt |
Optimizer to generate summary for, from return value of
|
par |
Vector of parameters at the end of the iteration, from return value
of |
fg |
Function and gradient list. See the documentation of
|
par_old |
(Optional). Vector of parameters at the end of the previous iteration. Used to calculate step size. |
calc_fn |
(Optional). If |
Details
By default, convergence tolerance parameters will be used to determine what function and gradient data is returned. The function value will be returned if it was already calculated and cached in the optimization iteration. Otherwise, it will be calculated only if a non-null absolute or relative tolerance value was asked for. A gradient norm will be returned only if a non-null gradient tolerance was specified, even if the gradient is available.
Note that if a function tolerance was specified, but was not calculated for
the relevant value of par, they will be calculated here and the
calculation does contribute to the total function count (and will be cached
for potential use in the next iteration). The same applies for gradient
tolerances and gradient calculation. Function and gradient calculation can
also be forced here by setting the calc_fn and calc_gr
(respectively) parameters to TRUE.
Value
A list with the following items:
-
optOptimizer with updated state (e.g. function and gradient counts). -
iterIteration number. -
fFunction value atpar. -
g2n2-norm of the gradient atpar. -
ginfnInfinity-norm of the gradient atpar. -
nfNumber of function evaluations so far. -
ngNumber of gradient evaluations so far. -
stepSize of the step betweenpar_oldandpar, ifpar_oldis provided. -
alphaStep length of the gradient descent part of the step. -
muMomentum coefficient for this iteration
Examples
rb_fg <- list(
fn = function(x) {
100 * (x[2] - x[1] * x[1])^2 + (1 - x[1])^2
},
gr = function(x) {
c(
-400 * x[1] * (x[2] - x[1] * x[1]) - 2 * (1 - x[1]),
200 * (x[2] - x[1] * x[1])
)
}
)
rb0 <- c(-1.2, 1)
opt <- make_mize(method = "BFGS", par = rb0, fg = rb_fg, max_iter = 30)
mize_res <- mize_step(opt = opt, par = rb0, fg = rb_fg)
# Get info about first step, use rb0 to compare new par with initial value
step_info <- mize_step_summary(mize_res$opt, mize_res$par, rb_fg, rb0)