-
Notifications
You must be signed in to change notification settings - Fork 334
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
User-provided initial positions #119
Comments
Hi @szhan , currently there is no explicit implementation for that, but we're currently developing a feature for this in #115 and #117 . The only workaround we can have here is to initialize the swarm as usual, then set the import numpy as np
import pyswarms as ps
# Your own initial positions of shape (3,3)
my_own_init_pos = np.array([[1,2,3], [4,5,6], [7,8,9]])
# Initialize optimizer, this creates a position and velocity matrix of shape (3,3)
options = {'c1':0.5, 'c2':0.4,'w':0.9}
optimizer = ps.single.GlobalBestPSO(n_particles=3, dimensions=3, options=options)
# Provide your own init_pos
optimizer.pos = my_own_init_pos.copy()
# Do optimization below
# optimizer.optimizer()... I realized that this functionality is actually important upon releasing, so hopefully the next update will give this capability. For now, I hope this workaround works. |
Thanks, @ljvmiranda921! Also, I would like to help with the development of PySwarms, as I find it quite useful in my work. |
I have tried the workaround you suggested, but I am encountering an error that I cannot make sense of. I wrote a wrapper to feed GlobalBestPSO() some initial positions to solve some BBOB function. When trying to have it solve the Rastrigin function, I got the following error:
The initial positions are clearly within bounds. I also checked the source code, and even tried the condition that checks for the bounds. All seems to be in order. What makes it even more puzzling is that it works perfectly fine for the Ackley function! Am I not seeing something very obvious? My wrapper is as follows:
Update: It works when using different values for the initial positions to solve Rastrigin, e.g., [2.0, 0, -0.02] works but [2.0, 3.0, -0.02] does not. |
Okay, that's weird. Hmmm, let me check on this later. Thanks for reporting this @szhan ! |
Thanks, @ljvmiranda921 ! I am actually quite interested in topology selection. So, I think I will help with implementing additional topologies first. |
Awesome, let me update you once I need help. Just need to clean up what I'm doing first then I'll ping you right away! |
Reference: #119 The name init_pos tends to be confusing. We're not really setting the initial positions here. Instead, we're just defining where the center is whenever the swarm is generated. Next, we'll set an init_pos variable so that we can explicitly set the center Signed-off-by: Lester James V. Miranda <[email protected]>
Resolves #119 This commit adds an option to set the initial position in a more exposed way. This also performs some checks to see if the init_pos confirms with the bounds. Signed-off-by: Lester James V. Miranda <[email protected]>
Reference: #119 Tests the init_pos feature for swarm generation. Checks cases when: - init_pos and bounds is not None - init_pos and bounds is None - either init_pos or bounds is None (2 cases) Signed-off-by: Lester James V. Miranda <[email protected]>
Reference: #119 This commit exposes the init_pos option for user-defined initial positions in the SwarmOptimizer base class and gbest and lbest implementations. Signed-off-by: Lester James V. Miranda <[email protected]>
Reference: #119 This commit exposes the init_pos option for user-defined initial positions in the SwarmOptimizer base class and gbest and lbest implementations. Signed-off-by: Lester James V. Miranda <[email protected]>
Reference: #119 The name init_pos tends to be confusing. We're not really setting the initial positions here. Instead, we're just defining where the center is whenever the swarm is generated. Next, we'll set an init_pos variable so that we can explicitly set the center Signed-off-by: Lester James V. Miranda <[email protected]>
Resolves #119 This commit adds an option to set the initial position in a more exposed way. This also performs some checks to see if the init_pos confirms with the bounds. Signed-off-by: Lester James V. Miranda <[email protected]>
Reference: #119 Tests the init_pos feature for swarm generation. Checks cases when: - init_pos and bounds is not None - init_pos and bounds is None - either init_pos or bounds is None (2 cases) Signed-off-by: Lester James V. Miranda <[email protected]>
Reference: #119 This commit exposes the init_pos option for user-defined initial positions in the SwarmOptimizer base class and gbest and lbest implementations. Signed-off-by: Lester James V. Miranda <[email protected]>
Is your feature request related to a problem? Please describe.
I would like to specify the starting positions of every particle in a swarm.
Describe the solution you'd like
I see that init_pos can be specified, but it only allows the user to specify a starting position for the swarm's center. Looking at the code of pyswarms.base.base_single, it seems that reset() needs to be extended or modified. That is, I need to update how self.pos is being initialized. So, I would provide a list of starting positions to self.pos. Is there an already existing alternative to this?
The text was updated successfully, but these errors were encountered: