Part V · Chapter 12

Evolution as an Algorithm

Copy, vary, select, repeat. The recipe from Chapter 1 does not care whether it runs on DNA, on antibodies or on numbers in a computer. Engineers now use it on purpose. Watching it run in a machine shows both how powerful it is and the one thing a computer version always adds that nature never has: a goal.

Look back at what every simulation in this book needed. Something that makes copies of itself. Copies that are slightly imperfect. Surroundings that let some copies make more copies than others. Nothing in that list mentions cells, proteins or even life. The philosopher Daniel Dennett argued that natural selection is best seen as an algorithm: a mindless, step-by-step procedure that will produce its results in any medium where the three ingredients are present.

It already runs in more places than you might expect. When you fight an infection, the immune cells that make antibodies change their antibody genes at a high rate, and the cells whose antibodies grip the invader best are favoured: a small burst of variation and selection inside your own body, over days and weeks. Chemists now do the same in test tubes. Frances Arnold shared the 2018 Nobel Prize in Chemistry for "directed evolution": making many slightly different versions of an enzyme, keeping the ones that work best at a job, and repeating.

Evolution in a computer

In the 1960s and 1970s the computer scientist John Holland developed genetic algorithms: programs that keep a population of candidate solutions, score each one, let the better ones "breed" by mixing their settings, add random changes, and repeat. Engineers have used such methods to design things that are hard to reason about directly; NASA engineers, for example, used an evolutionary algorithm to design a small, oddly bent radio antenna for a spacecraft mission in the mid-2000s.

Here is a genetic algorithm you can watch. Each rocket's "genome" is a list of 110 thrust directions, one for each moment of its flight. The first generation's lists are random, so the rockets wobble aimlessly. Each generation, rockets that end up closer to the target are more likely to be picked as parents; crashing into the barrier or the walls is heavily penalised. Children mix two parents' lists and get a few random changes.

Interactive 12.1Evolving Rockets
Watch a few generations, then drag (or use the buttons to move) the target or the barrier
 
target (part of the environment) barrier, crashes this generation's flights last generation's best path; best distance
Usually within a few dozen generations the population's flight plans come to curve around the barrier and reach the target, though some runs stay stuck behind it for a long time: a local peak. Set mutation to 0 and press Reset: mixing alone soon runs out of new options and progress usually stalls. Push it to a few percent and good flight plans keep getting scrambled, so more rockets crash. Now move the target mid-run (drag it, or press Move the target). The population has to re-adapt from whatever it has, just as a real population does when its world changes. (The physics is a toy. This program also keeps one unchanged copy of the best rocket each generation, a common engineering trick that has no exact counterpart in nature.)
The difference that matters

A genetic algorithm has a fitness function chosen by a person: "get close to this target". That is a goal, written down in advance. Nature has nothing like it. In living populations, "fitness" is not a score anyone set in advance. It is a variant's expected reproductive success, which comes from how its traits interact with the conditions it actually meets: the climate, predators, rivals and mates. Nobody chose which traits should win, and the conditions keep changing, partly because other species are evolving too. The rockets share evolution's machinery, not its lack of a goal. The same caveat applied to the target-phrase demo in Chapter 7.

Hikers and herds

Most of modern machine learning trains models by a different method: gradient descent. Picture a single blindfolded hiker on a landscape of hills. At each step the hiker feels which way the ground slopes underfoot and takes a small step uphill (or downhill, if the goal is to minimise an error). It is efficient, but it only ever knows the ground at one spot, so it climbs whichever hill it happens to start on.

An evolving population is more like a herd spread over the hills. It never measures slopes at all; it only compares the heights where its members stand, and the next generation is drawn from those standing higher, with random scatter. A herd can spill over a low ridge onto a taller hill that the lone hiker would never find. But it can get stuck too, and it wastes effort on members standing in poor spots. Let them race.

Interactive 12.2Hiker Versus Herd
Press New start a few times; try New landscape and different mutation sizes
 
fitness landscape (height) herd members the hiker
Both start at the same spot. The hiker stops at the top of the first hill it climbs. The herd keeps scattering, and members that land higher are favoured. In our own test runs on random landscapes like these, the hiker reached the tallest peak about 40% of the time; the herd did so about as often as the hiker with the smallest mutations, and more often as mutations grew, nearly always with the largest. Neither is guaranteed: a deep, wide valley can trap the herd as well, and with large mutations its members are spread so thin that few sit right on top.

Real machine learning mixes these ideas. Gradient methods need a smooth score whose slope can be calculated; evolutionary methods only need to compare scores, which makes them useful when the slope cannot be measured. Both are search procedures, and both need someone to say what counts as better. That is why the landscape picture from Chapter 8 turns up in so many fields.

Misconception spotter

You have now run evolution in a dozen forms. Time to test the instincts you have built. For each statement, decide whether it is true or false.

0 of 8 answered

Intuition check

A programmer writes a genetic algorithm to design a lightweight bridge. Which statement about it is accurate?

What you now see

This chapter, and the whole book, in a few lines:

  • The engine (Chapters 1–3): variation, inheritance and differential reproduction make populations change, with no goal and no foresight. Mutations are random with respect to need; selection is not random.
  • What counts (4–6): fitness means reproductive success in a particular environment, not strength. Breeders proved how far selection can go. Chance also moves gene frequencies, most strongly in small populations.
  • Climbing without a map (7–8): small steps add up over deep time into eyes and wings; populations climb fitness landscapes blindly and can get stuck on lesser peaks.
  • Life shaping life (9–10): when the environment includes other evolving species, races never end; helping evolves when it tends to aid copies of the helper's genes.
  • The tree and the algorithm (11–12): isolated populations diverge into new species, all life forms one branching tree, and the same loop now runs in our machines, where, unlike in nature, someone writes down the goal.