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 did not use mutation, pygad print the following warning:
If you do not want to mutate any gene, please set mutation_type=None.
But when I set mutation_type=None, or mutation_type="None", then pygad crashed:
File "C:\My\MyPythonProject\GeneticAlgo\venv\lib\site-packages\pygad\pygad.py", line 282, in __init__
raise TypeError("The expected type of the 'mutation_type' parameter is str but ({mutation_type}) found.".format(mutation_type=type(mutation_type)))
TypeError: The expected type of the 'mutation_type' parameter is str but (<class 'NoneType'>) found.
I looked at the source code, it seems that line 280 does not allow the possibility of mutation_type being None. Yet line 295 does allow such possibility.
Thank you. The issue with assigning None values for crossover_type and mutation_type is solved. The updated pygad.py module is available at GitHub and a new release will be published to PyPI later. Please try the updated module if there a chance.
Hi @ahmedfgad thanks a lot for this wonderful tool. I tried to run the example code from
/home/sikari/Desktop/temp_proj_pygad/PYGAD/pygad.py:374: UserWarning: The percentage of genes to mutate (mutation_percent_genes=10) resutled in selecting (0) genes. The number of genes to mutate is set to 1 (mutation_num_genes=1).
If you do not want to mutate any gene, please set mutation_type=None.
if not self.suppress_warnings: warnings.warn("The percentage of genes to mutate (mutation_percent_genes={mutation_percent}) resutled in selecting ({mutation_num}) genes. The number of genes to mutate is set to 1 (mutation_num_genes=1).\nIf you do not want to mutate any gene, please set mutation_type=None.".format(mutation_percent=mutation_percent_genes, mutation_num=mutation_num_genes))
solution, solution_fitness, solution_idx = ga_instance.best_solution()
print("Parameters of the best solution : {solution}".format(solution=solution))
Parameters of the best solution : [ 4.46054413 -0.56253708 -0.58246418 1.96274254 -2.26517722 1.62457641]
print("Fitness value of the best solution = {solution_fitness}".format(solution_fitness=solution_fitness))
Fitness value of the best solution = 42.05377974846767
This is a normal warning and you can supress all warnings by setting suppress_warnings=True.
The warning is returned because you use the default of mutating 10% of the genes (mutation_percent_genes=10). When you have few genes like only 2, then 10% means 0.2 genes which is rounded to 0. This means you are mutating 0 genes. With that situation, the number of genes is raised to 1 automatically.
This warning tells you that if you intentionally want to mutate no genes, then it is better to set mutation_type=None. Otherwise, there will be 1 gene mutated.
Activity
None values for crossover_type and mutation_type
ahmedfgad commentedon May 2, 2021
Thank you. The issue with assigning None values for
crossover_typeandmutation_typeis solved. The updatedpygad.pymodule is available at GitHub and a new release will be published to PyPI later. Please try the updated module if there a chance.mathlusiverse commentedon May 2, 2021
Thanks, @ahmedfgad for the quick response! Please keep up the good work.
I will test it after you make it available on your web page.
ahmedfgad commentedon May 3, 2021
Thank you.
ahmedfgad commentedon May 3, 2021
Hi @asishadhikari ,
This is a normal warning and you can supress all warnings by setting
suppress_warnings=True.The warning is returned because you use the default of mutating 10% of the genes (
mutation_percent_genes=10). When you have few genes like only 2, then 10% means 0.2 genes which is rounded to 0. This means you are mutating 0 genes. With that situation, the number of genes is raised to 1 automatically.This warning tells you that if you intentionally want to mutate no genes, then it is better to set
mutation_type=None. Otherwise, there will be 1 gene mutated.Please let me know if I should clarify something.
PyGAD 2.14.0 Released
PyGAD 2.14.0 Documentation
ahmedfgad commentedon May 19, 2021
This issue is solved in the new release of PyGAD 2.14.0.
Thank you.