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

feat: 💥 Add _pseudo_ genetic search #777

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Anselmoo
Copy link
Contributor

@Anselmoo Anselmoo commented Dec 5, 2022

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

codecov-commenter commented Dec 5, 2022

Codecov Report

Patch coverage: 100.00% and project coverage change: +4.45 🎉

Comparison is base (61a1796) 95.41% compared to head (be86e9b) 99.86%.

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     
Impacted Files Coverage Δ
keras_tuner/__init__.py 100.00% <100.00%> (ø)
keras_tuner/tuners/__init__.py 100.00% <100.00%> (ø)
keras_tuner/tuners/genetic.py 100.00% <100.00%> (ø)
keras_tuner/errors.py 100.00% <0.00%> (ø)
keras_tuner/protos/service_pb2_grpc.py
keras_tuner/protos/service_pb2.py
keras_tuner/api_export.py
keras_tuner/protos/__init__.py
keras_tuner/protos/keras_tuner_pb2_grpc.py
keras_tuner/protos/keras_tuner_pb2.py
... and 20 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

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

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

@Anselmoo
Copy link
Contributor Author

Anselmoo commented Dec 5, 2022

@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
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
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
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?

Copy link
Collaborator

@haifeng-jin haifeng-jin left a comment

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.

keras_tuner/tuners/genetic.py Outdated Show resolved Hide resolved
keras_tuner/tuners/genetic.py Outdated Show resolved Hide resolved
keras_tuner/tuners/genetic.py Outdated Show resolved Hide resolved
keras_tuner/tuners/genetic.py Outdated Show resolved Hide resolved
keras_tuner/tuners/genetic.py Outdated Show resolved Hide resolved
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
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
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?

keras_tuner/tuners/genetic.py Outdated Show resolved Hide resolved
keras_tuner/tuners/genetic.py Outdated Show resolved Hide resolved
Comment on lines +263 to +264
self.population = {"hyperparameters": [], "scores": []}
self.new_population = {"hyperparameters": [], "scores": []}
Copy link
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
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?

Copy link
Contributor Author

@Anselmoo Anselmoo Mar 21, 2023

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.

keras_tuner/tuners/genetic.py Show resolved Hide resolved
@Anselmoo Anselmoo requested a review from haifeng-jin March 26, 2023 13:00
@Anselmoo
Copy link
Contributor Author

Anselmoo commented Apr 5, 2023

@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