Playing with genetic algorithms in Python
joseprupi.github.io
joseprupi.github.io
One thing that might improve the algorithms in the linked write-up is not choosing the strict top results. Often, GAs perform better if you choose a random selection from the result set, then choose the top performer from that selection.
So, if your algorithm generates 100 results, pick 10 randomly, then use the top 2 from that selection to generate the next generation. This allows more exploration of the solution space and mitigates landing in local optima. Introducing the new parameters means more playing with the values, but it's been shown to work better, and makes sense in the context of biological evolution, as well.
Anyway - GAs are fun and I'd like to see them used more. Thanks for the article OP!
Throughout the generations you can adjust the parameters (selection pressure) from just a slight favoring of fitness to higher favoring fitness, making the GA have a large initial search space that gradually approaches an optima. If you are worried about the solution converging to soon, a high grade of mutation can also be used.
Is there a term for that approach?
[0] https://link.springer.com/chapter/10.1007/3-540-63173-9_61 but likely can be found online in other places
> python3 -m timeit 'import numpy as np; mutations=0.05; rows=10; columns=10; np.random.choice([0,1], p=[(1-mutations), mutations],size=(rows,columns))'
50000 loops, best of 5: 8.88 usec per loop`
> python3 -m timeit 'import numpy as np; mutations=0.05; rows=10; columns=10; np.random.rand(rows,columns) <= mutations'
200000 loops, best of 5: 1.06 usec per loop[0] An Introduction to Genetic Algorithms https://a.co/d/hKyQoqO