[HN Gopher] Playing with Genetic Algorithms in Python
___________________________________________________________________
Playing with Genetic Algorithms in Python
Author : melenaboija
Score : 41 points
Date : 2023-09-06 16:57 UTC (3 hours ago)
(HTM) web link (joseprupi.github.io)
(TXT) w3m dump (joseprupi.github.io)
| JoeDaDude wrote:
| I've been fascinated by GAs ever since Blondie24 [1] demonstrated
| it could be used to create strong board game players. Now that
| there exists the Distributed Evolutionary Algorithms (DEAP, [2])
| library for Python I am tempted to recreate Blondie24.
|
| [1]. https://en.wikipedia.org/wiki/Blondie24
|
| [2]. https://deap.readthedocs.io/en/master/
| bun_at_work wrote:
| GAs are super cool and I think underutilized in the NN era.
|
| 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!
| shepardrtc wrote:
| I agree. Personally I had success using randomness on an
| energy-based system. You start off with energy and compete to
| earn more. Once you hit 0 then you're out. Then you can
| generate new ones, with some being completely random, and then
| others being the combination of random choices from the Top N.
| Probably not the most theoretically-sound approach, but it
| worked well enough in the real world.
| pantsforbirds wrote:
| In my experience using tournament selection with a small
| elitism count works best. You keep the best `n` members of the
| population and for all other members you group them into random
| groups of size `m` and select the best value from that group.
| gjstein wrote:
| It seems like using np.random.choice is indeed a slow way to get
| a grid in which 5% of the values are 1. I would recommend using
| np.random.rand(size) >= mutations: > 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
___________________________________________________________________
(page generated 2023-09-06 20:01 UTC)