DEV Community

Paul Crinigan
Paul Crinigan

Posted on

What Genetic Algorithms Borrow From Evolution, and What They Leave Out

Genetic algorithms are one of the few places where a biology metaphor made it all the way into production code. Population, fitness, crossover, mutation, selection. The vocabulary came over intact, which is exactly why it is easy to assume the model came over intact too.

It did not. Evolutionary biology runs on four mechanisms, and most GA implementations only implement one and a half of them. The gap is worth knowing about, because the mechanisms that got left behind are the ones that explain the failure modes people hit.

Selection Is Only One Of Four Mechanisms

Natural selection is the mechanism everyone ports over, and it is the only one that reliably produces adaptation. It needs three things at once: variation in a trait, heritability of that trait, and differential reproductive success based on it. Take away any one of the three and it stops working.

That maps cleanly onto a GA. Variation is your initial population plus mutation, heritability is crossover, differential success is your fitness function. When a GA is not converging on anything useful, one of those three has usually gone missing. A fitness function that returns nearly the same score for everything has removed the third condition, and you are left running a very slow random walk.

Drift Is The Bug You Ship Without Noticing

Genetic drift is change in allele frequency by pure chance, with no selective advantage involved. In biology its effects scale inversely with population size. In a small population it can fix a neutral or even mildly harmful allele in a handful of generations, and it can overpower selection entirely.

This is the one that bites GA implementations, and it usually shows up as premature convergence. Run a population of 30 for a few hundred generations and a chunk of your diversity disappears for reasons that have nothing to do with fitness. You end up in a local optimum that no single mutation can escape, and it looks like the search space was hard when really the sampling was too small. Biology calls the extreme version of this the founder effect, where a small group colonizes a new habitat carrying only a slice of the original diversity.

The practical read: population size is not a performance knob you tune down for speed. It is the parameter that decides how much of your result is selection and how much is noise.

Mutation Rate Is A Tuning Knob, Not A Detail

Mutation supplies all new variation. Crossover only recombines what the population already carries, so once diversity collapses, crossover has nothing left to work with and mutation is the only source of anything new.

Biology runs this at a very low rate, roughly one to two new mutations per 100 million base pairs per generation in humans, and most are neutral. That low rate works because the population sizes are enormous and the timescales are long. A GA has neither, which is why GA mutation rates sit orders of magnitude higher. Set it too low and drift eats your diversity. Set it too high and heritability breaks down, because offspring stop resembling the parents that earned their fitness score, and you have quietly deleted the second condition selection requires.

Gene Flow And Why Island Models Work

The fourth mechanism is gene flow, alleles moving between populations. It homogenizes: high gene flow keeps populations similar, restricted gene flow lets them diverge independently, which is why geographic isolation is the usual first step toward a new species.

Island model GAs are gene flow implemented on purpose. Run several subpopulations mostly separately, let each one drift and adapt on its own, and migrate a few individuals between them occasionally. You get the diversity benefits of isolation and the recombination benefits of mixing, and the migration rate is the dial between them. Most people arrive at this pattern empirically after fighting premature convergence. It is easier to reason about when you recognize it as the mechanism biology already uses.

The Takeaway

The useful version of the metaphor is not "evolution optimizes." Evolution has no goal, no direction, and no notion of a global optimum. It responds to present conditions, and a trait that helps in a cold climate becomes a liability when the climate warms.

What it does give you is a well studied model of how variation, retention and chance interact over many generations. If your GA is converging too early, that is drift and population size. If it is wandering, that is mutation rate versus heritability. If it is stuck, that is a fitness landscape problem, not a code problem. The full breakdown of all four mechanisms, plus the evidence lines behind them, is here: How Evolution Works.

Top comments (0)