Skip to content
StackDecode
AI & ML Atlas
Artificial IntelligencealgorithmInteractive simulation

Genetic Algorithm

Evolves a population of solutions using selection, crossover and mutation.

The idea

Keep a population of candidate solutions. Fitter ones are more likely to be chosen as parents; their "genes" are mixed (crossover) and randomly tweaked (mutation) to make the next generation. Over many generations the population drifts toward high fitness.

next generation = mutate(crossover(select(population)))

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

  • fittest
  • population

A random population: every dot is a candidate solution. Brighter ground = fitter.

generation:
0
best:
0.686
1/26

Dark spots on the map are poor settings; bright spots are good. One of the peaks is the tallest.

Step by step

  1. 1Create a random population and score every individual.
  2. 2Select parents, favouring higher fitness.
  3. 3Crossover pairs of parents to make children.
  4. 4Mutate a few genes at random.
  5. 5Replace the population and repeat for many generations.

Where it is used

Design optimisation, scheduling, evolving neural network structures.

Watch out for

Needs a sensible encoding and fitness function. Too little mutation loses diversity and converges early.

Related