Customization
Subtypes of Downhill.Wrapper
are used to add custom behavior to optimization, such as stopping after reaching certain criteria, limiting timesteps etc.
A wrapper around an object of AbstractOptBuffer
type should at a minimum provide the base_method(M::Wrapper)
to return the wrapped object.
The wrappers can modify the optimization behavior by overloading the following methods:
Downhill.init!
— Functionoptfn!
must be the 3-arg closure that computes fdf(x + α*d) and overwrites M
's gradient
Downhill.callfn!
— Functioncallfn!(fdf, M::AbstractOptBuffer, x, α, d)
Return the value of fdf(x + α * d)
overwriting the internal buffers of M
as needed. fdf(x, g)
must return a tuple (f(x), ∇f(x)) and, if g
is mutable, overwrite it with the gradient (see optimize!
).
Downhill.reset!
— Functionreset!(M::AbstractOptBuffer, args...; kwargs...)
Reset the solver parameters to the default (or to specific value – see the documentation for the specific types).
Each method has to implement a parameter-free reset!(M)
method.
Downhill.step!
— Functionstep!(fdf, M::AbstractOptBuffer; kw...)
Make one iteration of optimization routine from the current state of M
using fdf
as the objective function and modifying the internal buffers as needed.
Downhill.stopcond
— Functionstopcond(M::AbstractOptBuffer)
Decide if the optimization should be stopped from the state of M
.
Downhill.conv_success
— Functionconv_success(M::AbstractOptBuffer)
Decide if the optimization has converged from the state of M
(useful to distinguish between stopping by convergence and stopping by iterations count when the convergence has been achieved on the limiting iteration).
Predefined Wrappers
Downhill.BasicConvergenceStats
— TypeBasicConvergenceStats
Wrapper type to provide basic stop conditions: magnitude of gradient is less than the specified value, objective function call count exceeds threshold, iteration count exceeds threshold.
Downhill.ConstrainStepSize
— TypeConstrainStepSize
Wrapper type to limit step sizes attempted in optimization, given a function (origin, direction) -> max_step
.