pymoo icon indicating copy to clipboard operation
pymoo copied to clipboard

Issue with PSO and small population size

Open mihofer opened this issue 3 years ago • 0 comments

Hi,

Through a typo, I stumbled onto an issue where running PSO with a population size of 2 runs into a ValueError: unsupported format character '-' (0x2d) at index 2.

MWE:

from pymoo.core.problem import ElementwiseProblem
from pymoo.optimize import minimize
from pymoo.algorithms.soo.nonconvex.pso import PSO

class MyProblem(ElementwiseProblem):

    def __init__(self, **kwargs):
        super().__init__(n_var=10, n_obj=1, n_ieq_constr=0, xl=-5, xu=5, **kwargs)

    def _evaluate(self, x, out, *args, **kwargs):
         out["F"] = (x ** 2).sum()

problem = MyProblem()

res = minimize(problem, PSO(pop_size=2), termination=("n_gen", 10), seed=1, save_history=False, verbose=True,)

The problem seems to originate from the _adapt method when calculating the new inertia weight yields an overflow error, which then creates an issue with the display output. Running with either adaptive=False , verbose=False, or a population size >= 3 fixes the issue. It also only appears with PSO, other algorithms like GA, ES, etc. work fine with such a small population size.

Arguably, running with such small population sizes is more of a user mistake than anything but maybe a warning could be issued if an algorithm is initialized with nonsensical values.

Otherwise, great package, works like a charm, and the documentation is really nice ( and improved with the latest release).

mihofer avatar Aug 09 '22 07:08 mihofer