---
title: "Hopfield Associative Memory Interactive Lab | Sandbox Physics"
description: "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."
canonical_url: "https://sandboxphysics.com/labs/hopfield-associative-memory/"
language: "en"
page_type: "lab"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/labs/hopfield-associative-memory/"
last_modified: "2026-10-24"
---

D-X2 · A damaged picture finds a memory

# 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 simulation: open this page in a web browser to change the parameters and run the model.

The network has one hundred and forty-four binary units with symmetric Hebbian weights, zero self-coupling and zero thresholds. Units update asynchronously in a shuffled order; a zero local field leaves a unit unchanged. Each successful update lowers the network energy. The three hand-drawn patterns are correlated, so a stored pattern need not remain an exact fixed point when all three are stored. The energy has other local minima, including inverted and mixed patterns; convergence alone does not guarantee the intended memory. There is no learning during recall, no thermal noise and no fitted model of a biological brain. Slowed updates make individual changes visible. The energy curve is a model diagnostic, not an electrical energy measurement.

Energy falls during this recall

Pictures stored in the weights

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

Scientific sources

- [Hopfield (1982), Neural networks and physical systems with emergent collective computational abilities](https://doi.org/10.1073/pnas.79.8.2554)
- [The Nobel Prize in Physics 2024](https://www.nobelprize.org/prizes/physics/2024/summary/)

## Where the idea came from

[How a Hopfield network finds a damaged memory](https://sandboxphysics.com/stories/thermal-complexity/hopfield-energy-memory/) [How a Boltzmann machine learns which patterns belong together](https://sandboxphysics.com/stories/thermal-complexity/hinton-boltzmann-learning/) [Explore heat, chance and collective behaviour](https://sandboxphysics.com/stories/thermal-complexity/)

Physics tutorial

## A memory is a resting state of the network

**Background** A 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 matters** The 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.

Start with the essentials

- **Focus question**: How can a network recover a whole picture from a damaged cue?
- **One-sentence intuition**: Symmetric connections let asynchronous updates descend an energy function toward a stable pattern.

### Core mathematical model

#### Pictures set the connections

$$
w_{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

$$
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=-\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 misconception** Once the energy stops falling, the intended picture must have been recovered.

**Better mental model** The 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.

Physical conclusion

Recall can be a physical relaxation process, and finding a stable state is only part of remembering correctly.

Fields & matter · Starter path

## From a field to an electron microscope

Map an electric field and steer a charged particle. Then find the electron's wavelength and use electron beams to see a crystal and a surface.

[Start here → **Make an Electric Field Visible** Move the probe around a dipole and check that the field always points downhill on the potential landscape. Observe · 8 min](https://sandboxphysics.com/labs/electric-field/)

1. [1 Make an Electric Field Visible](https://sandboxphysics.com/labs/electric-field/)
2. [2 A Charge Bending through Fields](https://sandboxphysics.com/labs/charged-particle/)
3. [3 Electron Wavelength & Voltage](https://sandboxphysics.com/labs/electron-wavelength/)
4. [4 Electron Diffraction & Reciprocal Space](https://sandboxphysics.com/labs/electron-diffraction/)
5. [5 TEM Bright Field, Dark Field & SAED](https://sandboxphysics.com/labs/tem-mode-selector/)
6. [6 SEM Secondary-Electron Topography](https://sandboxphysics.com/labs/sem-topography/)

[View the full path →](https://sandboxphysics.com/topics/fields-and-matter/#starter-path)
