You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some comments on your code:
You set gene_space=a = np.arange(0,32,1) which is not valid. Where is the variable a? I wonder if that code is working.
The parameter sol_per_pop is missing. This one and the num_genes must exist as long as the initial_population parameter is not used.
I am using the latest version of PyGAD and I did not see any duplicates while allow_duplicate_genes=False. Note that I built a fitness function that returns random fitness values.
This is the code I tested where I find the difference between the following 2 sets:
The set of unique values in the solution.
The set of unique gene values (i.e. np.arange(0,32,1))
As long as you use 32 genes and the gene space has only 32 values, then it is expected that the difference between those 2 sets must be empty. This is what happens in my code. So, I think there is no issue with the allow_duplicate_genes parameter.
If my code does not reflect yours, please let me know.
Mutation is not enabled, but i guess there is something i'm missing... Should allow_duplicate_genes also block duplicates after the mating?
Thank
@KevinGalassi, allow_duplicate_genes works only after the mutation is applied. The reason is that even if there is a duplicate, then it can be solved using mutation because it can generate new values for a gene to solve the duplicate.
But for crossover, it only combines the genes from 2 solutions. Crossover is not meant to introduce new gene values by its own.
But I think it would be a good feature to support. A warning maybe used if mutation is disabled while allow_duplicate_genes=False.
My bad, when I looked at the wiki I haven't found this information explicitly declared. I avoided mutation because the possibility of multiple genes with the same value, but the same problem may arise with crossover too.
BTW I'm trying to solve a kind of 'Travelling Saleman Problem', guess I'll look online.
I might be doing something wrong but allow_duplicate_genes=False is not working for me, even the best solutions for the fitness function I am using have duplicate genes.
For my case I am trying a fitness function that takes around 20 min, but here with a dummy fitness function also returns solutions with duplicated genes as the ones to be printed at the end:
Initially I tried with adaptive mutation and thought that was the problem, then when mutation_type is left to defaults but the mutation_probability is set, there are duplicates. However, when mutation_probability is set to default, no duplicates are generated.
Then, I am not sure how to proceed since I am not sure mutation is happening at all when mutation_type and mutation_probability is set to default.
Activity
ahmedfgad commentedon Apr 12, 2021
Hi,
Thanks for using PyGAD!
I have some comments on your code:
You set
gene_space=a = np.arange(0,32,1)which is not valid. Where is the variablea? I wonder if that code is working.The parameter
sol_per_popis missing. This one and thenum_genesmust exist as long as theinitial_populationparameter is not used.I am using the latest version of PyGAD and I did not see any duplicates while
allow_duplicate_genes=False. Note that I built a fitness function that returns random fitness values.This is the code I tested where I find the difference between the following 2 sets:
np.arange(0,32,1))As long as you use 32 genes and the gene space has only 32 values, then it is expected that the difference between those 2 sets must be empty. This is what happens in my code. So, I think there is no issue with the
allow_duplicate_genesparameter.If my code does not reflect yours, please let me know.
JanKulbinski commentedon Apr 12, 2021
Yes, it is working. The cause was lack of a gene_space parameter . Thank you for the response and this amazing library
KevinGalassi commentedon Apr 8, 2022
And i getting solutions with duplicated genes like:
[10 3 14 4 17 10 5 0 7 6 11 8 15 16 13 1 14 4 2 9]]
Mutation is not enabled, but i guess there is something i'm missing... Should allow_duplicate_genes also block duplicates after the mating?
Thank
ahmedfgad commentedon Apr 8, 2022
@KevinGalassi,
allow_duplicate_genesworks only after the mutation is applied. The reason is that even if there is a duplicate, then it can be solved using mutation because it can generate new values for a gene to solve the duplicate.But for crossover, it only combines the genes from 2 solutions. Crossover is not meant to introduce new gene values by its own.
But I think it would be a good feature to support. A warning maybe used if mutation is disabled while
allow_duplicate_genes=False.KevinGalassi commentedon Apr 9, 2022
My bad, when I looked at the wiki I haven't found this information explicitly declared. I avoided mutation because the possibility of multiple genes with the same value, but the same problem may arise with crossover too.
BTW I'm trying to solve a kind of 'Travelling Saleman Problem', guess I'll look online.
Thanks
PyGAD 2.17.0 Documentation
PyGAD 2.17.0
gabrieldelpozo commentedon Oct 18, 2022
I might be doing something wrong but allow_duplicate_genes=False is not working for me, even the best solutions for the fitness function I am using have duplicate genes.
For my case I am trying a fitness function that takes around 20 min, but here with a dummy fitness function also returns solutions with duplicated genes as the ones to be printed at the end:
Initially I tried with adaptive mutation and thought that was the problem, then when mutation_type is left to defaults but the mutation_probability is set, there are duplicates. However, when mutation_probability is set to default, no duplicates are generated.
Then, I am not sure how to proceed since I am not sure mutation is happening at all when mutation_type and mutation_probability is set to default.
ahmedfgad commentedon Feb 22, 2023
@gabrieldelpozo,
A new release will be pushed soon with a fix to this issue. It happens as crossover creates duplicate genes that, for sometimes , are not solved.
PyGAD 2.19.0 Release