Skip to content

Commit

Permalink
add Nocedal and Wright trust region updating scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
FHoltorf committed Sep 14, 2023
1 parent 065aee6 commit c693f2c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/trustRegion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ EnumX.@enumx RadiusUpdateSchemes begin
"""
NLsolve

"""
`RadiusUpdateSchemes.NLsolve`
Nocedal and Wright updating scheme
"""
NW

"""
`RadiusUpdateSchemes.Hei`
Expand Down Expand Up @@ -180,7 +187,7 @@ function TrustRegion(; chunk_size = Val{0}(),
autodiff = Val{true}(),
standardtag = Val{true}(), concrete_jac = nothing,
diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS,
radius_update_scheme::RadiusUpdateSchemes.T = RadiusUpdateSchemes.Simple, #defaults to conventional radius update
radius_update_scheme::RadiusUpdateSchemes.T = RadiusUpdateSchemes.NW, #defaults to conventional radius update
max_trust_radius::Real = 0 // 1,
initial_trust_radius::Real = 0 // 1,
step_threshold::Real = 1 // 10000,
Expand Down Expand Up @@ -540,6 +547,22 @@ function trust_region_step!(cache::TrustRegionCache)
if iszero(cache.fu) || cache.internalnorm(cache.fu) < cache.abstol
cache.force_stop = true

Check warning on line 548 in src/trustRegion.jl

View check run for this annotation

Codecov / codecov/patch

src/trustRegion.jl#L547-L548

Added lines #L547 - L548 were not covered by tests
end

elseif radius_update_scheme === RadiusUpdateSchemes.NW
# accept/reject decision
if r > cache.step_threshold # accept
take_step!(cache)
cache.loss = cache.loss_new
cache.make_new_J = true
else # reject
cache.make_new_J = false
end

if r < 1 // 4
cache.trust_r = (1 // 4) * norm(cache.step_size)
elseif (r > (3 // 4)) && abs(norm(cache.step_size) - cache.trust_r)/cache.trust_r < 1e-6
cache.trust_r = min(2*cache.trust_r, cache.max_trust_r)
end

elseif radius_update_scheme === RadiusUpdateSchemes.Hei
if r > cache.step_threshold
Expand Down

0 comments on commit c693f2c

Please sign in to comment.