55
55
# SimpleTrustRegion
56
56
function benchmark_scalar (f, u0)
57
57
probN = NonlinearProblem {false} (f, u0)
58
- sol = (solve (probN, SimpleTrustRegion (10.0 )))
58
+ sol = (solve (probN, SimpleTrustRegion ()))
59
59
end
60
60
61
61
sol = benchmark_scalar (sf, csu0)
@@ -68,8 +68,7 @@ using ForwardDiff
68
68
# Immutable
69
69
f, u0 = (u, p) -> u .* u .- p, @SVector [1.0 , 1.0 ]
70
70
71
- for alg in [SimpleNewtonRaphson (), Broyden (), Klement (),
72
- SimpleTrustRegion (10.0 )]
71
+ for alg in (SimpleNewtonRaphson (), Broyden (), Klement (), SimpleTrustRegion ())
73
72
g = function (p)
74
73
probN = NonlinearProblem {false} (f, csu0, p)
75
74
sol = solve (probN, alg, abstol = 1e-9 )
84
83
85
84
# Scalar
86
85
f, 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 ())
89
87
g = function (p)
90
88
probN = NonlinearProblem {false} (f, oftype (p, u0), p)
91
89
sol = solve (probN, alg)
@@ -126,8 +124,7 @@ for alg in [Bisection(), Falsi()]
126
124
@test ForwardDiff. jacobian (g, p) ≈ ForwardDiff. jacobian (t, p)
127
125
end
128
126
129
- for alg in [SimpleNewtonRaphson (), Broyden (), Klement (),
130
- SimpleTrustRegion (10.0 )]
127
+ for alg in (SimpleNewtonRaphson (), Broyden (), Klement (), SimpleTrustRegion ())
131
128
global g, p
132
129
g = function (p)
133
130
probN = NonlinearProblem {false} (f, 0.5 , p)
@@ -144,8 +141,8 @@ probN = NonlinearProblem(f, u0)
144
141
145
142
@test solve (probN, SimpleNewtonRaphson ()). u[end ] ≈ sqrt (2.0 )
146
143
@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 )
149
146
@test solve (probN, Broyden ()). u[end ] ≈ sqrt (2.0 )
150
147
@test solve (probN, Klement ()). u[end ] ≈ sqrt (2.0 )
151
148
@@ -159,9 +156,9 @@ for u0 in [1.0, [1, 1.0]]
159
156
@test solve (probN, SimpleNewtonRaphson ()). u ≈ sol
160
157
@test solve (probN, SimpleNewtonRaphson (; autodiff = false )). u ≈ sol
161
158
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
165
162
166
163
@test solve (probN, Broyden ()). u ≈ sol
167
164
@@ -215,17 +212,16 @@ f = (u, p) -> 0.010000000000000002 .+
215
212
(0.21640425613334457 .+
216
213
216.40425613334457 ./
217
214
(1 .+ 0.0006250000000000001 (u .^ 2.0 ))) .^ 2.0 )) .^ 2.0 ) .-
218
- 0.0011552453009332421 u
219
- .- p
215
+ 0.0011552453009332421 u .- p
220
216
g = function (p)
221
217
probN = NonlinearProblem {false} (f, u0, p)
222
- sol = solve (probN, SimpleTrustRegion (100.0 ))
218
+ sol = solve (probN, SimpleTrustRegion ())
223
219
return sol. u
224
220
end
225
221
p = [0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ]
226
222
u = g (p)
227
223
f (u, p)
228
- @test all (f (u, p) .< 1e-10 )
224
+ @test all (abs .( f (u, p) ) .< 1e-10 )
229
225
230
226
# Test kwars in `SimpleTrustRegion`
231
227
max_trust_radius = [10.0 , 100.0 , 1000.0 ]
@@ -242,7 +238,7 @@ list_of_options = zip(max_trust_radius, initial_trust_radius, step_threshold,
242
238
expand_factor, max_shrink_times)
243
239
for options in list_of_options
244
240
local probN, sol, alg
245
- alg = SimpleTrustRegion (options[1 ];
241
+ alg = SimpleTrustRegion (max_trust_radius = options[1 ],
246
242
initial_trust_radius = options[2 ],
247
243
step_threshold = options[3 ],
248
244
shrink_threshold = options[4 ],
@@ -253,5 +249,5 @@ for options in list_of_options
253
249
254
250
probN = NonlinearProblem (f, u0, p)
255
251
sol = solve (probN, alg)
256
- @test all (f (u, p) .< 1e-10 )
252
+ @test all (abs .( f (u, p) ) .< 1e-10 )
257
253
end
0 commit comments