Genetic Algorithm

5 min read#optimization

Optimize with no gradient at all — keep a population of candidate solutions, let the fittest reproduce with mutation and crossover, and watch quality climb.

Genetic Algorithm

Some landscapes are too rugged, discrete, or mysterious to differentiate — there is no gradient to follow. A genetic algorithm sidesteps that entirely by imitating natural selection. Instead of one point creeping downhill, you maintain a whole population of candidate solutions and breed them:

  1. Evaluate each individual's fitness (how good a solution it is).
  2. Select parents, favoring the fitter ones.
  3. Crossover — combine two parents into a child, mixing their "genes."
  4. Mutate — randomly tweak a few genes to inject new variety.
  5. Repeat. The next generation is, on average, a little fitter than the last.

There is no derivative anywhere — only variation (mutation and crossover) and selection (survival of the fittest). Over generations, that loop reliably climbs toward good solutions, and it cheerfully handles problems gradient descent cannot touch.

Evolving toward a target phrase

The classic demonstration: evolve random gibberish into a target sentence. Each individual is a string; its fitness is simply how many letters it gets right. No string is ever designed — selection and mutation alone drive the population from noise to the exact phrase. Watch the best fitness climb generation by generation; matched letters turn green.

Click to start a fresh population of random strings.

A genetic algorithm evolving random strings toward a target phrase. Fitness = number of correct letters; selection favors the fittest, crossover mixes parents, mutation adds variety. The curve tracks best fitness rising to 100%. Click to reseed.

See also