Optimization.jl
Optimization.jl copied to clipboard
Particle Swarm stuck on corner of optimization domain
I have been trying to use Optimization.jl with Optim.jl to perform global optimization with ParticleSwarm()
, with MethodOfLines.jl generating the data for the loss, and running the forward problem.
I have run in to an issue where the solver gets locked in to only evaluating the upper bound of all parameters, after a few iterations.
Is this a good issue here, or should I direct to Optim.jl?
My code is somewhat difficult to produce an MWE from, so I thought to ask if this is a known issue before gutting it for debugging fodder.
My optimization setup:
...
LOSS = [] # Loss accumulator
PARS = [] # parameters accumulator
using Plots
cb = function (θ, l) #callback function to observe training
append!(LOSS, l)
append!(PARS, [θ])
println("loss = ", l, "; θ = ", θ)
false
end
println("Generate OptimizationFunction...")
@time opf = OptimizationFunction(loss, Optimization.AutoZygote())
println("Generate OptimizationProblem...")
@time opprob = OptimizationProblem(opf, initp)
_ = loss([1.0,1.0], [])
println("Optimizing...")
@time result = Optimization.solve(opprob, OptimizationOptimJL.ParticleSwarm(lower = [0.0, 20.0], upper = [1.0, 100.0], n_particles=100), maxiters=500, callback=cb)
The output of the run so far:
Optimizing...
loss = 18.22959044129359; θ = [1.0, 30.0]
loss = 11.263023755822093; θ = [0.9909603966537504, 99.77047480421588]
loss = 9.926057679334475; θ = [1.0, 100.0]
loss = 9.926057679334475; θ = [1.0, 100.0]
loss = 9.926057679334475; θ = [1.0, 100.0]
loss = 9.926057679334475; θ = [1.0, 100.0]
loss = 9.926057679334475; θ = [1.0, 100.0]
loss = 9.926057679334475; θ = [1.0, 100.0]
loss = 9.926057679334475; θ = [1.0, 100.0]
loss = 9.926057679334475; θ = [1.0, 100.0]
loss = 9.926057679334475; θ = [1.0, 100.0]
loss = 9.926057679334475; θ = [1.0, 100.0]
loss = 9.926057679334475; θ = [1.0, 100.0]
...
Should I post full code?
Yeah specific solver issues are upstream of here. We just call them. So unless this is suspected to be a wrapper issue (which to me, this looks upstream), I think this needs to be redirected. Did you try a different solver to isolate whether it's a wrapper or solver issue?