Skip to content
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

Merged
merged 19 commits into from
Jun 23, 2021
Merged

Conversation

jonpsy
Copy link
Member

@jonpsy jonpsy commented Jun 18, 2021

Continuing #293

  • Add uniform_init.hpp.
  • Use DefaultMOEAD = MOEAD<Uniform, Tchebycheff>.
  • Use BBSMOEAD = MOEAD<BayesianBootstrap, Tchebycheff>
  • Test and verify its working locally.
  • Document uniform_init.hpp.
  • Add documentation in optimizers.md.
  • HISTORY.md.

Comment on lines 55 to 58
auto BinomialCoefficient =
[](size_t n, size_t k) -> double
{
return std::tgamma(n + 1) / (std::tgamma(k + 1) * std::tgamma(n - k + 1));
Copy link
Member Author

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

@jonpsy
Copy link
Member Author

jonpsy commented Jun 18, 2021

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.

@jonpsy
Copy link
Member Author

jonpsy commented Jun 18, 2021

I'm getting errors on adagrad_test.cpp for the changes I did in moead class. I'm done with C++ 👍 .

@zoq
Copy link
Member

zoq commented Jun 18, 2021

I'm getting errors on adagrad_test.cpp for the changes I did in moead class. I'm done with cpp .

Huh, do you have a link to the Travis build, looks like it's down for me.

@jonpsy
Copy link
Member Author

jonpsy commented Jun 18, 2021

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,
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

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.

Comment on lines +152 to +153
point.insert_rows(point.n_rows, RowType(1).fill(
delta * static_cast<ElemType>(beta)));
Copy link
Member

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.

Comment on lines +83 to +100
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);
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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 :) .

Copy link
Member

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.

jonpsy and others added 3 commits June 18, 2021 21:13
….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>
@jonpsy
Copy link
Member Author

jonpsy commented Jun 18, 2021

Could you re-trigger the CI please? The build was cancelled for some reason. Thanks.

@zoq
Copy link
Member

zoq commented Jun 18, 2021

Could you re-trigger the CI please? The build was cancelled for some reason. Thanks.

Done.

@jonpsy
Copy link
Member Author

jonpsy commented Jun 18, 2021

It got cancelled again...

@jonpsy
Copy link
Member Author

jonpsy commented Jun 18, 2021

Added using BBSMOEAD = MOEAD<BayesianBootstrap, Tchebycheff> along with documentation in optimizers.md.

@jonpsy
Copy link
Member Author

jonpsy commented Jun 19, 2021

@coatless Would you like to have a pass over this? Thanks.

….hpp

Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
Copy link
Member

@zoq zoq left a 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.

HISTORY.md Show resolved Hide resolved
Copy link
Contributor

@coatless coatless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See notes.

Comment on lines +83 to +100
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);
Copy link
Contributor

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?

Copy link

@mlpack-bot mlpack-bot bot left a 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. 👍

@jonpsy
Copy link
Member Author

jonpsy commented Jun 23, 2021

Great, now I have to wait another 2 days.

@coatless
Copy link
Contributor

@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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants