Skip to main content
Sandbox Physics

Hopfield Associative Memory

How can a network recover a whole picture from a damaged cue? The stored pictures set connections that favor familiar combinations of cells. Starting from a damaged cue, each cell follows the influence of the others and the network energy falls. The final pattern can recover a memory or settle in a competing local minimum.

Scratch over a stored picture and let a network repair it one cell at a time. Add competing memories or scramble most of the cue to see when recall finds a different resting state.

Interactive modelHopfield Associative Memory
Error against selected picture00
Network energy00
Cells changed in this sweep00
Recall state00
Energy falls during this recall
Pictures stored in the weights

A recorded asynchronous recall is replayed. Cyan: computed energy; amber: current frame.

Scientific sources

A memory is a resting state of the network

BackgroundA familiar word can survive a missing letter. Hopfield’s model asks whether many simple units, each following its neighbors, can recover a familiar pattern from a damaged one.

Why it mattersThe memory sits in the connections between units. No separate program tells each cell which part of a heart or a lightning bolt it should draw.

One-sentence intuition
Symmetric connections let asynchronous updates descend an energy function toward a stable pattern.

Core mathematical model

Pictures set the connections

wij=1N∑μ=1Pξiμξjμ,wii=0w_{ij}=\frac{1}{N}\sum_{\mu=1}^{P}\xi_i^{\mu}\xi_j^{\mu},\qquad w_{ii}=0

A stored picture assigns one binary value to each cell. A pair that often agrees gets a positive connection; a pair that often differs gets a negative one. The count of cells sets the normalization.

A cell follows its local field

si←sgn⁡ ⁣(∑jwijsj)s_i\leftarrow\operatorname{sgn}\!\left(\sum_j w_{ij}s_j\right)

One unit updates at a time, in a shuffled order. It follows the weighted influence of the other units. A zero sum leaves it unchanged.

Energy decreases when a unit changes

E=−12∑i,jwijsisj,ΔE=−(sinew−siold)∑jwijsj≤0E=-\frac12\sum_{i,j}w_{ij}s_i s_j,\qquad\Delta E=-(s_i^{\mathrm{new}}-s_i^{\mathrm{old}})\sum_j w_{ij}s_j\leq0

Symmetric weights and zero self-coupling make each allowed change lower the energy. The units eventually reach a state that no single update can improve.

Common difficulties

A minimum can be the wrong memory

Typical misconceptionOnce the energy stops falling, the intended picture must have been recovered.

Better mental modelThe energy can have many local minima. Correlated stored pictures can shift or merge them, and every picture has an inverted partner in this zero-threshold model.

Run the experiment

  1. 01

    Watch the repair

    Choose Repair a scratched heart and follow the amber marker on the energy curve.

    What to observe: The damaged cells change as the energy falls. The recorded recall repeats so you can follow the same repair.
  2. 02

    Give it a different clue

    Choose Recall lightning, then drag over part of the picture.

    What to observe: Release the pointer to start a new recall from your drawing. The connections stay fixed during recall.
  3. 03

    Let memories compete

    Choose Competing pictures and inspect the final error.

    What to observe: The correlated patterns can pull the network into a resting state that differs from the selected picture.
  4. 04

    Try the inverted picture

    Choose An inverted memory.

    What to observe: The network can settle on the inverted picture, which has the same energy as its original.

Related experiments and articles

What this page links to directly

See every article series on the content map →

Continue exploring

Chance and thresholds in living systems

How do random events, thresholds and neighbour coupling shape populations, neurons and tissue patterns?

  1. LabGenetic Drift and Fixation: Who Takes Over a Small Population?Leave Half and half: a coin flip running and watch chance alone let one type take over.
  2. LabRange Expansion Sectors: Why a Mixed Colony Grows in StripesChoose A straight front loses colours and watch the number of sectors fall as it grows.
  3. LabPulled and Pushed Waves: Where an Invading Population Comes FromCompare the Pulled and Fully pushed presets and see where the ancestors of the front sit.
  4. LabHodgkin–Huxley Model: How a Squid Axon Fires an Action PotentialCompare One all-or-none spike with Just below threshold and watch the membrane voltage.
  5. LabStochastic Ion Channels: Why Small Neurons Fire UnreliablyLeave Threshold becomes a coin flip running and count how often the same shock fires.
  6. LabExcitable waves and spiralsChoose A half-recovered sheet and drag a short stroke on each side to see where a wave starts.
  7. LabNeural Avalanches and Criticality: When a Power Law MisleadsCompare Cascades near the critical point with Shared slow input, no coupling on the size chart.
  8. LabIsing Critical FluctuationsCompare Order survives with Heat breaks the patches and watch how far aligned patches reach.
  9. You are hereHopfield Associative MemoryChoose Recall lightning, drag over part of the picture and watch the network restore it.
  10. LabTuring patternsChoose Spots emerge, then Diffusion smooths, and compare whether a pattern grows.
  11. LabActive Nematic FlowCompare Defects drive the flow with Reverse the stress and watch the flow turn around.

Heat and collective behaviour · Reading path

When a network can remember and learn

Articles on this path that use this experiment, followed by the other experiments they suggest.

  1. ArticleHow a Hopfield network finds a damaged memory
  2. ArticleHow a Boltzmann machine learns which patterns belong together
Something broken, confusing, or missing on this page?Tell us
What kind of feedback?

Sent with this page’s address, its Lab ID, the site language and your device type. Please leave out personal details. Feedback is kept for up to 12 months.Privacy policy