Skip to content

Commit 5591de2

Browse files
authored
Use 10D problem from#108 (#242)
1 parent 410a12e commit 5591de2

4 files changed

Lines changed: 74 additions & 22 deletions

File tree

benchmark/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
33
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
44
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
5+
IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807"
56
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
67
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

benchmark/benchmarks.jl

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
include("../examples/smiley_examples.jl")
2-
using .SmileyExample22, .SmileyExample52, .SmileyExample54, .SmileyExample55
3-
41
using BenchmarkTools
52
using ForwardDiff
63
using IntervalArithmetic
74
using IntervalRootFinding
8-
using StaticArrays
9-
105
import Random
6+
using StaticArrays
117

128
const SUITE = BenchmarkGroup()
139

1410
Random.seed!(0) # Seed the RNG to get consistent results
1511
tol = 1e-10
1612

17-
include("dietmar_ratz_functions.jl")
13+
## Smiley and Chun examples
14+
include("../examples/smiley_examples.jl")
15+
using .SmileyExample22, .SmileyExample52, .SmileyExample54, .SmileyExample55
1816

1917
S = SUITE["Smiley"] = BenchmarkGroup()
20-
for example in (SmileyExample22, SmileyExample52, SmileyExample54) #, SmileyExample55)
18+
19+
for example in (SmileyExample22, SmileyExample52, SmileyExample54, SmileyExample55)
2120
s = S[example.title] = BenchmarkGroup()
2221
for contractor in (Newton, Krawczyk)
2322
s[string(contractor)] = @benchmarkable roots($(example.f), $(example.region) ; contractor = $contractor, abstol = $tol, infer_root_type = false)
2423
end
2524
end
2625

2726

27+
## Rastrigin function
2828
S = SUITE["Rastigrin stationary points"] = BenchmarkGroup()
2929

30-
# Rastrigin function:
3130
const A = 10
3231

3332
f(x, y) = 2A + x^2 - A*cos(2π*x) + y^2 - A*cos(2π*y)
@@ -43,22 +42,11 @@ for contractor in (Newton, Krawczyk)
4342
end
4443

4544

46-
S = SUITE["Linear equations"] = BenchmarkGroup()
47-
48-
sizes = (2, 5, 10)
49-
50-
for n in sizes
51-
s = S["n = $n"] = BenchmarkGroup()
52-
M = interval.(randn(n, n))
53-
b = interval.(randn(n))
54-
55-
# s["Gauss seidel"] = @benchmarkable gauss_seidel_interval($M, $b)
56-
# s["Gauss seidel contractor"] = @benchmarkable gauss_seidel_contractor($M, $b)
57-
# s["Gauss elimination"] = @benchmarkable gauss_elimination_interval($M, $b)
58-
end
59-
45+
## Dietmar-Ratz functions
46+
include("dietmar_ratz_functions.jl")
6047

6148
S = SUITE["Dietmar-Ratz"] = BenchmarkGroup()
49+
6250
X = interval(0.75, 1.75)
6351

6452
for (k, dr) in enumerate(dr_functions)
@@ -70,3 +58,12 @@ for (k, dr) in enumerate(dr_functions)
7058
end
7159
end
7260
end
61+
62+
# 10 dimensional problem
63+
include("../examples/10_dimensional.jl")
64+
65+
S = SUITE["10 dimensional"] = BenchmarkGroup()
66+
67+
for contractor in (Newton, Krawczyk)
68+
S[string(contractor)] = @benchmarkable roots($f10d, $X10d_close ; contractor = $contractor, abstol = $tol, max_iteration = 1_000_000)
69+
end

examples/10_dimensional.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using IntervalArithmetic
2+
using IntervalRootFinding
3+
using StaticArrays
4+
5+
# 10 dimensional problem from https://discourse.julialang.org/t/solvers-fail-on-nonlinear-problem-which-has-solutions/20051
6+
function f10d(X)
7+
p = [3600, 18, 18, 3600, 3600, 3600, 1800, 3600, 18, 18, 18, 1800, 18, 36, 11, 180, 0.7, 0.4, 30, 0.2, 4, 4.5, 0.4]
8+
x1, x2, x3, x4, x5, x6, x7, x8, x9, x10 = X
9+
10+
return SVector(
11+
-p[17] * x1 + -2 * p[1] * (x1 ^ 2 / 2) + 2 * p[2] * x2 + p[21] * p[18] * ((1 + p[19] * x7) / (p[20] + x7)),
12+
-p[17] * x2 + p[1] * (x1 ^ 2 / 2) + -1 * p[2] * x2 + -1 * p[4] * x2 * x4 + p[9] * x3 + p[14] * x3 + -1 * p[6] * x2 * x7 + p[11] * x8,
13+
-p[17] * x3 + p[4] * x2 * x4 + -1 * p[9] * x3 + -1 * p[5] * x3 * x4 + p[10] * x5 + -1 * p[14] * x3 + p[15] * x5 + p[7] * x8 * x4 + -1 * p[12] * x3 * x7,
14+
-p[17] * x4 + -1 * p[4] * x2 * x4 + p[9] * x3 + -1 * p[5] * x3 * x4 + p[10] * x5 + -1 * p[7] * x8 * x4 + p[12] * x3 * x7 + p[16] * x9 + p[22] * p[18] * ((1 + p[19] * x7) / (p[20] + x7)),
15+
-p[17] * x5 + p[5] * x3 * x4 + -1 * p[10] * x5 + -1 * p[15] * x5,
16+
-p[17] * x6 + p[14] * x3 + p[15] * x5 + -1 * p[8] * x6 * x10 + p[13] * x9,
17+
-p[17] * x7 + -1 * p[6] * x2 * x7 + p[11] * x8 + p[7] * x8 * x4 + -1 * p[12] * x3 * x7 + p[18] * ((1 + p[19] * x7) / (p[20] + x7)),
18+
-p[17] * x8 + p[6] * x2 * x7 + -1 * p[11] * x8 + -1 * p[7] * x8 * x4 + p[12] * x3 * x7,
19+
-p[17] * x9 + p[8] * x6 * x10 + -1 * p[13] * x9 + -1 * p[16] * x9,
20+
x10 + x9 - p[23]
21+
)
22+
end
23+
24+
# Approximate solution
25+
sol10d = SVector(0.11584484298713685,
26+
0.9455230206055336,
27+
1.4935460680512724,
28+
0.014733756971650408,
29+
2.6673387628301497,
30+
15.827943289607886,
31+
0.03777227940579977,
32+
5.088785613357363,
33+
0.3986099863617728,
34+
0.0013900136199035832
35+
)
36+
37+
# This input is close enough to the solution to converge in less than 1e6 iterations
38+
X10d_close = SVector{10}(interval(x - 0.0002, x + 0.0002) for x in sol10d)
39+
40+
# This input is too large, and requires more than 1e6 iterations to converge
41+
X10d_large = SVector{10}(fill(interval(0, 100), 10))

test/roots.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ end
133133
end
134134
end
135135

136+
@testset "10D roots" begin
137+
include("../examples/10_dimensional.jl")
138+
139+
for contractor in newtonlike_methods
140+
rts = roots(f10d, X10d_large ; contractor, max_iteration = 50_000)
141+
@test any(X -> all(in_interval.(sol10d, X.region)), rts)
142+
143+
rts = roots(f10d, X10d_close ; contractor, max_iteration = 1_000_000)
144+
@test length(rts) == 1
145+
@test isunique(rts[1])
146+
end
147+
end
148+
136149
@testset "Dimension mismatch" begin
137150
f21(xy) = [xy[1]^2 - 2]
138151
f23(xy) = [xy[1]^2 - 2, xy[2]^2 - 3, xy[1] + xy[2]]

0 commit comments

Comments
 (0)