Initialization
Before we can use update! we have to initialize with SimpleSolvers.initialize![1].
Similar to update!, SimpleSolvers.initialize! returns the first input argument as output. Examples include:
SimpleSolvers.initialize!(::Hessian, ::AbstractVector): this routine exists for mostHessians, i.e. forHessianFunction,HessianAutodiff,HessianBFGSandHessianDFP,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.H3×3 Matrix{Float64}:
NaN NaN NaN
NaN NaN NaN
NaN NaN NaNFor an instance of SimpleSolvers.NewtonOptimizerCache[2]:
cache = SimpleSolvers.NewtonOptimizerCache(x)
initialize!(cache, x)
cache.g3-element Vector{Float64}:
NaN
NaN
NaNClear Routines
For SimpleSolvers.OptimizerResult and SimpleSolvers.OptimizerStatus the SimpleSolvers.clear! routines are used instead of the SimpleSolvers.initialize! routines.
Reasoning behind Initialization with NaNs
We initialize with NaNs instead of with zeros (or other values) as this clearly divides the initialization from the numerical operations (which are done with 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.NewtonOptimizerCachehas five keys:x,x̄,δ,gandrhs. All of them are initialized withNaNs except forx. We also remark that the constructor, which is called by providing a single vectorxas input argument, internally also callsSimpleSolvers.initialize!.