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:
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:
There is an inaccuracy on the PSO example on the
smin
andsmax
parameters. When the parameters are used in the constructor, they are similar topmin
andpmax:
They seem to be a minimum and maximum speed range. But when a particle is updated, they seem to have a different meaning:
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:I think if someone wants different
smin
it will not work: