TMC #0014: Hebb Learning Rule: Associative Memory Network
A pure-Python implementation of Hebbian learning (1949): outer-product weight storage, bipolar associative recall, noise-tolerance testing, capacity limit demonstration, and Oja's normalised rule for comparison.
Hebb's 1949 outer-product rule is the oldest weight-update algorithm in neural network history. This project implements it faithfully, tests its associative recall under noise, and measures the capacity limit () empirically.
What It Includes
HebbianNetwork: -neuron bipolar network. store(pattern) applies the outer-product update ; recall(cue, steps) performs synchronous threshold updates until convergence. Diagonal is zeroed (no self-connections).
Noise tolerance demo: Stores 5 patterns in a 100-neuron network, then queries each at corruption levels 5%–40%. Reports recall accuracy at each noise level and shows the cliff where retrieval fails.
Capacity limit experiment: Sweeps the number of stored patterns from 1 to 30 for neurons, measures average recall error, and finds the empirical : showing the theoretical pattern limit for .
Oja's rule comparison: OjaNetwork implements ; weight norms are plotted alongside pure Hebb to show stabilisation vs unbounded growth.
Running It
python hebb_sim.py # all demos
python hebb_sim.py --demo recall # noise tolerance only
python hebb_sim.py --demo capacity # capacity limit sweep
python hebb_sim.py --demo oja # Oja normalisation comparison
No external dependencies: pure Python 3.10+.