Skip to content

Commit 98f1fd7

Browse files
tune in hyperparam
Signed-off-by: AdityaPandeyCN <adityapand3y666@gmail.com>
1 parent 7a61db2 commit 98f1fd7

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

benchmarks/PSOGlobalOptimization/pso_global_optimizers.jmd

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ using OptimizationMetaheuristics, OptimizationSciPy
2727
using ParallelParticleSwarms
2828
using ForwardDiff
2929
using KernelAbstractions
30-
using CUDA
3130
using StaticArrays, LinearAlgebra
3231

3332
const PSOKernel = ParallelParticleSwarms.ParallelPSOKernel
3433
const SyncPSOKernel = ParallelParticleSwarms.ParallelSyncPSOKernel
3534
const SerPSO = ParallelParticleSwarms.SerialPSO
3635
const HPso = ParallelParticleSwarms.HybridPSO
3736

38-
const BACKEND = CUDABackend()
37+
const BACKEND = CPU() # use CUDABackend() from CUDA.jl on GPU CI
3938
```
4039

4140
```julia
@@ -99,12 +98,13 @@ function _pso_problem(f::BBOBFunction, D::Int; x0 = nothing)
9998
end
10099

101100
function pso_solve(opt, f::BBOBFunction, D::Int, maxiters::Int;
102-
local_maxiters::Int = 50, x0 = nothing)
101+
local_maxiters::Int = 150, x0 = nothing)
103102
prob = _pso_problem(f, D; x0)
104103
if opt isa HPso
105-
solve(prob, opt; maxiters, local_maxiters, abstol = 1.0f-8, reltol = 1.0f-8)
104+
solve(prob, opt; maxiters, local_maxiters,
105+
abstol = 1.0f-8, reltol = 1.0f-8, w = 0.65f0, wdamp = 0.99f0)
106106
else
107-
solve(prob, opt; maxiters)
107+
solve(prob, opt; maxiters, w = 0.65f0, wdamp = 0.99f0)
108108
end
109109
end
110110

@@ -116,7 +116,7 @@ function _extract_u(sol, D)
116116
end
117117

118118
function pso_benchmark(opt, funcs, run_length;
119-
Ntrials = 15, dimension = 3, local_maxiters = 50, Δf = 1e-6, CI_quantile = 0.25,
119+
Ntrials = 15, dimension = 3, local_maxiters = 150, Δf = 1e-6, CI_quantile = 0.25,
120120
n_particles = 1)
121121
Nf = length(funcs); Nr = length(run_length)
122122
success = zeros(Float64, Nf, Nr)
@@ -161,7 +161,7 @@ function pso_benchmark(opt, funcs, run_length;
161161
end
162162

163163
function pso_tts(opt, funcs; Ntrials = 15, dimension = 3, Δf = 1e-6,
164-
local_maxiters = 50, max_run_length = 100_000)
164+
local_maxiters = 150, max_run_length = 100_000)
165165
all_times = Float64[]
166166
D = dimension
167167
for f in funcs
@@ -170,10 +170,10 @@ function pso_tts(opt, funcs; Ntrials = 15, dimension = 3, Δf = 1e-6,
170170
prob = _pso_problem(f, D; x0)
171171
t0 = time()
172172
sol = if opt isa HPso
173-
solve(prob, opt; maxiters = max_run_length,
174-
local_maxiters, abstol = 1.0f-8, reltol = 1.0f-8)
173+
solve(prob, opt; maxiters = max_run_length, local_maxiters,
174+
abstol = 1.0f-8, reltol = 1.0f-8, w = 0.65f0, wdamp = 0.99f0)
175175
else
176-
solve(prob, opt; maxiters = max_run_length)
176+
solve(prob, opt; maxiters = max_run_length, w = 0.65f0, wdamp = 0.99f0)
177177
end
178178
elapsed = time() - t0
179179
fval = _to_f64(sol.objective)
@@ -194,13 +194,14 @@ dimension = 10
194194
# Exclude unstable BBOB functions: f4 Buche-Rastrigin, f7 Step-Ellipsoidal (segfault),
195195
# f10 Ellipsoidal-2 (illegal access).
196196
test_functions = filter(f -> nameof(f.f) ∉ (:f4, :f7, :f10), BBOB.bbob_suite(Val(dimension)))
197-
run_length = round.(Int, 10 .^ LinRange(1, 4, 15))
197+
run_length = round.(Int, 10 .^ LinRange(1, 4.5, 18)) # up to ~3e4 iters
198198
Ntrials = 15
199-
num_particles = 5_000
199+
num_particles = 8_000
200200

201201
const SUCCESS_Δf = 1e-6
202202

203-
PSO_KEYS = Set(["SerialPSO", "PSOKernel", "SyncPSOKernel", "HybridPSO_LBFGS"])
203+
# SyncPSOKernel omitted as a standalone entry: Hybrid embeds it before L-BFGS.
204+
PSO_KEYS = Set(["SerialPSO", "PSOKernel", "HybridPSO_LBFGS"])
204205

205206
setup = Dict(
206207
"NelderMead" => NelderMead(),
@@ -216,10 +217,12 @@ setup = Dict(
216217
"OptimizationMetaheuristics.ECA" => chain(OptimizationMetaheuristics.ECA(), isboxed = true),
217218
"OptimizationMetaheuristics.DE" => chain(OptimizationMetaheuristics.DE(), isboxed = true),
218219
"ScipyDifferentialEvolution" => chain(ScipyDifferentialEvolution(), isboxed = true),
219-
"SerialPSO" => SerPSO(512),
220+
"SerialPSO" => SerPSO(2048),
220221
"PSOKernel" => PSOKernel(num_particles; backend = BACKEND, global_update = true),
221-
"SyncPSOKernel" => SyncPSOKernel(num_particles; backend = BACKEND),
222-
"HybridPSO_LBFGS" => HPso(pso = SyncPSOKernel(num_particles; backend = BACKEND); backend = BACKEND),
222+
"HybridPSO_LBFGS" => HPso(
223+
pso = SyncPSOKernel(num_particles; backend = BACKEND),
224+
local_opt = ParallelParticleSwarms.LBFGS(threshold = 20),
225+
backend = BACKEND),
223226
)
224227

225228
@memoize run_bench(algo) = algo in PSO_KEYS ?

0 commit comments

Comments
 (0)