Skip to content

Commit 34821e5

Browse files
committed
run SciML formatter
1 parent f67ced5 commit 34821e5

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/trustRegion.jl

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,14 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::TrustRegion,
258258
initial_trust_radius = convert(trustType, alg.initial_trust_radius)
259259
if iszero(initial_trust_radius)
260260
initial_trust_radius = convert(trustType, max_trust_radius / 11)
261-
end
261+
end
262262
end
263263
step_threshold = convert(trustType, alg.step_threshold)
264264
shrink_threshold = convert(trustType, alg.shrink_threshold)
265265
expand_threshold = convert(trustType, alg.expand_threshold)
266266
shrink_factor = convert(trustType, alg.shrink_factor)
267267
expand_factor = convert(trustType, alg.expand_factor)
268-
268+
269269
# Parameters for the Schemes
270270
p1 = convert(floatType, 0.0)
271271
p2 = convert(floatType, 0.0)
@@ -322,7 +322,8 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::TrustRegion,
322322
jac_cache, false, maxiters, internalnorm, ReturnCode.Default, abstol, prob,
323323
radius_update_scheme, initial_trust_radius, max_trust_radius, step_threshold,
324324
shrink_threshold, expand_threshold, shrink_factor, expand_factor, loss, loss_new,
325-
H, g, shrink_counter, du, u_tmp, u_gauss_newton, u_cauchy, fu_new, make_new_J, r, p1, p2, p3, p4, ϵ,
325+
H, g, shrink_counter, du, u_tmp, u_gauss_newton, u_cauchy, fu_new, make_new_J, r,
326+
p1, p2, p3, p4, ϵ,
326327
NLStats(1, 0, 0, 0, 0))
327328
end
328329

@@ -338,9 +339,9 @@ function perform_step!(cache::TrustRegionCache{true})
338339

339340
# do not use A = cache.H, b = _vec(cache.g) since it is equivalent
340341
# to A = cache.J, b = _vec(fu) as long as the Jacobian is non-singular
341-
linres = dolinsolve(alg.precs, linsolve, A = J, b = _vec(fu),
342-
linu = _vec(u_gauss_newton),
343-
p = p, reltol = cache.abstol)
342+
linres = dolinsolve(alg.precs, linsolve, A = J, b = _vec(fu),
343+
linu = _vec(u_gauss_newton),
344+
p = p, reltol = cache.abstol)
344345
cache.linsolve = linres.cache
345346
@. cache.u_gauss_newton = -1 * u_gauss_newton
346347
end
@@ -374,7 +375,7 @@ function perform_step!(cache::TrustRegionCache{false})
374375

375376
# Compute the potentially new u
376377
cache.u_tmp = u + cache.du
377-
378+
378379
cache.fu_new = f(cache.u_tmp, p)
379380
trust_region_step!(cache)
380381
cache.stats.nf += 1
@@ -406,7 +407,7 @@ function trust_region_step!(cache::TrustRegionCache)
406407

407408
# Compute the ratio of the actual reduction to the predicted reduction.
408409
cache.r = -(loss - cache.loss_new) / (dot(du, g) + dot(du, H, du) / 2)
409-
@unpack r = cache
410+
@unpack r = cache
410411

411412
if radius_update_scheme === RadiusUpdateSchemes.Simple
412413
# Update the trust region radius.
@@ -446,19 +447,19 @@ function trust_region_step!(cache::TrustRegionCache)
446447
end
447448

448449
# trust region update
449-
if r < 1//10 # cache.shrink_threshold
450-
cache.trust_r *= 1//2 # cache.shrink_factor
451-
elseif r >= 9//10 # cache.expand_threshold
450+
if r < 1 // 10 # cache.shrink_threshold
451+
cache.trust_r *= 1 // 2 # cache.shrink_factor
452+
elseif r >= 9 // 10 # cache.expand_threshold
452453
cache.trust_r = 2 * norm(cache.du) # cache.expand_factor * norm(cache.du)
453-
elseif r >= 1//2 # cache.p1
454-
cache.trust_r = max(cache.trust_r, 2*norm(cache.du)) # cache.expand_factor * norm(cache.du))
454+
elseif r >= 1 // 2 # cache.p1
455+
cache.trust_r = max(cache.trust_r, 2 * norm(cache.du)) # cache.expand_factor * norm(cache.du))
455456
end
456457

457458
# convergence test
458459
if iszero(cache.fu) || cache.internalnorm(cache.fu) < cache.abstol
459460
cache.force_stop = true
460461
end
461-
462+
462463
elseif radius_update_scheme === RadiusUpdateSchemes.NW
463464
# accept/reject decision
464465
if r > cache.step_threshold # accept
@@ -471,9 +472,9 @@ function trust_region_step!(cache::TrustRegionCache)
471472

472473
if r < 1 // 4
473474
cache.trust_r = (1 // 4) * norm(cache.du)
474-
elseif (r > (3 // 4)) && abs(norm(cache.du) - cache.trust_r)/cache.trust_r < 1e-6
475-
cache.trust_r = min(2*cache.trust_r, cache.max_trust_r)
476-
end
475+
elseif (r > (3 // 4)) && abs(norm(cache.du) - cache.trust_r) / cache.trust_r < 1e-6
476+
cache.trust_r = min(2 * cache.trust_r, cache.max_trust_r)
477+
end
477478

478479
elseif radius_update_scheme === RadiusUpdateSchemes.Hei
479480
if r > cache.step_threshold
@@ -579,25 +580,24 @@ function dogleg!(cache::TrustRegionCache{true})
579580
# Take intersection of steepest descent direction and trust region if Cauchy point lies outside of trust region
580581
l_grad = norm(cache.g) # length of the gradient
581582
d_cauchy = l_grad^3 / dot(cache.g, cache.H, cache.g) # distance of the cauchy point from the current iterate
582-
if d_cauchy >= trust_r
583-
@. cache.du = - (trust_r/l_grad) * cache.g # step to the end of the trust region
583+
if d_cauchy >= trust_r
584+
@. cache.du = -(trust_r / l_grad) * cache.g # step to the end of the trust region
584585
return
585586
end
586587

587588
# Take the intersection of dogled with trust region if Cauchy point lies inside the trust region
588-
@. u_cauchy = - (d_cauchy/l_grad) * cache.g # compute Cauchy point
589+
@. u_cauchy = -(d_cauchy / l_grad) * cache.g # compute Cauchy point
589590
@. u_tmp = u_gauss_newton - u_cauchy # calf of the dogleg -- use u_tmp to avoid allocation
590-
591+
591592
a = dot(u_tmp, u_tmp)
592-
b = 2*dot(u_cauchy, u_tmp)
593+
b = 2 * dot(u_cauchy, u_tmp)
593594
c = d_cauchy^2 - trust_r^2
594-
aux = max(b^2 - 4*a*c, 0.0) # technically guaranteed to be non-negative but hedging against floating point issues
595-
τ = (-b + sqrt(aux)) / (2*a) # stepsize along dogleg to trust region boundary
595+
aux = max(b^2 - 4 * a * c, 0.0) # technically guaranteed to be non-negative but hedging against floating point issues
596+
τ = (-b + sqrt(aux)) / (2 * a) # stepsize along dogleg to trust region boundary
596597

597598
@. cache.du = u_cauchy + τ * u_tmp
598599
end
599600

600-
601601
function dogleg!(cache::TrustRegionCache{false})
602602
@unpack u_tmp, u_gauss_newton, u_cauchy, trust_r = cache
603603

@@ -611,18 +611,18 @@ function dogleg!(cache::TrustRegionCache{false})
611611
l_grad = norm(cache.g)
612612
d_cauchy = l_grad^3 / dot(cache.g, cache.H, cache.g) # distance of the cauchy point from the current iterate
613613
if d_cauchy > trust_r # cauchy point lies outside of trust region
614-
cache.du = - (trust_r/l_grad) * cache.g # step to the end of the trust region
614+
cache.du = -(trust_r / l_grad) * cache.g # step to the end of the trust region
615615
return
616616
end
617-
617+
618618
# Take the intersection of dogled with trust region if Cauchy point lies inside the trust region
619-
u_cauchy = - (d_cauchy/l_grad) * cache.g # compute Cauchy point
619+
u_cauchy = -(d_cauchy / l_grad) * cache.g # compute Cauchy point
620620
u_tmp = u_gauss_newton - u_cauchy # calf of the dogleg
621621
a = dot(u_tmp, u_tmp)
622-
b = 2*dot(u_cauchy, u_tmp)
622+
b = 2 * dot(u_cauchy, u_tmp)
623623
c = d_cauchy^2 - trust_r^2
624-
aux = max(b^2 - 4*a*c, 0.0) # technically guaranteed to be non-negative but hedging against floating point issues
625-
τ = (-b + sqrt(aux)) / (2*a) # stepsize along dogleg to trust region boundary
624+
aux = max(b^2 - 4 * a * c, 0.0) # technically guaranteed to be non-negative but hedging against floating point issues
625+
τ = (-b + sqrt(aux)) / (2 * a) # stepsize along dogleg to trust region boundary
626626

627627
cache.du = u_cauchy + τ * u_tmp
628628
end

0 commit comments

Comments
 (0)