-
Notifications
You must be signed in to change notification settings - Fork 227
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
particle_swarm #218
particle_swarm #218
Conversation
I'll review it as soon as I can. Do you have a reference? |
This is awesome. I'll make a cursory review and let @pkofod handle the rest. |
@@ -0,0 +1,383 @@ | |||
using Distributions |
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.
You generally shouldn't do this in library code for several reasons:
- You've added a dependency that was intentionally removed from this package in the past.
- You've done it in the wrong place: dependencies should always be listed in the main package file at
src/Optim.jl
because they have global effects - You've introduced a major change in the global namespace.
My suggestions:
- Try to find a way to not use Distributions.jl. I won't say that's an absolute requirement for merging, but think of it as being one to motivate you. :)
- Make sure you move the importing to
src/Optim.jl
. - Do the importing using
import Distributions
and use fully qualified names likeDistributions.Gamma
everywhere.
here is the reference to the paper |
immutable ParticleSwarm <: Optimizer | ||
xmin::Array | ||
xmax::Array | ||
nParticles::Int |
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.
This is the wrong case convention for Julia code: you should use underscores here.
This is a very impressive first PR. I've made a lot of comments about stylistic conventions you should try to adopt when contributing to packages with an existing style of code. I'll let Patrick make sure the substantive stuff is right. |
Thanks for the advice! |
autodiff = autodiff) | ||
method = get_optimizer(method)::Optimizer | ||
optimize(f, initial_x, method, options) | ||
end |
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.
What is your intention here? You're basically creating a new method that defaults to ParticleSwarm if given a function and an array, but the method just below overrides that method, and NelderMead is again the default (which it probably should be, unless we find particle swarm to be a better default solver).
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.
my bad. I simply copied from NelderMead() and forgot to get rid of it after the fact.
I'm in the middle of moving these days, so I don't have too much time, but I will get back to this. I will also read the article just to have two set of eyes that can catch bugs. Generally, I think you should start with John Myles White's comments, as I agree with those. Then I'll take a shot at giving comments when that is in place. What is the problem with the traces? |
Current coverage is 84.47%@@ master #218 diff @@
==========================================
Files 30 31 +1
Lines 1896 2138 +242
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 1596 1806 +210
- Misses 300 332 +32
Partials 0 0
|
sorry guys but I need some git help to proceed here.
but now git tells me I cannot push my changes
Is the suggested step from the error message the right way to proceed? I dont want to mess up stuff.. :) |
Honestly, you're best off just making a copy of any work that's unsaved and trying things until they work. Something like the suggestion in the error message is likely to work, but I'm not sure exactly what's necessary. |
well.. :) what would be the proper way to start something like this? (this = working on a PR from a different machine) |
Ignore the PR part. You have a repo (which is your fork) and a branch (which is the branch you're using on your fork). You need to clone your repo, checkout the branch and do work from there. |
Yes, that is what I was thinking initially (and will do this from now on) but the reason I went the other way was this thought: How can I then pull the latest changes anyone else does on the original Optim.jl code into my repo? |
Oh and the following: When cloning my repo to my machine: where do I clone it to? If it is a arbitrary location, how do I tell Julia to use that one? Sorry for the noobery... |
I'm not sure I follow, didn't you just say n equal to length of x was a good rule of thumb ? At least n equal to 10 seems too small for some of the problems. |
True, but because lenght(x) < 100 there will not be an increase in
|
Sure, I just wanted to see how it performed given that particular rule of thumb. I didn't expect it to outperform n=100 |
Good catch on the Edit: I'm not sure the const is necessary though. I'm not sure it does what you think. Consider
|
@abieler have you given the |
To be honest, no.. Was buried under a pile of work and have not looked at this for a while now. |
You should never trust my judgement :) I just don't think they add anything, but I could be wrong. Edit Also, if you're busy, don't worry. There's no rush! |
I ll free some time next week to look into this. |
Cool, let me know if I can help you. |
profiling with and without const showed no difference in performance, so I removed them. |
there is still the issue with my arbitrary choices of f_converged = true
ftol = 1e-2 which are hard coded after an optimization run. same thing for ftol. I have no use for this variable (yet?) in the current implementation. |
Just return false and nan? |
Can do. Was more of a question on what makes sense or if there is a convention of some sorts for similar cases. |
If there is some small thing left to do I can probably take care of it tomorrow. I ll then be off the grid for 3 weeks starting Saturday. |
I will see if I can find something, but right now I think it's pretty good to go. If there are minor details, I can fix them after a merge. It would be nice if you could add a bit of details to the docs (when you return) about the implementation, and how to control the various parts of the algorithm. |
Cool. Looking forward to being a contributor to Julia :D I also played a little bit with an option of a swarm with limited memory. this could be used in cases One step at a time. |
I'll look it through one more time later, and then I will probably merge unless someone else has any comments. And thank you for the contribution. |
rebase the commits into just one perhaps? |
Github allows you to squash upon merge now, so I'll just do that :) |
n_particles::Int | ||
end | ||
|
||
ParticleSwarm() = ParticleSwarm([], [], 0) |
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 hadn't seen these. This should probably just be a empty constructor with keywords. I might just merge and fix it.
Work left to be done here : change xmin and xmax to x_min and x_max, fix the constructor, and add docs. I will merge it tomorrow, and fix the notation thing, and the constructor in a follow-up commit, as @abieler is off the grid. It would be wonderful if you could add docs when you get back. I didn't think about it earlier, but I also asked for it in the #238 PR. I think it is much better if people who contribute a solver also has a go at the docs themselves. |
A great first PR! Thanks for doing this. |
implementation of the adaptive particle swarm algorithm which is a global optimization method.
tested this algorithm on many real world problems. although being slower than
the gradient based versions it proves stable, especially for systems with "real" data
which can be noisy or in other ways hampered.
I tried my best to have the code in similar form as the other packages in Optim.jl, but surely there
is a lot of room for improvement.
No optimization for speed done yet.
My first PR, so go easy on my ;)