Skip to content

feat: 💥 Add _pseudo_ genetic search#777

Open
Anselmoo wants to merge 5 commits into
keras-team:masterfrom
Anselmoo:genetic_optimizer
Open

feat: 💥 Add _pseudo_ genetic search#777
Anselmoo wants to merge 5 commits into
keras-team:masterfrom
Anselmoo:genetic_optimizer

Conversation

@Anselmoo

@Anselmoo Anselmoo commented Dec 5, 2022

Copy link
Copy Markdown
Contributor

The proposed implementation of a genetic algorithm for hyper optimization as discussed in #47

Even if genetic optimization might be costly for CNN, the applications in numeric analysis or Design of Experiment (DoE) make it still interesting.

Fixes: #47

Further Reading:

  1. Vishwakarma G, et al Towards Autonomous Machine Learning in Chemistry via Evolutionary Algorithms. ChemRxiv.
  2. Rosanna Nichols et al 2019 Quantum Sci. Technol. 4 045012

The proposed implementation of a genetic algorithm for hyper optimization.

Even if genetic optimization might be costly for CNN, the applications in numeric analysis or Design of Experiment (DoE) make it still interesting.

Fixes: keras-team#47


Further Reading:

1. [Vishwakarma G, et al Towards Autonomous Machine Learning in Chemistry via Evolutionary Algorithms. **ChemRxiv.**](https://chemrxiv.org/engage/api-gateway/chemrxiv/assets/orp/resource/item/60c7445a337d6c2849e26d98/original/towards-autonomous-machine-learning-in-chemistry-via-evolutionary-algorithms.pdf)
2. [Rosanna Nichols et al 2019 _Quantum Sci. Technol._ **4** 045012](https://iopscience.iop.org/article/10.1088/2058-9565/ab4d89/meta?casa_token=db7uZRqRMEAAAAAA:fRO9qB25dAkeoskS6MMyzpZw2jSiMkpsN4zA_k6lheWUXaSUU8fPS-JPMoNFcIl9tka4OPCG5AtDtiM)
@codecov-commenter

codecov-commenter commented Dec 5, 2022

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.86%. Comparing base (61a1796) to head (be86e9b).
⚠️ Report is 97 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #777      +/-   ##
==========================================
+ Coverage   95.41%   99.86%   +4.45%     
==========================================
  Files          50       45       -5     
  Lines        3247     3028     -219     
==========================================
- Hits         3098     3024      -74     
+ Misses        149        4     -145     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Anselmoo
Anselmoo marked this pull request as ready for review December 5, 2022 10:02
@haifeng-jin

Copy link
Copy Markdown
Collaborator

@Anselmoo Thanks for the contribution! We will need to have an internal review. I will get back to you afterwards.

@Anselmoo

Anselmoo commented Dec 5, 2022

Copy link
Copy Markdown
Contributor Author

@Anselmoo Thanks for the contribution! We will need to have an internal review. I will get back to you afterwards.

@haifeng-jin thx for the quick response and to the team.

I know introducing a new algorithm is not straightforward, so see what's next 😊
Best

@haifeng-jin haifeng-jin self-assigned this Dec 5, 2022
@haifeng-jin

Copy link
Copy Markdown
Collaborator

@Anselmoo
My first concern is which evolutionary algorithm is the best to use.
Another concern is that I do not have the bandwidth to revise and maintain it for the performance and correctness in different settings, like in parallel tuning.

However, this would serve as a great example of implementing custom algorithms for KerasTuner in the KerasTuner guides on keras.io. https://keras.io/guides/keras_tuner/
It is wanted for a long time.

Would you like to contribute it there?
If so, I can guide you through the process. A few more modifications to the code are needed.

@haifeng-jin

Copy link
Copy Markdown
Collaborator

@Anselmoo I should have closed the issue in the first place as we are very conservative on accepting new algorithms.
Sorry about that.

Please mention me in the thread before making any big contributions to ensure the PR can be accepted in the future.
Thank you!

@Anselmoo

Copy link
Copy Markdown
Contributor Author

@Anselmoo My first concern is which evolutionary algorithm is the best to use. Another concern is that I do not have the bandwidth to revise and maintain it for the performance and correctness in different settings, like in parallel tuning.

However, this would serve as a great example of implementing custom algorithms for KerasTuner in the KerasTuner guides on keras.io. https://keras.io/guides/keras_tuner/ It is wanted for a long time.

Would you like to contribute it there? If so, I can guide you through the process. A few more modifications to the code are needed.

This sound promising, let's do it. How, does this match with your @haifeng-jin latest comment?

@haifeng-jin haifeng-jin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR! I have left some comments. You can either change it here in the PR. Or create a new PR in https://github.com/keras-team/keras-io, where the final contribution would be. You need to create a new file here: https://github.com/keras-team/keras-io/tree/master/guides/keras_tuner. Please use the other files in the directory as examples.

Comment thread keras_tuner/tuners/genetic.py Outdated
Comment thread keras_tuner/tuners/genetic.py Outdated
Comment thread keras_tuner/tuners/genetic.py Outdated
Comment thread keras_tuner/tuners/genetic.py Outdated
Comment thread keras_tuner/tuners/genetic.py Outdated
self.ranges = self._make_ranges
self.population = {"hyperparameters": [], "scores": []}
self.new_population = {"hyperparameters": [], "scores": []}
self.values = {hp.name: hp.default for hp in self.get_space().space}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We don't need this. It can be a local variable in self.populate_space() and an argument in self._check_score(..., values).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The problem is if you define in self.populate_space(), it actually starts to re-initialize the hp.default again and again for every trial. In general, this implementation is kind of nested because I was focusing on using the oracle trial_id for making use of the parallelisation so far.

Make it sense a little?

Comment thread keras_tuner/tuners/genetic.py Outdated
Comment thread keras_tuner/tuners/genetic.py Outdated
Comment on lines +263 to +264
self.population = {"hyperparameters": [], "scores": []}
self.new_population = {"hyperparameters": [], "scores": []}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These 2 should be lists of trial_ids.
The score information and hyperparameters information can be retrieved from self.trials[trial_id].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does this mean that self.trials[trial_id] should get a list of dict?

@Anselmoo Anselmoo Mar 21, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@haifeng-jin can you briefly explain to me, what a possible implementation should look like, please. Pseudo code is fine.

Comment thread keras_tuner/tuners/genetic.py
@Anselmoo
Anselmoo requested a review from haifeng-jin March 26, 2023 13:00
@Anselmoo

Anselmoo commented Apr 5, 2023

Copy link
Copy Markdown
Contributor Author

@haifeng-jin can you take a brief look, please? With regards to https://keras.io/guides/keras_tuner/ it is more like a tutorial on how to build your individual solver solution?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pseudo genetic search

4 participants