I did the same in Javascript a while ago with a genetic algorithm.
http://www.puremango.co.uk/2010/12/genetic-algorithm-for-hel... (HN discussion:
http://news.ycombinator.com/item?id=2002673)
Again just evolving a string not a full program.
Mine hit the target significantly faster than OPs (around 70 generations rather than between 2 and 4 thousand).
I'm trying to work out where he went wrong.
First of all his 'mutate' function in the second example is actually performing both mutation and crossover.
As far as the mutation goes it looks fine; almost identical to the way I mutate genes. I think the problem lies in the way he's doing his crossover (breeding), just trying to work it out.
He's using one-point crossover, same as me.
The selection method is a kind of hybrid elite method where fitter members are more likely to be selected than unfit members, which is reasonable.
It might just be that his crossover and mutation probability is 100% and his population is only 20. But if you plug those figures into the interactive demo on my post (http://www.puremango.co.uk/genetic-hello-world.html) then it gets as far as "Hbumr Xqnkd" by the 70th generation. Still looks like it's evolving faster than his code. Must be the way he's selecting parents...
Again just evolving a string not a full program.
Mine hit the target significantly faster than OPs (around 70 generations rather than between 2 and 4 thousand).
I'm trying to work out where he went wrong.
First of all his 'mutate' function in the second example is actually performing both mutation and crossover.
As far as the mutation goes it looks fine; almost identical to the way I mutate genes. I think the problem lies in the way he's doing his crossover (breeding), just trying to work it out.
He's using one-point crossover, same as me.
The selection method is a kind of hybrid elite method where fitter members are more likely to be selected than unfit members, which is reasonable.
It might just be that his crossover and mutation probability is 100% and his population is only 20. But if you plug those figures into the interactive demo on my post (http://www.puremango.co.uk/genetic-hello-world.html) then it gets as far as "Hbumr Xqnkd" by the 70th generation. Still looks like it's evolving faster than his code. Must be the way he's selecting parents...