Skip to content

Commit be89678

Browse files
Automatic build\nPublished by build of: SciML/SciMLBenchmarks.jl@a72ef0a
1 parent 4b22ead commit be89678

8 files changed

Lines changed: 166 additions & 112 deletions

markdown/GlobalOptimization/blackbox_global_optimizers.md

Lines changed: 120 additions & 80 deletions
Large diffs are not rendered by default.
5.49 KB
Loading
446 Bytes
Loading
-265 Bytes
Loading
31.1 KB
Loading
13.5 KB
Loading
11.7 KB
Loading

script/GlobalOptimization/blackbox_global_optimizers.jl

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,54 @@ import BlackBoxOptimizationBenchmarking.Chain
44
const BBOB = BlackBoxOptimizationBenchmarking
55

66
using OptimizationBBO, OptimizationOptimJL, OptimizationEvolutionary, OptimizationNLopt
7-
using OptimizationMetaheuristics, OptimizationNOMAD, OptimizationPRIMA, OptimizationOptimisers
7+
using OptimizationMetaheuristics, OptimizationNOMAD, OptimizationPRIMA, OptimizationOptimisers, OptimizationSciPy, OptimizationPyCMA
88

99

10-
chain = (t; isboxed=false) -> Chain(
10+
chain = (t;
11+
isboxed = false) -> Chain(
1112
BenchmarkSetup(t, isboxed = isboxed),
1213
BenchmarkSetup(NelderMead(), isboxed = false),
1314
0.9
1415
)
1516

1617
test_functions = BBOB.list_functions()
1718
dimension = 3
18-
run_length = round.(Int, 10 .^ LinRange(1,5,30))
19+
run_length = round.(Int, 10 .^ LinRange(1, 5, 30))
1920

20-
@memoize run_bench(algo) = BBOB.benchmark(setup[algo], test_functions, run_length, Ntrials=40, dimension = dimension)
21+
@memoize run_bench(algo) = BBOB.benchmark(
22+
setup[algo], test_functions, run_length, Ntrials = 40, dimension = dimension)
2123

2224

2325
setup = Dict(
2426
"NelderMead" => NelderMead(),
2527
#Optim.BFGS(),
2628
#"NLopt.GN_MLSL_LDS" => chain(NLopt.GN_MLSL_LDS(), isboxed=true), # gives me errors
27-
"NLopt.GN_CRS2_LM()" => chain(NLopt.GN_CRS2_LM(), isboxed=true),
28-
"NLopt.GN_DIRECT()" => chain(NLopt.GN_DIRECT(), isboxed=true),
29-
"NLopt.GN_ESCH()" => chain(NLopt.GN_ESCH(), isboxed=true),
30-
"OptimizationEvolutionary.GA()" => chain(OptimizationEvolutionary.GA(), isboxed=true),
31-
"OptimizationEvolutionary.DE()" => chain(OptimizationEvolutionary.DE(), isboxed=true),
32-
"OptimizationEvolutionary.ES()" => chain(OptimizationEvolutionary.ES(), isboxed=true),
33-
"Optim.SAMIN" => chain(SAMIN(verbosity=0), isboxed=true),
34-
"BBO_adaptive_de_rand_1_bin" => chain(BBO_adaptive_de_rand_1_bin(), isboxed=true),
35-
"BBO_adaptive_de_rand_1_bin_radiuslimited" => chain(BBO_adaptive_de_rand_1_bin_radiuslimited(), isboxed=true), # same as BBO_adaptive_de_rand_1_bin
36-
"BBO_separable_nes" => chain(BBO_separable_nes(), isboxed=true),
37-
"BBO_de_rand_2_bin" => chain(BBO_de_rand_2_bin(), isboxed=true),
29+
"NLopt.GN_CRS2_LM()" => chain(NLopt.GN_CRS2_LM(), isboxed = true),
30+
"NLopt.GN_DIRECT()" => chain(NLopt.GN_DIRECT(), isboxed = true),
31+
"NLopt.GN_ESCH()" => chain(NLopt.GN_ESCH(), isboxed = true),
32+
"OptimizationEvolutionary.GA()" => chain(OptimizationEvolutionary.GA(), isboxed = true),
33+
"OptimizationEvolutionary.DE()" => chain(OptimizationEvolutionary.DE(), isboxed = true),
34+
"OptimizationEvolutionary.ES()" => chain(OptimizationEvolutionary.ES(), isboxed = true),
35+
"Optim.SAMIN" => chain(SAMIN(verbosity = 0), isboxed = true),
36+
"BBO_adaptive_de_rand_1_bin" => chain(BBO_adaptive_de_rand_1_bin(), isboxed = true),
37+
"BBO_adaptive_de_rand_1_bin_radiuslimited" => chain(
38+
BBO_adaptive_de_rand_1_bin_radiuslimited(), isboxed = true), # same as BBO_adaptive_de_rand_1_bin
39+
"BBO_separable_nes" => chain(BBO_separable_nes(), isboxed = true),
40+
"BBO_de_rand_2_bin" => chain(BBO_de_rand_2_bin(), isboxed = true),
3841
#"BBO_xnes" => chain(BBO_xnes(), isboxed=true), # good but slow
3942
#"BBO_dxnes" => chain(BBO_dxnes(), isboxed=true),
40-
"OptimizationMetaheuristics.ECA" => chain(OptimizationMetaheuristics.ECA(), isboxed=true),
43+
"OptimizationMetaheuristics.ECA" => chain(OptimizationMetaheuristics.ECA(), isboxed = true),
4144
#"OptimizationMetaheuristics.CGSA" => () -> chain(OptimizationMetaheuristics.CGSA(), isboxed=true), #give me strange results
4245
"OptimizationMetaheuristics.DE" => chain(OptimizationMetaheuristics.DE(), isboxed=true),
4346
"Optimisers.AdamW" => chain(Optimisers.AdamW(), isboxed=false),
4447
"Optimisers.RMSProp" => chain(Optimisers.RMSProp(), isboxed=false),
48+
# SciPy global optimizers
49+
"ScipyDifferentialEvolution" => chain(ScipyDifferentialEvolution(), isboxed=true),
50+
#"ScipyBasinhopping" => chain(ScipyBasinhopping(), isboxed=true),
51+
#"ScipyDualAnnealing" => chain(ScipyDualAnnealing(), isboxed=true), # taking long time
52+
"ScipyShgo" => chain(ScipyShgo(), isboxed=true),
53+
"ScipyDirect" => chain(ScipyDirect(), isboxed=true),
54+
"ScipyBrute" => chain(ScipyBrute(), isboxed=true),
4555
# "NOMADOpt" => chain(NOMADOpt()), too much printing
4656
# "OptimizationPRIMA.UOBYQA()" => chain(OptimizationPRIMA.UOBYQA()), :StackOverflowError?
4757
# "OptimizationPRIMA.NEWUOA()" => OptimizationPRIMA.UOBYQA(),
@@ -50,8 +60,8 @@ setup = Dict(
5060

5161

5262
@time b = BBOB.benchmark(
53-
chain(OptimizationMetaheuristics.CGSA(), isboxed=true),
54-
test_functions[1:10], 100:500:10_000, Ntrials=10, dimension = 3
63+
chain(OptimizationMetaheuristics.CGSA(), isboxed = true),
64+
test_functions[1:10], 100:500:10_000, Ntrials = 10, dimension = 3
5565
)
5666

5767
plot(b)
@@ -60,41 +70,44 @@ plot(b)
6070
Δf = 1e-6
6171
f = test_functions[3]
6272

63-
single_setup = BenchmarkSetup(NLopt.GN_CRS2_LM(), isboxed=true)
73+
single_setup = BenchmarkSetup(NLopt.GN_CRS2_LM(), isboxed = true)
6474

6575
sol = [BBOB.solve_problem(single_setup, f, 3, 5_000) for in in 1:10]
6676
@info [sol.objective < Δf + f.f_opt for sol in sol]
6777

68-
p = plot(f, size = (600,600), zoom = 1.5)
78+
p = plot(f, size = (600, 600), zoom = 1.5)
6979
for sol in sol
70-
scatter!(sol.u[1:1], sol.u[2:2], label="", c="blue", marker = :xcross, markersize=5, markerstrokewidth=0)
80+
scatter!(sol.u[1:1], sol.u[2:2], label = "", c = "blue",
81+
marker = :xcross, markersize = 5, markerstrokewidth = 0)
7182
end
7283
p
7384

7485

7586
results = Array{BBOB.BenchmarkResults}(undef, length(setup))
7687

77-
Threads.@threads for (i,algo) in collect(enumerate(keys(setup)))
88+
Threads.@threads for (i, algo) in collect(enumerate(keys(setup)))
7889
results[i] = run_bench(algo)
7990
end
8091

8192
results
8293

8394

8495
labels = collect(keys(setup))
85-
idx = sortperm([b.success_rate[end] for b in results], rev=true)
96+
idx = sortperm([b.success_rate[end] for b in results], rev = true)
8697

87-
p = plot(xscale = :log10, legend = :outerright, size = (700,350), margin=10Plots.px, dpi=200)
98+
p = plot(xscale = :log10, legend = :outerright,
99+
size = (700, 350), margin = 10Plots.px, dpi = 200)
88100
for i in idx
89-
plot!(results[i], label = labels[i], showribbon=false, lw=2.5, xlim = (1,1e5), x = :run_length)
101+
plot!(results[i], label = labels[i], showribbon = false,
102+
lw = 2.5, xlim = (1, 1e5), x = :run_length)
90103
end
91104
p
92105

93106

94107
success_rate_per_function = reduce(hcat, b.success_rate_per_function for b in results)
95108

96-
idx = sortperm(mean(success_rate_per_function, dims=1)[:], rev=false)
97-
idxfunc = sortperm(mean(success_rate_per_function, dims=2)[:], rev=true)
109+
idx = sortperm(mean(success_rate_per_function, dims = 1)[:], rev = false)
110+
idxfunc = sortperm(mean(success_rate_per_function, dims = 2)[:], rev = true)
98111
idxfunc = 1:length(test_functions)
99112

100113
p = heatmap(
@@ -103,18 +116,19 @@ p = heatmap(
103116
xticks = :all,
104117
yticks = :all,
105118
xrotation = 45,
106-
dpi = 200,
119+
dpi = 200
107120
)
108121

109122

110123
labels = collect(keys(setup))
111-
idx = sortperm([b.distance_to_minimizer[end] for b in results], rev=false)
124+
idx = sortperm([b.distance_to_minimizer[end] for b in results], rev = false)
112125

113-
p = plot(xscale = :log10, legend = :outerright, size = (900,500), margin=10Plots.px, ylim = (0,5))
126+
p = plot(xscale = :log10, legend = :outerright,
127+
size = (900, 500), margin = 10Plots.px, ylim = (0, 5))
114128
for i in idx
115129
plot!(
116130
results[i].run_length, results[i].distance_to_minimizer, label = labels[i],
117-
showribbon=false, lw=2, xlim = (1,1e5),
131+
showribbon = false, lw = 2, xlim = (1, 1e5),
118132
xlabel = "Iterations", ylabel = "Mean distance to minimum"
119133
)
120134
end
@@ -127,7 +141,7 @@ runtimes = runtimes ./ runtimes[ref]
127141

128142
bar(
129143
labels, runtimes, xrotation = :45, xticks = :all, ylabel = "Run time relative to NM",
130-
yscale = :log10, yticks = [0.1,1,10,100],
144+
yscale = :log10, yticks = [0.1, 1, 10, 100],
131145
legend = false, margin = 25Plots.px
132146
)
133147

0 commit comments

Comments
 (0)