esa / pygmo2

A Python platform to perform parallel computations of optimisation tasks (global and local) via the asynchronous generalized island model.
https://esa.github.io/pygmo2/
Mozilla Public License 2.0
434 stars 57 forks source link

Getting the best particle after each iteration of PSO #36

Closed simone-fontana closed 4 years ago

simone-fontana commented 4 years ago

For debugging purposes, I need to get the best particle (and do some computation with it) after each iteration of PSO. To my understanding, there is no direct way of doing it. I thought that one workaround could be to set the gen parameter to 1, call the evolve method in a loop and get the best after each call. However, I was wondering whether calling many times evolve is the same as calling it once, with the gen parameter appropriately set. Looking at the code of PSO, it seems that my solution would be inefficient (since it would repeat the initialization at the beginning of evolve many times), but it should not change the result. Am I right?

darioizzo commented 4 years ago

Yes the result is the same. In case of pso (https://esa.github.io/pygmo2/algorithms.html#pygmo.pso) you need to set memory= True so that velocities are not reset between succewssive calls.