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

Inaccuracy in PSO example? #685

Open
mariosky opened this issue Jan 24, 2023 · 0 comments
Open

Inaccuracy in PSO example? #685

mariosky opened this issue Jan 24, 2023 · 0 comments

Comments

@mariosky
Copy link

mariosky commented Jan 24, 2023

There is an inaccuracy on the PSO example on the smin and smax parameters.
When the parameters are used in the constructor, they are similar to pmin and pmax:

toolbox.register("particle", generate, size=2, pmin=-6, pmax=6, smin=-3, smax=3)

They seem to be a minimum and maximum speed range.
But when a particle is updated, they seem to have a different meaning:

for i, speed in enumerate(part.speed):
        if abs(speed) < part.smin:
            part.speed[i] = math.copysign(part.smin, speed)
        elif abs(speed) > part.smax:
            part.speed[i] = math.copysign(part.smax, speed)

In this case, with smin having a negative value, the first conditional will never be true.
I think the code has a different meaning: smin is the minimum absolute value of the speed regardless of direction.
So, a particle could have a speed from 0.3 to 3 negative or positive. I think this more useful.
The case above works because it is symmetric around zero.
Maybe the parameter should be:

toolbox.register("particle", generate, size=2, pmin=-6, pmax=6, smin=0, smax=3)

I think if someone wants different smin it will not work:

toolbox.register("particle", generate, size=2, pmin=-6, pmax=6, smin=-1, smax=3)
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

1 participant