Initialization
Before we can use SimpleSolvers.update!
we have to initialize with SimpleSolvers.initialize!
[1].
Similar to SimpleSolvers.update!
, SimpleSolvers.initialize!
returns the first input argument as output. Examples include:
SimpleSolvers.initialize!(::Hessian, ::AbstractVector)
: this routine exists for mostHessian
s, i.e. forHessianFunction
,HessianAutodiff
,HessianBFGS
andHessianDFP
,SimpleSolvers.initialize!(::SimpleSolvers.NewtonSolverCache, ::AbstractVector)
,SimpleSolvers.initialize!(::SimpleSolvers.NonlinearSolverStatus, ::AbstractVector, ::Base.Callable)
,SimpleSolvers.initialize!(::SimpleSolvers.NewtonOptimizerCache, ::AbstractVector)
.
We demonstrate these examples in code. First for an instance of SimpleSolvers.Hessian
:
using LinearAlgebra: norm
x = rand(3)
obj = MultivariateObjective(x -> norm(x - vcat(0., 0., 1.)) ^ 2, x)
hes = Hessian(obj, x; mode = :autodiff)
initialize!(hes, x)
hes.H
3×3 Matrix{Float64}:
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
For an instance of SimpleSolvers.NewtonOptimizerCache
[2]:
cache = SimpleSolvers.NewtonOptimizerCache(x)
initialize!(cache, x)
cache.g
3-element Vector{Float64}:
NaN
NaN
NaN
Clear Routines
For SimpleSolvers.OptimizerResult
and SimpleSolvers.OptimizerStatus
the SimpleSolvers.clear!
routines are used instead of the SimpleSolvers.initialize!
routines.
Reasoning behind Initialization with NaN
s
We initialize with NaN
s instead of with zeros (or other values) as this clearly divides the initialization from the numerical operations (which are done with SimpleSolvers.update!
).
Alloc Functions
- 1The different methods for
SimpleSolvers.initialize!
are however often called with the constructor of astruct
(e.g. forSimpleSolvers.NewtonOptimizerCache
). - 2Here we remark that
SimpleSolvers.NewtonOptimizerCache
has five keys:x
,x̄
,δ
,g
andrhs
. All of them are initialized withNaN
s except forx
. We also remark that the constructor, which is called by providing a single vectorx
as input argument, internally also callsSimpleSolvers.initialize!
.