A Python reimplementation of the simulation from:
Hinton, G. E., & Nowlan, S. J. (1987). How Learning Can Guide Evolution. Complex Systems, 1, 495–502.
The paper's puzzle: how can evolution find a needle in a haystack when the haystack has no gradient to climb? Its answer is the Baldwin effect — learning during an individual's lifetime can turn a flat, gradient-less fitness landscape into a smooth one that natural selection can climb, without the learned trait ever being directly written into the genome.
Each individual has a genome of 20 genes. Each gene is one of:
| Symbol | Meaning |
|---|---|
1 |
correct allele, fixed by genetics ("innate knowledge") |
0 |
incorrect allele, fixed by genetics |
? |
plastic allele — resolved by learning during the individual's life |
Fitness landscape (needle in a haystack): of the 2²⁰ possible phenotypes (each gene expressed as correct/incorrect), exactly one — all 20 genes correct — gives high fitness. Every other phenotype gets the same low baseline fitness. There is no partial credit for "close" genomes, so a pure genetic search has nothing to hill-climb.
Learning: an individual with any fixed-incorrect gene can never express the correct phenotype, no matter how much it learns. An individual whose non-plastic genes are all correct, however, can potentially stumble onto the right phenotype by guessing random 0/1 values for its plastic genes, up to ~1000 trials in its lifetime. If it has k plastic genes, each trial succeeds with probability 0.5^k. The fewer trials it needs, the higher its fitness:
- found on trial 1 (e.g. no plastic genes left, already correct) → fitness ≈ 20 (max)
- found late in the 1000-trial budget → fitness barely above baseline
- never found within the budget → fitness = 1 (baseline)
This is the trick: individuals that are genetically close to the answer (few plastic genes needed) tend to find it faster and score higher, even though the genome itself never encodes the full solution. Learning converts the flat landscape into a gradient that selection can follow.
A standard generational genetic algorithm. The reproduction operators — fitness-proportionate selection, single-point crossover, and per-gene mutation — are Holland's genetic algorithm from Adaptation in Natural and Artificial Systems (1975; see References). Hinton & Nowlan's contribution isn't a new algorithm; it's the plastic-allele fitness landscape layered on top of it, which is what turns the needle-in-a-haystack search into something Holland's GA can actually climb.
- Initialize a population of 1000 individuals; each gene is correct with probability 0.25, incorrect with probability 0.25, and plastic otherwise (≈50%).
- Evaluate fitness of every individual via the learning process above (vectorized with a geometric distribution instead of literally looping over 1000 trials per individual — statistically equivalent, much faster).
- Select parents by fitness-proportionate (roulette wheel) selection.
- Crossover: single-point crossover on parent pairs.
- Mutate: each gene independently has a small chance of becoming a random allele (correct/incorrect/plastic).
- Repeat for 50 generations, recording the proportion of correct, incorrect, and plastic alleles each generation.
python3 baldwin_effect.pyUseful flags: --pop-size, --generations, --mutation-rate,
--max-learning-trials, --seed, --out. Run python3 baldwin_effect.py -h
for the full list.
The script prints per-generation stats and writes a plot to
baldwin_effect.png.
Reading the plot:
- Incorrect alleles collapse almost to zero by around generation 15 — a fixed-wrong gene dooms an individual regardless of learning, so selection purges it quickly.
- Correct alleles rise from ~25% to ~75%, driven by the fitness gradient that learning creates around the single correct genotype.
- Plastic alleles decline but never disappear, settling around 24%. This is the paper's central finding: learning smooths the landscape enough for evolution to make progress, but genetic assimilation is only partial — a meaningful fraction of the genome stays plastic even after many generations.
- Mean fitness climbs from 1 to ~19 as the population improves, while best fitness hits the maximum of 20 as soon as a lucky, low-plasticity, high-fitness individual appears for selection to amplify (around generation 15 here).
- Hinton, G. E., & Nowlan, S. J. (1987). How Learning Can Guide Evolution. Complex Systems, 1, 495–502.
- Holland, J. H. (1975). Adaptation in Natural and Artificial Systems. University of Michigan Press.
