Early stropping (ftol) if cost isn't reduced
See original GitHub issueDescribe the bug When the ftol is used and the best cost is equal in two consecutive iteration, the search is stopped even if the cost is high.
To Reproduce
options = {'c1': 0.5, 'c2': 0.3, 'w':0.9} optimizer = ps.single.GlobalBestPSO(n_particles=100, dimensions=2, options=options, ftol=1e-10) cost, pos = optimizer.optimize(fx.sphere, iters=1000, n_processes=None, verbose=True)
Output is something like this.
Position: [0.06410654 0.02934344], Cost: 0.0049706854704889645
As can be seen, x1 and x2 are far from zero, the cost is relatively high, and it’s much higher than 1e-10. The reason is that the algorithm couldn’t find lower cost so the swarm.best_cost is equal to best_cost_yet_found. So the search is stopped even if the cost remains high.
Environment (please complete the following information):
- PySwarms Version 1.1.0
How to fix In optimizer code, an additional check should be performed to ignore if swarm.best_cost == best_cost_yet_found. After applying the fix, the output will be:
Position: [-8.05105641e-06 -6.63608458e-07], Cost: 6.525988549305629e-11
Issue Analytics
- State:
- Created 3 years ago
- Comments:36 (29 by maintainers)
Top GitHub Comments
Hi @nishnash54 I was busy with my thesis, I just finished reading the PR #401 . You guys were having so much fun 😃
Yes, You can use my code, actually I have should I posted my previous comment in that PR.
I will comment only on ftol_iter part. ftol_iter causes early stopping and can be stuck at a local optimum and that is what we intended to do by using ftol_iter. This option is for users who are only interested in finding a good feasible solution, but not an exact global solution because they have a big problem. In my case, each iteration takes 3 minutes, and I usually run more than 500 iterations. In my case, a fast good feasible solution is a lot better than a late exact solution.