Hopfield Network Visualization
Two Jupyter notebooks exploring Hopfield networks — a basic 2-neuron energy landscape demo and an advanced 5x5 grid showing pattern storage and noisy-input recovery with animation. Built with AI assistance while learning the concepts.
Two Jupyter notebooks that implement and visualize Hopfield networks — a classical recurrent associative memory architecture — as a learning exercise.
Note
These notebooks were built with ChatGPT and Claude as active collaborators (both credited in the README). This is an exploratory/educational project, not independent original research.
Attractor Dynamics: Rolling Down the Energy Gradient
In a recurrent Hopfield network, memorized patterns exist as local minima on an energy surface. Asynchronous neuron updates guarantee that energy monotonically decreases until a clean pattern is recovered.
Retrieval is the loop in the middle: the network is not looking anything up, it is falling downhill on an energy surface until it stops moving. That is the part the advanced notebook animates frame by frame.
What’s in the notebooks
Basic (2-neuron): Implements a minimal Hopfield network with 2 neurons to show the core concept — energy landscape, weight matrix from Hebb’s rule, and convergence to a stored pattern. Visualizes the energy function as a 3D surface to make the “energy minimization = memory retrieval” idea concrete.
Advanced (5×5 grid): Scales to a 25-neuron network arranged as a 5×5 image grid. Demonstrates:
- Storing multiple binary patterns (5×5 pixel “images”)
- Presenting a noisy or incomplete version of a stored pattern
- Watching the network iterate via asynchronous update rules until it converges to the nearest stored memory
- Animating the convergence step-by-step with Matplotlib
Why Hopfield networks
Hopfield networks predate modern deep learning and aren’t used in production ML today, but they make the core ideas of energy-based models, associative memory, and recurrent dynamics unusually visible. The energy landscape is something you can actually plot. The weight update rule is one equation. It’s a good starting point for understanding what “the network has learned something” means at a mathematical level before moving to neural networks where everything is less interpretable.
Stack
- Python 3, NumPy, Matplotlib
- Jupyter Notebook
Timeline: Oct 2024 · Learning project