Training Methods Intermediate

Genetic Algorithm

Mixing and nudging a batch of candidates to pick the best

Key points
  • A genetic algorithm makes a whole batch of candidates at once, then repeats picking the good ones, mixing them, and nudging them slightly.
  • One candidate is a list of setting values. That list gets ranked by score, and only the top of the ranking moves on to the next round.
  • Mixing means building a new candidate by splitting two good candidates' entries between them, and it's always paired with deliberately throwing one entry off.
  • It earns its keep when there's no way to compute a gradient, or when settings are made of choppy, discrete values. In exchange, it's slow, because every candidate has to be tested.
  • Lose diversity, and it stalls right where it is. That's why some lagging candidates get kept around on purpose, and how much gets nudged each round is tuned carefully.
Contents

1The analogy

Pitching a sunshade at a campsite has no single right answer. How high to set the pole, what angle to spread the guy lines at, how many stakes to drive in, which side to face into the wind — the combinations run into the dozens. Instead of testing one setup at a time, try six spots with six different setups all at once, and a single evening's wind hands you six answers. Pick the two that held up best, take the pole height from one and the line angle from the other, and pitch a new one combining them. Throw in one deliberate change too — just the stake count, done differently this time. By the next evening, you're left with a setup noticeably sturdier than where you started. A genetic algorithm carries this exact approach over.

2In detail

It handles a whole batch, not just one

Ordinary training holds onto a single answer and corrects it bit by bit. A genetic algorithm starts by generating dozens to hundreds of candidates all at once and runs them together. This batch is called the population.

One candidate is a list of setting values laid out in a row. For the sunshade, that's an ordered line of entries like pole height, line angle, and stake count. How you define those entries is half the battle of solving the problem. Slice them too finely and the combinations explode beyond what's manageable; lump them too coarsely and a good answer might not even exist inside the list.

Ranking by score, keeping only the top

Every candidate gets actually tested and scored. That score is called fitness. For the sunshade, it might be how long it held up against the wind; for a parking problem, how close it landed to the target spot. What matters here is that all you need is a rule for scoring — you don't need to know how to fix a candidate to make it better.

The candidates get ranked by score, and the top few become parents for the next round. It's not always strictly the very best one, either — picking a small sample and choosing the better one from within it keeps things a bit looser, so an early candidate that happened to do well by chance doesn't take over the whole population. The single best candidate or two sometimes get carried over untouched into the next round as well.

Mixing, and nudging one spot

A new candidate gets built by splitting two parents' lists between them — the front half from one, the back half from the other, say. Sometimes a coin flip decides, entry by entry, which parent to pull from. The idea is to combine two candidates with different strengths and land on something better than either.

On top of that, one more thing gets added: picking a single entry in the newly built list and nudging its value slightly off. Without this, any value that was never present in the starting candidates can never appear at all. Nudge too little and things circle in place; nudge too much and a hard-won good combination gets scrambled every round. Mixing recombines what already exists; nudging brings in what never existed before.

As generations stack up

One round is called a generation. As generations pass, the average score rises, and the candidates in the population start resembling each other more. At some point, the score stops rising no matter how many more rounds run, and that's where it stops.

The trouble is settling into that resemblance too early. If one candidate does noticeably well early on, its descendants can flood the population, and a better answer sitting elsewhere never gets a candidate left to reach it. That's why selection gets loosened, the nudge rate gets bumped up a bit, or the population gets split into separate groups that run apart and mix only occasionally.

Where it fits

For problems where a gradient can actually be computed, gradient-descent-style methods are usually much faster. A genetic algorithm's territory sits on the other side of that line — problems where you can score a candidate but have no idea which direction would improve it, where the settings are choppy, discrete values like counts or orderings, and where good answers might be scattered in several different spots.

The cost is the number of tests. Every candidate in every generation has to be tested, so it gets unwieldy fast if a single test takes a long time. That's why it tends to be used on problems where testing is quick or many candidates can run in parallel — picking settings for a neural network, or working out a physical shape, are common examples.

3More precisely

A genetic algorithm is a search method modeled on evolution's selection, crossover, and mutation. One candidate is called an individual, its list of settings a genome, the whole batch a population, and its score fitness. Tournament selection or rank-based selection are common ways to pick parents, and carrying the top candidates forward unchanged is called elitism. Since it never uses a gradient of the objective function, it can be applied even to problems that can't be differentiated at all — though it carries no guarantee of finding the true optimum.

The analogy breaks down in places. A person watching the sunshade can guess, just by looking, why one setup held up and another didn't, but a genetic algorithm never asks why — it only looks at the score, with no notion of cause built in anywhere. That's why combinations that look strange or even wrong to a person can still survive, simply because they happened to score well. There's another gap: camping wraps up after testing six setups in one evening, but in real problems, the same candidate's score can shift with conditions from one test to the next, so it often has to be tested several times and averaged before the ranking can be trusted.

4Try it yourself

5Common misconceptions

  • It's easy to think a genetic algorithm is a kind of learning, but actually it isn't learning a rule from data — it's a search method for finding good settings.

  • It's easy to think running more generations always reaches the best answer, but actually if the population resembles itself too early, it stalls right there.

  • It's easy to think a higher nudge rate is always better, but actually set it too high and a hard-won good combination gets scrambled every round, and the score stops climbing.

7One-line summary

In shortA genetic algorithm builds a batch of candidates, ranks them by score, and refines the answer by mixing the good ones together and nudging one spot at a time.

Spotted an error or have a better analogy? Suggest an edit · Last updated2026-09-02