@@ -300,7 +300,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::TrustRegion,
300
300
p2 = convert (floatType, 0.25 ) # c5
301
301
p3 = convert (floatType, 12.0 ) # c6
302
302
p4 = convert (floatType, 1.0e18 ) # M
303
- initial_trust_radius = convert (trustType, p1 * (norm (fu )^ 0.99 ))
303
+ initial_trust_radius = convert (trustType, p1 * (norm (fu1 )^ 0.99 ))
304
304
elseif radius_update_scheme === RadiusUpdateSchemes. Bastin
305
305
step_threshold = convert (trustType, 0.05 )
306
306
shrink_threshold = convert (trustType, 0.05 )
@@ -362,11 +362,8 @@ function perform_step!(cache::TrustRegionCache{false})
362
362
dogleg! (cache)
363
363
364
364
# Compute the potentially new u
365
- if u isa Number
366
- cache. u_tmp = u + cache. du
367
- else
368
- @. cache. u_tmp = u + cache. du
369
- end
365
+ cache. u_tmp = u + cache. du
366
+
370
367
cache. fu_new = f (cache. u_tmp, p)
371
368
trust_region_step! (cache)
372
369
cache. stats. nf += 1
@@ -592,29 +589,29 @@ end
592
589
function dogleg! (cache:: TrustRegionCache{false} )
593
590
@unpack u_tmp, u_cauchy, trust_r = cache
594
591
595
- # Test if the full step is within the trust region.
592
+ # Take the full Gauss-Newton step if lies within the trust region.
596
593
if norm (u_tmp) ≤ trust_r
597
594
cache. du = deepcopy (u_tmp)
598
595
return
599
596
end
600
597
601
- # Calcualte Cauchy point, optimum along the steepest descent direction.
598
+ # # Take intersection of steepest descent direction and trust region if Cauchy point lies outside of trust region
602
599
l_grad = norm (cache. g)
603
600
d_cauchy = l_grad^ 3 / dot (cache. g, cache. H, cache. g) # distance of the cauchy point from the current iterate
604
601
if d_cauchy > trust_r # cauchy point lies outside of trust region
605
602
cache. du = - (trust_r/ l_grad) * cache. g # step to the end of the trust region
606
603
return
607
604
end
608
605
609
- # cauchy point lies inside the trust region
610
- u_cauchy = - (d_cauchy/ l_grad) * cache. g
611
-
612
- # Find the intersection point on the boundary.
613
- u_tmp -= u_cauchy # calf of the dogleg, use u_tmp to avoid allocation
614
- θ = dot (u_tmp, u_cauchy) # ~ cos(∠(calf,thigh))
615
- l_calf = dot (u_tmp,u_tmp ) # length of the calf of the dogleg
616
- aux = max (θ ^ 2 + l_calf * (trust_r ^ 2 - d_cauchy ^ 2 ), 0 ) # technically guaranteed to be non-negative but hedging against floating point issues
617
- τ = ( - θ + sqrt ( aux ) ) / l_calf # stepsize along dogleg
606
+ # Take the intersection of dogled with trust region if Cauchy point lies inside the trust region
607
+ u_cauchy = - (d_cauchy/ l_grad) * cache. g # compute Cauchy point
608
+ u_tmp -= u_cauchy # calf of the dogleg -- use u_tmp to avoid allocation
609
+ a = dot (u_tmp, u_tmp)
610
+ b = 2 * dot ( u_cauchy, u_tmp)
611
+ c = d_cauchy ^ 2 - trust_r ^ 2
612
+ aux = max (b ^ 2 - 4 * a * c, 0.0 ) # technically guaranteed to be non-negative but hedging against floating point issues
613
+ τ = ( - b + sqrt (aux)) / ( 2 * a) # stepsize along dogleg to trust region boundary
614
+
618
615
cache. du = u_cauchy + τ * u_tmp
619
616
end
620
617
0 commit comments