-
-
Notifications
You must be signed in to change notification settings - Fork 489
usage of new "save_solutions" option #57
-
Usage of new "save_solutions" option
I'm saving the solutions with save_solutions=True and adjusted the fitness-calculation so that only former unseen, thus new solutions will be executed ( ~ a second each). It is then possible to save much time..
My GA has 20 genes and I did run with stop_criteria='saturate_20'
Modus 1
mutation_percent_genes=20
random_mutation_max_val=5
- 42 generations
- 17200 total solutions (0.39s each)
- 8796 unique / executed solutions (0.77s each)
- 1.89hours, best fitness: 0.3305
- without save_solutions: >3.67hours, 1.95 times slower
Modus 2
mutation_percent_genes=50
random_mutation_max_val=10
- 71 generations
- 28800 total solutions (0.39s each)
- 14600 unique / executed solutions (0.77s each)
- 3.15hours, best fitness: 0.3150
- without save_solutions: >6.16hours, 1.97 times slower
Speed-Factor:
Since num_parents_mating=200 is half as high as sol_per_pop=400, I suppose that 50% of all 400 solutions per generation are known, thus not recalculated, which results in the doubled speed. Theoretically this increases further, if solutions from generations long ago are "seen" again.
Conclusion:
The saving-feature is available in PyGAD > 2.16.0 and it is great that there are plans of implementing a feature to neglect the redundant calculation of already calculated fitness results for known solutions. Each time the fitness calculation takes more time than just a few ms (in my example around a second), this approach obviously does make sense.
One can access the data via:
- ga_instance.solutions
- ga_instance.solutions_fitness
Beyond the saving of solutions + their fitness, the described functionality has been added independantly from PyGAD. But, as this example does show, it makes sense in certain use cases, to NOT recalculate the fitness for known solutions again and again.
Beta Was this translation helpful? Give feedback.