Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A memory that completes what you give it
Show a Hopfield network a smudged or half-hidden picture it has stored, and it fills in the rest. Every unit is connected to every other, and the connections encode which units tend to agree in the stored memories. When the network runs, each unit flips to agree with what its neighbours “vote” for, and the whole pattern slides towards the closest stored memory, like a ball rolling into the nearest valley.
Hopfield networks introduced the energy view of neural computation (John Hopfield shared the 2024 Nobel Prize in Physics for it), linking networks to physics and optimisation. Their modern versions are mathematically the attention mechanism of transformers (E6-7), and the energy idea underlies Boltzmann machines and energy-based models.
- 1. A Hopfield network recalls a memory from…
- 2. Each update…
- 3. Hopfield networks are connected…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Storage (Hebbian): Wᵢⱼ = (1/N)Σₚ xᵢᵖxⱼᵖ, Wᵢᵢ = 0. For one pattern (1, −1, 1): W = (1/3)[[0, −1, 1], [−1, 0, −1], [1, −1, 0]].
- Update (asynchronous): pick a unit i; set xᵢ = sign(Σⱼ Wᵢⱼxⱼ).
- Energy: E(x) = −½xᵀWx. With W = [[0, 1], [1, 0]]: E(1, 1) = −1 and E(1, −1) = +1.
- Overlap: m = (1/N)x·xᵖ, 1 for perfect recall; (1, 1, 1, −1) against (1, 1, −1, −1) gives 0.5.
- Capacity: about 0.138N patterns with a small fraction of errors (138 for N = 1000), and about N/(2 ln N) with none (18.9 for N = 200).
- Spurious states: negatives of stored patterns and mixtures of odd numbers of them are also stable.
- 1. E(1, 1) with W = [[0, 1], [1, 0]]:
- 2. Capacity of 1000 units (small errors allowed):
- 3. The negative of a stored pattern is…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Hopfield networks in code
Exercise 1.
- With three stored 64-unit patterns, each pattern was a fixed point of the update.
- From a random start, the energy fell from −1.28 to −30.7 over 2000 asynchronous updates without ever rising, ending on a stored pattern (overlap 1.00).
Practice.
- Use ±1 units, zero diagonal and asynchronous updates; synchronous updates can oscillate between two states.
- Correlated patterns (similar images) interfere far more than random ones. Store decorrelated codes, or use the pseudo-inverse (projection) rule, or modern Hopfield networks (E6-7).
- For optimisation, encode a cost as the energy (Hopfield and Tank, 1985), although such networks often end in poor local minima.
W = X.T @ X / N; np.fill_diagonal(W, 0)
for i in rng.permutation(N): x[i] = 1 if W[i] @ x >= 0 else -1- 1. Synchronous updates can…
- 2. Correlated patterns…
- 3. Hopfield–Tank networks applied the energy to…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Energy descent. Updating unit i changes the energy by ΔE = −Δxᵢ·hᵢ with hᵢ = Σⱼ Wᵢⱼxⱼ, when W is symmetric with zero diagonal. The update sets xᵢ = sign(hᵢ), so Δxᵢ has the sign of hᵢ (or is zero) and ΔE ≤ 0. The energy is bounded below and states are finite, so the network reaches a fixed point.
Crosstalk. For a stored pattern ξ, the field on unit i is ξᵢ plus a crosstalk term from the other patterns, roughly Gaussian with variance (P − 1)/N. Recall fails when crosstalk flips units; for error-free recall of every pattern this limits P to about N/(2 ln N).
0.138N. Amit, Gutfreund and Sompolinsky (1985) used statistical mechanics to show that for P/N below about 0.138 the stored patterns are attractors with a small error fraction (about 1.6%); above it, retrieval states vanish abruptly as N → ∞. Finite networks show a smoother transition, as in exercise 2.
Connection to physics. The network is an Ising spin glass with Hebbian couplings; memories are low-energy states. This mapping brought methods from statistical physics into neural networks.
- 1. Energy descent needs W to be…
- 2. Crosstalk variance grows with…
- 3. Amit et al. used methods from…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Measuring capacity
History.
- J. Hopfield (1982) introduced the network; Hopfield (1984) gave a continuous version.
- J. Hopfield and D. Tank (1985) used it for optimisation (the travelling salesman problem).
- D. Amit, H. Gutfreund and H. Sompolinsky (1985) derived the 0.138 capacity.
- J. Hopfield and G. Hinton shared the 2024 Nobel Prize in Physics.
Exercise 2. N = 200 units, P random patterns stored by the Hebbian rule; each pattern is cued with 10% of its bits flipped and updated asynchronously until stable. Three seeds:
| load P/N | recalled exactly | mean overlap |
|---|---|---|
| 0.05 | 1.000 | 1.000 |
| 0.10 | 0.883 | 0.998 |
| 0.13 | 0.577 | 0.957 |
| 0.16 | 0.302 | 0.865 |
| 0.20 | 0.100 | 0.710 |
| 0.25 | 0.000 | 0.486 |
- Error-free recall held at load 0.05 and started to fail at 0.10, just above the N/(2 ln N) limit (0.094 for N = 200).
- Approximate recall (overlap above 0.95) held up to 0.13, close to the 0.138 capacity.
- Beyond that, recall degraded steadily; in a finite network the transition is smooth rather than abrupt.
Hopfield networks in AI, robotics and aerospace
- Associative recall and pattern completion, for example restoring corrupted telemetry frames against known templates.
- Energy-based thinking underlies Boltzmann machines, energy-based models and the analysis of attention.
- Analogue and optical hardware has implemented Hopfield-style networks for fast optimisation.
References
- J. J. Hopfield (1982). “Neural networks and physical systems with emergent collective computational abilities.” PNAS 79(8).
- D. J. Amit, H. Gutfreund, H. Sompolinsky (1985). “Storing infinite numbers of patterns in a spin-glass model of neural networks.” Physical Review Letters 55(14).
- J. J. Hopfield, D. W. Tank (1985). “‘Neural’ computation of decisions in optimization problems.” Biological Cybernetics 52.
- R. J. McEliece, E. C. Posner, E. R. Rodemich, S. S. Venkatesh (1987). “The capacity of the Hopfield associative memory.” IEEE Trans. Information Theory 33(4).