5555# SimpleTrustRegion
5656function benchmark_scalar (f, u0)
5757 probN = NonlinearProblem {false} (f, u0)
58- sol = (solve (probN, SimpleTrustRegion (10.0 )))
58+ sol = (solve (probN, SimpleTrustRegion ()))
5959end
6060
6161sol = benchmark_scalar (sf, csu0)
@@ -68,8 +68,7 @@ using ForwardDiff
6868# Immutable
6969f, u0 = (u, p) -> u .* u .- p, @SVector [1.0 , 1.0 ]
7070
71- for alg in [SimpleNewtonRaphson (), Broyden (), Klement (),
72- SimpleTrustRegion (10.0 )]
71+ for alg in (SimpleNewtonRaphson (), Broyden (), Klement (), SimpleTrustRegion ())
7372 g = function (p)
7473 probN = NonlinearProblem {false} (f, csu0, p)
7574 sol = solve (probN, alg, abstol = 1e-9 )
8483
8584# Scalar
8685f, u0 = (u, p) -> u * u - p, 1.0
87- for alg in [SimpleNewtonRaphson (), Broyden (), Klement (),
88- SimpleTrustRegion (10.0 )]
86+ for alg in (SimpleNewtonRaphson (), Broyden (), Klement (), SimpleTrustRegion ())
8987 g = function (p)
9088 probN = NonlinearProblem {false} (f, oftype (p, u0), p)
9189 sol = solve (probN, alg)
@@ -126,8 +124,7 @@ for alg in [Bisection(), Falsi()]
126124 @test ForwardDiff. jacobian (g, p) ≈ ForwardDiff. jacobian (t, p)
127125end
128126
129- for alg in [SimpleNewtonRaphson (), Broyden (), Klement (),
130- SimpleTrustRegion (10.0 )]
127+ for alg in (SimpleNewtonRaphson (), Broyden (), Klement (), SimpleTrustRegion ())
131128 global g, p
132129 g = function (p)
133130 probN = NonlinearProblem {false} (f, 0.5 , p)
@@ -144,8 +141,8 @@ probN = NonlinearProblem(f, u0)
144141
145142@test solve (probN, SimpleNewtonRaphson ()). u[end ] ≈ sqrt (2.0 )
146143@test solve (probN, SimpleNewtonRaphson (; autodiff = false )). u[end ] ≈ sqrt (2.0 )
147- @test solve (probN, SimpleTrustRegion (10.0 )). u[end ] ≈ sqrt (2.0 )
148- @test solve (probN, SimpleTrustRegion (10.0 ; autodiff = false )). u[end ] ≈ sqrt (2.0 )
144+ @test solve (probN, SimpleTrustRegion ()). u[end ] ≈ sqrt (2.0 )
145+ @test solve (probN, SimpleTrustRegion (; autodiff = false )). u[end ] ≈ sqrt (2.0 )
149146@test solve (probN, Broyden ()). u[end ] ≈ sqrt (2.0 )
150147@test solve (probN, Klement ()). u[end ] ≈ sqrt (2.0 )
151148
@@ -159,9 +156,9 @@ for u0 in [1.0, [1, 1.0]]
159156 @test solve (probN, SimpleNewtonRaphson ()). u ≈ sol
160157 @test solve (probN, SimpleNewtonRaphson (; autodiff = false )). u ≈ sol
161158
162- @test solve (probN, SimpleTrustRegion (10.0 )). u ≈ sol
163- @test solve (probN, SimpleTrustRegion (10.0 )). u ≈ sol
164- @test solve (probN, SimpleTrustRegion (10.0 ; autodiff = false )). u ≈ sol
159+ @test solve (probN, SimpleTrustRegion ()). u ≈ sol
160+ @test solve (probN, SimpleTrustRegion ()). u ≈ sol
161+ @test solve (probN, SimpleTrustRegion (; autodiff = false )). u ≈ sol
165162
166163 @test solve (probN, Broyden ()). u ≈ sol
167164
@@ -215,17 +212,16 @@ f = (u, p) -> 0.010000000000000002 .+
215212 (0.21640425613334457 .+
216213 216.40425613334457 ./
217214 (1 .+ 0.0006250000000000001 (u .^ 2.0 ))) .^ 2.0 )) .^ 2.0 ) .-
218- 0.0011552453009332421 u
219- .- p
215+ 0.0011552453009332421 u .- p
220216g = function (p)
221217 probN = NonlinearProblem {false} (f, u0, p)
222- sol = solve (probN, SimpleTrustRegion (100.0 ))
218+ sol = solve (probN, SimpleTrustRegion ())
223219 return sol. u
224220end
225221p = [0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ]
226222u = g (p)
227223f (u, p)
228- @test all (f (u, p) .< 1e-10 )
224+ @test all (abs .( f (u, p) ) .< 1e-10 )
229225
230226# Test kwars in `SimpleTrustRegion`
231227max_trust_radius = [10.0 , 100.0 , 1000.0 ]
@@ -242,7 +238,7 @@ list_of_options = zip(max_trust_radius, initial_trust_radius, step_threshold,
242238 expand_factor, max_shrink_times)
243239for options in list_of_options
244240 local probN, sol, alg
245- alg = SimpleTrustRegion (options[1 ];
241+ alg = SimpleTrustRegion (max_trust_radius = options[1 ],
246242 initial_trust_radius = options[2 ],
247243 step_threshold = options[3 ],
248244 shrink_threshold = options[4 ],
@@ -253,5 +249,5 @@ for options in list_of_options
253249
254250 probN = NonlinearProblem (f, u0, p)
255251 sol = solve (probN, alg)
256- @test all (f (u, p) .< 1e-10 )
252+ @test all (abs .( f (u, p) ) .< 1e-10 )
257253end
0 commit comments