Mutation
- What happens with a GA is the best members of the population
are used to make the next generation.
- We'll talk about "sexual" reproduction
shortly, but both "sexual" and "asexual" reproduction have mutations.
- (I put sexual and asexual in scare quotes because the GA mechanism
is just an approximation of these things in real biology.)
- If you want to mutate a member, you can pick a few genes to change
or pick each with a low probality.
- It turns out if you pick each with a low probability, you can get
to the best solution in one step (though it's really unlikely).
- This has some nice ramifications for search space exploration.
- So, that's what we do in the code.
- In the getNextGeneration function, the mutate function is called.
- It works on the already new next generation. (If you comment out
that bit, you get asexual reproduction but there's no competition.)
- Asexual reproduction just splits the existing member into two, and
the genes one or either of them can be mutated.
- Here we mutate all the children of the last generation.
- If you got the code and change MUTATION_RATE from 0.05 to 0.01 you'll
find that fewer things mutate each generation.
- So, it takes longer to get to the best solution.
- However, once you get to the best solution, members move away from it
(mutate) less often.
- Look at particular digits and you might want to change the
GENERATIONS_TO_RUN.