Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particle Swarm #944

Closed
marlloseff opened this issue Sep 19, 2021 · 4 comments
Closed

Particle Swarm #944

marlloseff opened this issue Sep 19, 2021 · 4 comments

Comments

@marlloseff
Copy link

marlloseff commented Sep 19, 2021

Hello everyone. I need help to understand Particle Swarm a bit. In the following example, the answer is right, but the Status seems to contradict. And why does Particle Swarm always exhaust the number of interactions? Even if you increase the number of interactions, it will still run out. Thank you.

using Optim

function test()
	f(x) = (1.0 - x[1])^2 + (2.0 - x[2])^2
	res = optimize(f, zeros(2), ParticleSwarm(; lower=[-10.0,-10.0], upper=[10.0,10.0]))
	println(res.minimizer)
	println(res)
end

test()

# [1.0, 2.0]

# * Status: failure (reached maximum number of iterations)

# * Candidate solution
# Final objective value:     9.632189e-27

# * Found with
# Algorithm:     Particle Swarm

# * Convergence measures
# |x - x'|               = NaN ≰ 0.0e+00
# |x - x'|/|x'|          = NaN ≰ 0.0e+00
# |f(x) - f(x')|         = NaN ≰ 0.0e+00
# |f(x) - f(x')|/|f(x')| = NaN ≰ 0.0e+00
# |g(x)|                 = NaN ≰ 1.0e-08

# * Work counters
# Seconds run:   0  (vs limit Inf)
# Iterations:    1000
# f(x) calls:    4003
# ∇f(x) calls:   0
@longemen3000
Copy link
Contributor

longemen3000 commented Sep 20, 2021

this is a known behaviour, as Particle swarm will always use the maximum number of iterations. the bug is in the display of the output, not in the result. this happens because the algorithm can't know if the current best solution is the solution to the optimization problem, so its determined to be the result given at the last iteration.

@marlloseff
Copy link
Author

this is a known behaviour, as Particle swarm will always use the maximum number of iterations. the bug is in the display of the output, not in the result. this happens because the algorithm can't know if the current best solution is the solution to the optimization problem, so its determined to be the result given at the last iteration.

Ok longemen3000, thanks.

@pkofod
Copy link
Member

pkofod commented Sep 20, 2021

Yeah, it's a bit of a strange thing to print. Particle swarm is never meant to "settle down", it will always try to escape any local optimum (but will often return if it was indeed at the global optimum). It should be changed so I'll keep it open.

@marlloseff
Copy link
Author

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants