-
Notifications
You must be signed in to change notification settings - Fork 120
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
Improvise NSGA2 #263
Improvise NSGA2 #263
Conversation
//TODO: Shouldn't we check if they're inside the upperBound && lowerBound? | ||
for (size_t i = 0; i < populationSize; i++) | ||
{ | ||
population.push_back(arma::randu<MatType>(iterate.n_rows, |
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.
Shouldn't we check if they're inside the upperBound && lowerBound? Am I missing something?
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 have to check the paper, not sure if the constrained was only for the mutation/crossover step or for the initial population as well. Also might be good to reference the paper instead of another python implementation.
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.
/*if limits are specified it generates the value in
range of minimum and maximum value of the variable*/
else
{
pop_ptr->ind[i].xreal[j] = d*(lim_r[j][1] - lim_r[j][0])+lim_r[j][0];
}
Source: realinit.h, Original Implementation in C, IITK Kanpur Genetics Laboratory.
//Remove the empty final set | ||
fronts.pop_back(); |
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.
Caught a big fish here. Allow me to explain myself,
- The while loop breaks when the newFront is empty. Note that the newFront is pushed regardless of any of the conditions.
- At the terminate stage of our while loop, the nextFront is not updated at all! That means its an empty vector which gets pushed into our
front
- This causes the while loop to terminate
Result?
You got an additional empty vector in your front
set. Which causes smelly code.
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.
Nice catch!
//TODO: Shouldn't we check if they're inside the upperBound && lowerBound? | ||
for (size_t i = 0; i < populationSize; i++) | ||
{ | ||
population.push_back(arma::randu<MatType>(iterate.n_rows, |
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 have to check the paper, not sure if the constrained was only for the mutation/crossover step or for the initial population as well. Also might be good to reference the paper instead of another python implementation.
Sounds good to me, if we can show that an OpenMP solution is faster let's integrate it into the current method, but maybe armadillo build against openblas is already faster, haven't read the paper yet. |
@@ -150,7 +161,7 @@ typename MatType::elem_type NSGA2::Optimize( | |||
|
|||
// Perform crowding distance assignment. | |||
crowdingDistance.resize(population.size()); | |||
|
|||
std::fill(crowdingDistance.begin(), crowdingDistance.end(), 0.f); |
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 guess before the reset to zero, we got lucky, because in the CrowdingDistanceAssignment
method we use front[i + 1]
which should be undefined:
crowdingDistance[front[i]] += (crowdingDistance[front[i - 1]] -
crowdingDistance[front[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.
Ahh, nevermind we set it to zero before as well.
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.
@zoq Regarding this, I think this implementation is wrong. Here's an excerpt from the paper
Notice the equation should've been
crowdingDistance[front[i]] += (fValue[i+1] - fValue[i-1])/(maxFval - minFval)
and not the average of crowdingDistances
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've implemented it in this patch
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.
Good, can you make the patch part of the PR?
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've no problem with that. Thing is, @say4n has implemented assignment first and sorting later which I think is wrong but I guess he must have some reason. I was waiting for his review, very well, I'll add this patch on my PR.
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 think I had unrolled the first iteration of some parts of the optimisation loop to be outside the for loop. This had the benefit of instantiating some items as far as I recall. I don't remember all the details now so do take this with a grain of salt!
Also, sorry for the delays, I have a bunch of impending exams and a ton of work. 😢
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.
Thanks for clarifying :). I'd say let's merge my patch for now as it is straightforward & adheres to the research paper directly. We can then try your optimization method and see how it all fits in.
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.
Yes, for sure! Great work btw!!
@@ -150,7 +161,7 @@ typename MatType::elem_type NSGA2::Optimize( | |||
|
|||
// Perform crowding distance assignment. | |||
crowdingDistance.resize(population.size()); | |||
|
|||
std::fill(crowdingDistance.begin(), crowdingDistance.end(), 0.f); |
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.
Ahh, nevermind we set it to zero before as well.
All the tests pass, Wohoo!. All the tasks are done as well. @zoq Do you have any comments? |
I'll do another pass over the PR, in the meantime can you update the |
AppVeyor is failing, but the tests work, can you throw some light on this please? |
Strange, I have to debug this on a local machine, but looks like the windows build never passed on this PR. |
On second thought, I think its better to keep |
Your question is well-founded, it looks like Appveyor cmd does not repeat for 3000 times, even after putting Let me know if you require further proof. |
Thanks, I just was just wondering what it was, thanks for tracking this down. |
I restarted the windows build. because the build failed, not sure it's because of the RDP session. |
The build fails because of RDP. Its waiting for us to access it, and terminates when we dont. @zoq , do we agree the algorithm is working? If so, I'll revert RDP changes and the build would pass. |
Ahh, right I have seen you removed it from one section, but looks like not from the other one. This looks good, so let's remove it. |
Hi @zoq , is this GTM? |
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 looks really good to me, just one more really minor style issue.
Once #283 is merged, I will incorporate that feature along with the rebase changes + static analysis fix changes. |
All right, waiting for the green tick :) . |
All green! 🥳 |
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.
Thanks for another great contribution 👍
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.
Second approval provided automatically after 24 hours. 👍
Thanks for digging into the optimization method, really nice improvements. |
Continuation of #262 .
The goal of this PR is to increase the efficiency of this code, enhance its expressibility and reducing its code size as much as possible.
Summary of my goals:
for
loopsI have a few questions before I do that, let me know your thoughts on that.
Providing logs for the convenience of the reader. Stay tuned for more progress updates!
LOGS
Main Loop
Fast Non Dominated Sorting
fronts.size() > 0
==>!fronts.empty()
Crowding Distance Assignment
crowdingDistance
0 initialisation out of the functionfronts.size() > 0
check, since empty front isn't passed at all. Refer the above section.crowdingDistance
is filled using objective values not by taking average ofcrowdingDistance
The calculation seems to be very roundabout, need to confirm with @say4n. If you're reading this, can you check this patchAs discussed, going with the patch.Testing
fmat