OptimizationFunction
SciMLBase.OptimizationFunction
— TypeOptimizationFunction{iip,AD,F,G,H,HV,C,CJ,CH,HP,CJP,CHP,S,HCV,CJCV,CHCV} <: AbstractOptimizationFunction{iip}
A representation of an optimization of an objective function f
, defined by:
\[min_{u} f(u,p)\]
and all of its related functions, such as the gradient of f
, its Hessian, and more. For all cases, u
is the state and p
are the parameters.
Constructor
OptimizationFunction{iip}(f,adtype::AbstractADType=NoAD(); grad=nothing,hess=nothing,hv=nothing, cons=nothing, consj=nothing,consh=nothing, hessprototype=nothing,consjacprototype=nothing, conshessprototype = nothing, syms = nothing, hesscolorvec = nothing, consjaccolorvec = nothing, conshesscolorvec = nothing)
adtype
: see the section "Defining Optimization Functions via AD"grad(G,u,p)
orG=grad(u,p)
: the gradient off
with respect tou
hess(H,u,p)
orH=hess(u,p)
: the Hessian off
with respect tou
hv(Hv,u,v,p)
orHv=hv(u,v,p)
: the Hessian-vector product $rac{d^2 f}{du^2} v$.cons(res,x,p)
orres=cons(x,p)
: the equality constraints vector, where the constraints are satisfied whenres = 0
.cons_j(res,x,p)
orres=cons_j(x,p)
: the Jacobian of the equality constraints.cons_h(res,x,p)
orres=cons_h(x,p)
: the Hessian of the equality constratins, provided as and array of Hessians withres[i]
being the Hessian with respect to thei
th output oncons
.paramjac(pJ,u,p)
: returns the parameter Jacobian $rac{df}{dp}$.hess_prototype
: a prototype matrix matching the type that matches the Hessian. For example, if the Hessian is tridiagonal, then an appropriately sizedHessian
matrix can be used as the prototype and integrators will specialize on this structure where possible. Non-structured sparsity patterns should use aSparseMatrixCSC
with a correct sparsity pattern for the Hessian. The default isnothing
, which means a dense Hessian.cons_jac_prototype
: a prototype matrix matching the type that matches the constraint Jacobian. The default isnothing
, which means a dense constraint Jacobian.cons_hess_prototype
: a prototype matrix matching the type that matches the constraint Hessian. This is defined as an array of matrices, wherehess[i]
is the Hessian w.r.t. thei
th output. For example, if the Hessian is sparse, thenhess
is aVector{SparseMatrixCSC}
. The default isnothing
, which means a dense constraint Hessian.syms
: the symbol names for the elements of the equation. This should matchu0
in size. For example, ifu = [0.0,1.0]
andsyms = [:x, :y]
, this will apply a canonical naming to the values, allowingsol[:x]
in the solution and automatically naming values in plots.hess_colorvec
: a color vector according to the SparseDiffTools.jl definition for the sparsity pattern of thehess_prototype
. This specializes the Hessian construction when using finite differences and automatic differentiation to be computed in an accelerated manner based on the sparsity pattern. Defaults tonothing
, which means a color vector will be internally computed on demand when required. The cost of this operation is highly dependent on the sparsity pattern.cons_jac_colorvec
: a color vector according to the SparseDiffTools.jl definition for the sparsity pattern of thecons_jac_prototype
.cons_hess_colorvec
: an array of color vector according to the SparseDiffTools.jl definition for the sparsity pattern of thecons_hess_prototype
.
Defining Optimization Functions Via AD
While using the keyword arguments gives the user control over defining all of the possible functions, the simplest way to handle the generation of an OptimizationFunction
is by specifying an AD type. By doing so, this will automatically fill in all of the extra functions. For example,
OptimizationFunction(f,AutoZygote())
will use Zygote.jl to define all of the necessary functions. Note that if any functions are defined directly, the auto-AD definition does not overwrite the user's choice.
Each of the AD-based constructors are documented separately via their own dispatches.
iip: In-Place vs Out-Of-Place
For more details on this argument, see the ODEFunction documentation.
recompile: Controlling Compilation and Specialization
For more details on this argument, see the ODEFunction documentation.
Fields
The fields of the OptimizationFunction type directly match the names of the inputs.
Automatic Differentiation Construction Choice Recommendations
The choices for the auto-AD fill-ins with quick descriptions are:
AutoForwardDiff()
: The fastest choice for small optimizationsAutoReverseDiff(compile=false)
: A fast choice for large scalar optimizationsAutoTracker()
: Like ReverseDiff but GPU-compatibleAutoZygote()
: The fastest choice for non-mutating array-based (BLAS) functionsAutoFiniteDiff()
: Finite differencing, not optimal but always applicableAutoModelingToolkit()
: The fastest choice for large scalar optimizations
Automatic Differentiation Choice API
The following sections describe the Auto-AD choices in detail.
Missing docstring for AutoForwardDiff
. Check Documenter's build log for details.
Missing docstring for AutoFiniteDiff
. Check Documenter's build log for details.
Missing docstring for AutoReverseDiff
. Check Documenter's build log for details.
Missing docstring for AutoZygote
. Check Documenter's build log for details.
Missing docstring for AutoTracker
. Check Documenter's build log for details.
Missing docstring for AutoModelingToolkit
. Check Documenter's build log for details.