Skip to content

Return value of pygad.GA.tournament_selection misleading #89

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
ahernandez105 opened this issue Feb 25, 2022 · 1 comment
Open

Return value of pygad.GA.tournament_selection misleading #89

ahernandez105 opened this issue Feb 25, 2022 · 1 comment
Assignees
Labels
invalid This doesn't seem right

Comments

@ahernandez105
Copy link

The parent_indices returned by pygad.GA.tournament_selection are actually the best indices selected from the K rand_indices. Within this method parents_indices are updated as followed:
parents_indices.append(selected_parent_idx)

where I believe it should be changed to:
parents_indices.append(rand_indices[selected_parent_idx])

ahmedfgad added a commit that referenced this issue Feb 27, 2022
Fixes this issue: #89
In the tournament_selection() method, this line:
parents_indices.append(selected_parent_idx)

is replaced by this line:
parents_indices.append(rand_indices[selected_parent_idx])
@ahmedfgad ahmedfgad self-assigned this Feb 28, 2022
@ahmedfgad ahmedfgad added bug Something isn't working invalid This doesn't seem right and removed bug Something isn't working labels Feb 28, 2022
@ahmedfgad
Copy link
Owner

Yes, you are right. There was an issue returning the indices of the selected parents. But still the correct parents are returned because rand_indices[selected_parent_idx] is correctly used to return the selected parents in the last line of the for loop.

ahmedfgad added a commit that referenced this issue Jul 8, 2022
## PyGAD 2.17.0

Release Date: 8 July 2022

1. An issue is solved when the `gene_space` parameter is given a fixed value. e.g. gene_space=[range(5), 4]. The second gene's value is static (4) which causes an exception.
2. Fixed the issue where the `allow_duplicate_genes` parameter did not work when mutation is disabled (i.e. `mutation_type=None`). This is by checking for duplicates after crossover directly. #39
3. Solve an issue in the `tournament_selection()` method as the indices of the selected parents were incorrect. #89
4. Reuse the fitness values of the previously explored solutions rather than recalculating them. This feature only works if `save_solutions=True`.
5. Parallel processing is supported. This is by the introduction of a new parameter named `parallel_processing` in the constructor of the `pygad.GA` class. Thanks to [@windowshopr](https://github.com/windowshopr) for opening the issue [#78](#78) at GitHub. Check the [Parallel Processing in PyGAD](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#parallel-processing-in-pygad) section for more information and examples.
ahmedfgad added a commit that referenced this issue Jul 8, 2022
PyGAD 2.17.0
Release Date: 8 July 2022

1. An issue is solved when the `gene_space` parameter is given a fixed value. e.g. gene_space=[range(5), 4]. The second gene's value is static (4) which causes an exception.
2. Fixed the issue where the `allow_duplicate_genes` parameter did not work when mutation is disabled (i.e. `mutation_type=None`). This is by checking for duplicates after crossover directly. #39
3. Solve an issue in the `tournament_selection()` method as the indices of the selected parents were incorrect. #89
4. Reuse the fitness values of the previously explored solutions rather than recalculating them. This feature only works if `save_solutions=True`.
5. Parallel processing is supported. This is by the introduction of a new parameter named `parallel_processing` in the constructor of the `pygad.GA` class. Thanks to [@windowshopr](https://github.com/windowshopr) for opening the issue [#78](#78) at GitHub. Check the [Parallel Processing in PyGAD](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#parallel-processing-in-pygad) section for more information and examples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants