AppsGuidesAI DictionarySmall FixesOn RecordAboutFollow the lab

Genetic algorithm

Also called evolutionary algorithm

A genetic algorithm finds good solutions by copying evolution: it tries many guesses, keeps the best, mixes and tweaks them, and repeats.

The basicsTechnical

In plain words

Some problems have too many possible answers to check one by one: the best shape for an antenna, the best timetable for a school, the best route for a delivery van. A genetic algorithm doesn't search them all. It breeds answers instead.

It starts with a crowd of random guesses and gives each one a score for how well it works. The best ones survive and become parents. Their children are made by mixing parts of two parents, plus a small random change now and then. The new crowd is scored again, and the cycle repeats.

After many rounds, called generations, the scores climb and the crowd fills with strong answers. Nobody told the computer how to solve the problem; it only needed a way to tell a better answer from a worse one. It is one kind of algorithm inspired by nature, usually grouped under evolutionary computation.

Everyday example

Saving seeds from the best tomato plants

A farmer plants many tomato varieties. At harvest, she keeps seeds only from the plants that did best: sweetest fruit, fewest pests. Next year some plants cross-pollinate, mixing traits, and the odd one turns out different by chance. Season after season, her crop gets better without her ever designing a tomato. A genetic algorithm runs those seasons in seconds.

Where the example breaks: Real breeding works with living things and takes years. A genetic algorithm's "genes" are just numbers or settings, and its idea of "best" is whatever score the programmer wrote, which can reward the wrong thing if written badly.

Go deeper

How it actually works

A genetic algorithm is an optimisation method: it searches for the input that gives the highest score, without needing a formula for how to get there.

  1. Encode a solution as genes

    Each candidate is written as a string, like a row of 0s and 1s or a list of numbers, much like DNA. For an antenna, the genes might be the lengths and angles of its wire segments. One string is one complete guess.

  2. Score every candidate

    A fitness function measures how good each guess is, for example by simulating the antenna's signal. This is the only place the programmer says what "good" means. It plays the same role as a loss function, but higher is better.

  3. Select parents

    Better-scoring candidates are more likely to be picked as parents, but selection is partly random so weaker ones still get a chance. Often the very best are copied unchanged into the next generation, so progress is never lost.

  4. Crossover and mutation

    Crossover combines two parents, say the first half of one with the second half of the other. Mutation flips a few genes at random. Crossover mixes good parts; mutation adds new ideas so the search doesn't get stuck.

  5. Repeat until good enough

    The loop runs for many generations, or until the score stops improving. Unlike gradient descent, which trains neural networks, it needs no slope to follow, which helps when the problem is bumpy or the score cannot be calculated smoothly.

Pioneer
John Holland of the University of Michigan, whose 1975 book Adaptation in Natural and Artificial Systems laid out the idea
Famous result
An antenna evolved for NASA's Space Technology 5 mission, launched March 2006, described as the first artificially evolved object to fly in space
Core steps
Score, select, crossover, mutate, repeat
Used for
Optimisation problems with a huge number of possible answers, such as engineering designs

Questions people ask

What is a genetic algorithm in simple words?

A computer method that solves problems the way evolution improves living things. It makes many guesses, keeps the best, mixes and slightly changes them to make new guesses, and repeats until the answers are good.

Is a genetic algorithm machine learning?

It is usually filed under AI and optimisation rather than mainstream machine learning. It searches for a good answer instead of learning patterns from examples.

What are crossover and mutation?

Crossover makes a child by combining parts of two parent solutions. Mutation randomly changes a small part of a solution. Together they produce new candidates that are similar to good ones but not identical.

What is the difference between a genetic algorithm and an evolutionary algorithm?

Evolutionary algorithm is the wider family of methods inspired by evolution. A genetic algorithm is one popular member, known for encoding solutions as gene-like strings and using crossover and mutation.

Where are genetic algorithms used in real life?

In optimisation problems with a huge number of possible answers, such as engineering designs. A well-known example is the antenna NASA evolved for its Space Technology 5 satellites, launched in 2006. When requirements changed, engineers evolved a new design in a few weeks.

Was this clear?

1 is confusing, 5 is crystal clear. One tap, no account needed.

Spotted something wrong, or know a better example? Suggest a change

Further reading