Skip to content

Implementation of the elitism feature #74

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

Open
eoantunes opened this issue Oct 25, 2021 · 2 comments
Open

Implementation of the elitism feature #74

eoantunes opened this issue Oct 25, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@eoantunes
Copy link

eoantunes commented Oct 25, 2021

Initially I would like to thank you for the excellent work.

Moving on to the question at hand, I've identified that there is no version of PyGAD that has already delivered elitism functionality.
Currently a similar effect can be achieved with just a few parent selection methods by making use of the variable keep_parents = -1(default) or >0.

As noted in the code comment itself:
"For some parent selection operators like rank selection, the parents are of high quality and it is beneficial to keep them in the next generation. In some other parent selection operators like roulette wheel selection (RWS), it is not guranteed that the parents will be of high quality and thus keeping the parents might degarde the quality of the population."
This functionality is interesting and important, so its implementation is my suggestion to make this work even better!
The expected behavior would be elitsm = 0(default) or >0, if >0 a specific number of best solutions or individuals from the current population would be kept in the next generation population.

This is my suggestion, thanks again!

@christian-oleary
Copy link

From looking at the code, it seems that keep_parents performs elitism using steady state selection regardless of what selection operator you pass as an argument. How would 'elitism=2' differ from 'keep_parents=2'? Would elitism replace keep_parents?

@ahmedfgad ahmedfgad added the enhancement New feature or request label Aug 2, 2022
@ahmedfgad
Copy link
Owner

@eoantunes @christian-oleary
Thanks you and apologize for following up that late!

The keep_parents parameter does not support elitism selection because it only keeps the parents. Sometimes the parents are not the best solutions.

This will be supported in a future release!

ahmedfgad added a commit that referenced this issue Sep 9, 2022
1. Raise an exception if the sum of fitness values is zero while either roulette wheel or stochastic universal parent selection is used. #129
2. Initialize the value of the `run_completed` property to `False`. #122
3. The values of these properties are no longer reset with each call to the `run()` method `self.best_solutions, self.best_solutions_fitness, self.solutions, self.solutions_fitness`: #123. Now, the user can have the flexibility of calling the `run()` method more than once while extending the data collected after each generation. Another advantage happens when the instance is loaded and the `run()` method is called, as the old fitness value are shown on the graph alongside with the new fitness values. Read more in this section: [Continue without Loosing Progress](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#continue-without-loosing-progress)
4. Thanks [Prof. Fernando Jiménez Barrionuevo](http://webs.um.es/fernan) (Dept. of Information and Communications Engineering, University of Murcia, Murcia, Spain) for editing this [comment](https://github.com./ahmedfgad/GeneticAlgorithmPython/blob/5315bbec02777df96ce1ec665c94dece81c440f4/pygad.py#L73) in the code. 5315bbe
5. A bug fixed when `crossover_type=None`.
6. Support of elitism selection through a new parameter named `keep_elitism`. It defaults to 1 which means for each generation keep only the best solution in the next generation. If assigned 0, then it has no effect. Read more in this section: [Elitism Selection](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#elitism-selection). #74
7. A new instance attribute named `last_generation_elitism` added to hold the elitism in the last generation.
8. A new parameter called `random_seed` added to accept a seed for the random function generators. Credit to this issue #70 and [Prof. Fernando Jiménez Barrionuevo](http://webs.um.es/fernan). Read more in this section: [Random Seed](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#random-seed).
9. Editing the `pygad.TorchGA` module to make sure the tensor data is moved from GPU to CPU. Thanks to Rasmus Johansson for opening this pull request: ahmedfgad/TorchGA#2
ahmedfgad added a commit that referenced this issue Sep 9, 2022
1. Raise an exception if the sum of fitness values is zero while either roulette wheel or stochastic universal parent selection is used. #129
2. Initialize the value of the `run_completed` property to `False`. #122
3. The values of these properties are no longer reset with each call to the `run()` method `self.best_solutions, self.best_solutions_fitness, self.solutions, self.solutions_fitness`: #123. Now, the user can have the flexibility of calling the `run()` method more than once while extending the data collected after each generation. Another advantage happens when the instance is loaded and the `run()` method is called, as the old fitness value are shown on the graph alongside with the new fitness values. Read more in this section: [Continue without Loosing Progress](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#continue-without-loosing-progress)
4. Thanks [Prof. Fernando Jiménez Barrionuevo](http://webs.um.es/fernan) (Dept. of Information and Communications Engineering, University of Murcia, Murcia, Spain) for editing this [comment](https://github.com./ahmedfgad/GeneticAlgorithmPython/blob/5315bbec02777df96ce1ec665c94dece81c440f4/pygad.py#L73) in the code. 5315bbe
5. A bug fixed when `crossover_type=None`.
6. Support of elitism selection through a new parameter named `keep_elitism`. It defaults to 1 which means for each generation keep only the best solution in the next generation. If assigned 0, then it has no effect. Read more in this section: [Elitism Selection](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#elitism-selection). #74
7. A new instance attribute named `last_generation_elitism` added to hold the elitism in the last generation.
8. A new parameter called `random_seed` added to accept a seed for the random function generators. Credit to this issue #70 and [Prof. Fernando Jiménez Barrionuevo](http://webs.um.es/fernan). Read more in this section: [Random Seed](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#random-seed).
9. Editing the `pygad.TorchGA` module to make sure the tensor data is moved from GPU to CPU. Thanks to Rasmus Johansson for opening this pull request: ahmedfgad/TorchGA#2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants