-
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
Add Das-Dennis weight initialization method #295
Conversation
include/ensmallen_bits/moead/weight_init_policies/uniform_init.hpp
Outdated
Show resolved
Hide resolved
auto BinomialCoefficient = | ||
[](size_t n, size_t k) -> double | ||
{ | ||
return std::tgamma(n + 1) / (std::tgamma(k + 1) * std::tgamma(n - k + 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.
I was wondering why there's an integer overflow happening here; then it hit me. std::tgamma(300)
is shooting off to infinity. This is a very naive approach to finding Binomial Coefficient, I guess I could utilize the fact that the denominator and numerator cancel out a lot of terms. Though it'll certainly be nice if armadillo had a support for this algorithm built-in cc/ @conradsnicta
The build failure seems unrelated to the PR. @zoq your insights would be helpful, thanks. EDIT: It does look related but I don't get how. I haven't even anything out of the ordinary. |
I'm getting errors on |
Huh, do you have a link to the Travis build, looks like it's down for me. |
Fixed it, I was missing a brace. C++ is so fun |
=> Use 300 instead of 150 population => DefaultMOEAD = MOEAD<Uniform, Tchebycheff>
@@ -72,8 +74,8 @@ class MOEAD { | |||
* @param upperBound The upper bound on each variable of a member | |||
* of the variable space. | |||
*/ | |||
MOEAD(const size_t populationSize = 150, | |||
const size_t maxGenerations = 300, | |||
MOEAD(const size_t populationSize = 300, |
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.
Was the test failing with populationSize = 150
?
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 because the binomial coefficient value (H) should equate to the size of the population. This algorithm is restrictive in that way. You can read Section IV (If I recall correctly) of the cited paper to know more. To ensure this, you can find I've added an if
statement inside Generate
method to catch a mismatch.
The main point is, there is only a certain number of points that can be generated uniformly given the number of partitions(gaps between points) and the number of objectives.
include/ensmallen_bits/moead/weight_init_policies/uniform_init.hpp
Outdated
Show resolved
Hide resolved
point.insert_rows(point.n_rows, RowType(1).fill( | ||
delta * static_cast<ElemType>(beta))); |
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.
It's not super clean, but I think it works, at least this way we can avoid the std::vector conversion.
auto BinomialCoefficient = | ||
[](size_t n, size_t k) -> size_t | ||
{ | ||
size_t retval = 1; | ||
// Since, C(n, k) = C(n, n - k). | ||
if (k > n - k) | ||
k = n - k; | ||
|
||
// [n * (n - 1) * .... * (n - k + 1)] / [k * (k - 1) * .... * 1]. | ||
for (size_t i = 0; i < k; ++i) | ||
{ | ||
retval *= (n - i); | ||
retval /= (i + 1); | ||
} | ||
|
||
return retval; | ||
}; | ||
return BinomialCoefficient(numObjectives + numPartitions - 1, numPartitions); |
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.
Note to myself, check that part in more depth.
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.
Add this to your notes.
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.
So, thinking about this... The lambda usage is nice, but should we maybe prefer to write this as a standalone function? Similar to the link post? Also, I think the code on the link post is 1-1 with what is written here. Do we need to worry about licensing?
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 reason for making it lambda inside the function was to secure the scope, it won't be used elsewhere. Regarding the heavy correlation, GFG (Geeks for geeks) is kinda open-sourced, and is made to help people(like Stack Overflow). Besides, finding Binomial Coefficient in O(n) isn't a ground breaking research that we're using without citing :) .
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.
According to https://www.geeksforgeeks.org/copyright-information/ this is fine, but let's add a comment which references the source for the code.
….hpp Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
….hpp Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
….hpp Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
Could you re-trigger the CI please? The build was cancelled for some reason. Thanks. |
Done. |
It got cancelled again... |
include/ensmallen_bits/moead/weight_init_policies/uniform_init.hpp
Outdated
Show resolved
Hide resolved
….hpp Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
Added |
@coatless Would you like to have a pass over this? Thanks. |
include/ensmallen_bits/moead/weight_init_policies/uniform_init.hpp
Outdated
Show resolved
Hide resolved
….hpp Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
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.
Looks great to me.
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.
See notes.
auto BinomialCoefficient = | ||
[](size_t n, size_t k) -> size_t | ||
{ | ||
size_t retval = 1; | ||
// Since, C(n, k) = C(n, n - k). | ||
if (k > n - k) | ||
k = n - k; | ||
|
||
// [n * (n - 1) * .... * (n - k + 1)] / [k * (k - 1) * .... * 1]. | ||
for (size_t i = 0; i < k; ++i) | ||
{ | ||
retval *= (n - i); | ||
retval /= (i + 1); | ||
} | ||
|
||
return retval; | ||
}; | ||
return BinomialCoefficient(numObjectives + numPartitions - 1, numPartitions); |
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.
So, thinking about this... The lambda usage is nice, but should we maybe prefer to write this as a standalone function? Similar to the link post? Also, I think the code on the link post is 1-1 with what is written here. Do we need to worry about licensing?
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. 👍
Great, now I have to wait another 2 days. |
@jonpsy not at all! From the first approval it will automatically give a second after 24 hours. Once the second bot-approval is in, we can merge. :) |
Continuing #293
DefaultMOEAD = MOEAD<Uniform, Tchebycheff>
.BBSMOEAD = MOEAD<BayesianBootstrap, Tchebycheff>