psopy icon indicating copy to clipboard operation
psopy copied to clipboard

Shapes consistency

Open ne3x7 opened this issue 6 years ago • 1 comments

Hi! Thanks for your awesome project.

I was checking it out when I ran into a ValueError: operands could not be broadcast together with shapes (D,) (N,), where D is my dimensionality and N is swarm size. It appears after quite a number of successful iteration on the line where you determine global and local gradient:

dv_g = g_rate * uniform(0, 1) * (gbest - position)

It seems that gbest and position are not of the same shape, or gbest doesn't broadcast in position properly.

I am running psopy from pip in python 3.6.3.

Also, is there a limit for number of constraints for efficient computation?

ne3x7 avatar Mar 13 '19 21:03 ne3x7

Could you please send me the call stack for the error and the meta-parameters passed to the method, if possible?

Regarding the constraints, there are two aspects to the way constraints are handled in the code,

  1. Initializing the particles to feasible solutions: The default implementation here uses random sampling. More constraints would just mean generating more samples. If this is taking too long, you could write a more efficient way to generate initial solutions, or run this once and cache the initial solutions.
  2. Updating pbest to ensure the final solutions are feasible. This is a O(nm) operation, with n being the number of constraints and m being the number of particles. You may need to consider this for computation time.

jerrytheo avatar Mar 25 '20 19:03 jerrytheo