-
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
Created class for pyramid topology #142
Created class for pyramid topology #142
Conversation
Created a class for the implementation of a pyramid topology using Delaunay triangulation. Also created a test file which does *not* work yet! Additionally, I changed a small error in the description of the `compute_velocity()` method in the Ring class
pyswarms/backend/topology/pyramid.py
Outdated
else: | ||
return (best_pos, best_cost) | ||
|
||
def compute_velocity(self, swarm, clamp=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @whzup , can you check the indentation here? I think you should move this 4 spaces backward 👍
Right now, it is aligned inside def compute_gbest()
, the three methods should be on the same level.
On my end, I wonder why it didn't raise any NotImplementedError
...
pyswarms/backend/topology/pyramid.py
Outdated
""" | ||
return ops.compute_velocity(swarm, clamp) | ||
|
||
def compute_position(self, swarm, bounds=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same issue with the indentation here 👍
Hey @whzup ! Awesome PR and I really appreciate you stepping up. For now, I think the issue with the missing argument is on the indentation of Hope this change will pass the tests from now on. Hopefully on Monday I can review the implementation itself. Another thing, we would appreciate if you can format your git commit messages similar to (this)[https://chris.beams.io/posts/git-commit/]. I know it's weird that we use present tenses than past tenses, but yeahp, let's just follow what been done before 👍 . Thanks a lot! |
Fix indentation error in the Pyramid class that prevented the tests from running. See also: #142
Thanks for the feedback! That was actually the error and it passes the test now. I am going to test it a bit further such that it might be used in an optimization class because, at the moment, it only tests the case when it actually does the same job as the Star topology (when there are less than 5 particles in the swarm). I'm sorry I wasn't aware of such a style guide, I'll try to incorporate these rules from now on! (I tried it in the correction commit to the indentation issue in my forked repo) Is there a way to correct the body of commits? |
Awesome! It's fine @whzup !
Usually, if we want to edit commits, we use Be careful though, and make sure that every time you commit, you are just editing one file (or subset of files). Rebase commands can cause conflicts within the history etc. But if you're just rewording your commit messages, then there's no problem. Some helpful links:
In practice, what I usually do is to have
This categorizes commits related to the main file and the test files. So after rebasing, it will now look like this:
But of course, your mileage may vary, check what works for you 👍
Nope no need! Just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @whzup!
Glad that it's working right now. 👍 I actually checked the Delaunay implementation before and I think it does resemble the Pyramid topology in literature. I just have some few comments below, and I think we will be all set.
pyswarms/backend/topology/pyramid.py
Outdated
idx = np.array() | ||
# Insert all the neighbors for each particle in the idx array | ||
for i in range(swarm.n_particles): | ||
idx.append(indptr[indices[i]:indices[i+1]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Can you check if this can be golfed via list-comprehension?
As far as I know list comps are much faster than initializing an array and appending to it.
idx = [indptr[indices[i]:indices[i+1] for i in range(swarm.n_particles)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I guess that is possible! I'm currently struggling with the rebasing. I rebased a wrong commit and I'm trying to resolve the mess I did 😃. Could I just refork the repo and add the files again? Or is does this mess up anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, nevermind got it working now! It's online now 👍.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Yup just found it right now!
pyswarms/backend/topology/pyramid.py
Outdated
best_cost = np.min(swarm.pbest_cost) | ||
else: | ||
pyramid = Delaunay(swarm.position) | ||
indices, indptr = pyramid.vertex_neighbor_vertices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what indptr
stands for? Index pointer? 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can change this into a more understandable variable? 👍
Created a class for the implementation of a pyramid topology using Delaunay triangulation with a test file for the standard tests. Additionally, changed a small error in the description of the compute_velocity() method in the Ring class. See also: #129
…into pyramid_topology
Added a list comprehension for obtaining the indices and changed the variable name indptr to index_pointer. See also: #142
Okay, so what I will do now is squash all your commits into a single one. If you wish to contribute again, simply fork the development branch. Or perhaps pull the new changes in your own repository 👍 Wow, thanks for your contributions @whzup ! You're really nice to work with, I appreciate your help! The commits you've done will show up once we've merged everything to master and released v.0.3.0. I'm really thankful for all your help in improving PySwarms! Hope you enjoyed and learned something in the process! |
Thanks! Really appreciate the working environment here, it's so friendly! I have just been working on the tests for the
Additionally, the respective list with indices of the neighbours for every point does not always have the same length! So if I run the script I get an I thought about filling in the missing values. But then the question raises with what? If I just choose 0 it might yield a wrong result for the best neighbour and if I choose infinity it would raise an |
Hmmm... let me check on this on the weekend.
Yes please, can I see what tests you ran? Is this more of an edge-case or
it’s a pretty regular thing given a certain input?
For now let’s just isolate a PR for the Pyramid class first before the
“topology attribute in the SwarmOptimizer.”
Awesome! I might respond slowly in the next few days because of thesis. But
I’ll get back to you this weekend.
On Wed, 27 Jun 2018 at 00:26 Aaron ***@***.***> wrote:
Thanks! Really appreciate the working environment here, it's so friendly!
I have just been working on the tests for the pyramid class and found
that there is a little bug and I'm not quite sure how to resolve it without
using an ugly workaround. When the list with the indices of the neighbours
is created it actually creates an array of floats:
idx = np.array([index_pointer[indices[i]:indices[i+1]] for i in
range(swarm.n_particles)])
Additionally, the respective list with indices of the neighbours for every
point does not always have the same length! So if I run the script I get an IndexError:
arrays used as indices must be of integer (or boolean) type. So I tried
to switch the data type of the array to integer but then it raises a ValueError:
setting an array element with a sequence.
I thought about filling in the missing values. But then the question
raises with what? If I just choose 0 it might yield a wrong result for the
best neighbour and if I choose infinity it would raise an IndexError. Do
you know an easy solution? I have searched for appropriate functions but I
don't find anything useful. Shall I create another PR so you can inspect
the code? I also added tests for the pyramid class and a topology
attribute to the SwarmOptimizer class, such that you can use it as a
constructor parameter.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#142 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMWYs62dnb8HtOhw8b0725XShv4avKldks5uAlK3gaJpZM4U0tko>
.
--
Lester James V. Miranda
BS Electronics and Communications Engineering,
Minor in Philosophy (Class of 2016)
Ateneo de Manila University
lester.miranda@ <[email protected]>*o
<http://toki.waseda.jp>bf.ateneo.edu <http://bf.ateneo.edu>*
|
See #147. The tests are actually dependent on the topology attribute so I just left it in. Sorry for the commit mess in the new PR. I feel like Git is very unforgivable and I missed the opportunity to refork the new |
It’s fine! I actually made a comment as well regarding this in #147. Haha!
Let’s just make the discussion in that PR.
On Wed, 27 Jun 2018 at 01:12 Aaron ***@***.***> wrote:
See #147 <#147>. The tests
are actually dependent on the topology attribute so I just left it in.
Sorry for the commit mess in the new PR. I feel like Git is very
unforgivable and I missed the opportunity to refork the new development
branch.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#142 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMWYs6NFLEsMUi2zfnWnzGMDMV50RSDlks5uAl1SgaJpZM4U0tko>
.
--
Lester James V. Miranda
BS Electronics and Communications Engineering,
Minor in Philosophy (Class of 2016)
Ateneo de Manila University
lester.miranda@ <[email protected]>*o
<http://toki.waseda.jp>bf.ateneo.edu <http://bf.ateneo.edu>*
|
Created a class for the implementation of a pyramid topology using Delaunay triangulation. Also created a test file which does not work yet! (see issue #129 for a description of the problem)
Additionally, I changed a small error in the description of the
compute_velocity()
method in the Ring class, where the use case imported the Star class instead of the Ring class.