From Ising Models to Recurrent Neural Networks
ML for Science and Engineering — Lecture 17
Joseph Bakarji
We have been building a toolkit for modeling dynamical systems from data:
Every time-stepping scheme is an autoregressive model:
The Ising Model, Hopfield Networks, and Boltzmann Machines
How statistical mechanics inspired the first neural network architectures
A model from statistical mechanics: a 2D grid of spins, each either "up" $(+1)$ or "down" $(-1)$. Neighboring spins want to align. The model was designed to explain ferromagnetism: how local interactions produce global order.
$s_i \in \{-1, +1\}$ = spin at site $i$
$J > 0$ = coupling (scalar); favors aligned neighbors
$h$ = external magnetic field (scalar)
$\langle i,j \rangle$ = nearest-neighbor pairs only
The Metropolis-Hastings algorithm simulates the Ising model at temperature $T$:
import numpy as np
def ising_step(grid, T, J=1.0):
N = grid.shape[0]
for _ in range(N * N):
i, j = np.random.randint(N, size=2)
s = grid[i, j]
# Sum of 4 nearest neighbors
neighbors = (grid[(i-1)%N, j] +
grid[(i+1)%N, j] +
grid[i, (j-1)%N] +
grid[i, (j+1)%N])
dE = 2 * J * s * neighbors
if dE <= 0 or np.random.rand() < np.exp(-dE / T):
grid[i, j] = -s
return grid
The Ising model is the simplest model of a magnetic material. It was proposed by Wilhelm Lenz in 1920 and solved analytically in 1D by his student Ernst Ising in 1925. Despite its simplicity, it exhibits phase transitions and connects directly to Hopfield networks and Boltzmann machines.
A lattice of spins $s_i \in {-1, +1}$ with nearest-neighbor coupling:
$$E({s}) = -J \sum_{\langle i,j \rangle} s_i s_j$$
where $J > 0$ favors alignment (ferromagnetic). At temperature $T$, configurations follow the Boltzmann distribution:
$$P({s}) = \frac{1}{Z} e^{-E({s})/T}$$
The 2D Ising model has a critical temperature $T_c \approx 2.27$ (in units of $J/k_B$).
Let's simulate the Ising model at three temperatures and watch the dynamics.
The order parameter is the average magnetization:
$$m = \frac{1}{N^2} \left| \sum_i s_i \right|$$
Near $T_c$, it drops from $m \approx 1$ to $m \approx 0$. Let's trace $m(T)$.
The Ising model is the direct ancestor of:
| Physics | Neural Networks |
|---|---|
| Spin $s_i \in {-1, +1}$ | Neuron activation |
| Coupling $J_{ij}$ | Synaptic weight $w_{ij}$ |
| Energy $E({s})$ | Loss / cost function |
| Boltzmann dist. $e^{-E/T}$ | Softmax / Gibbs sampling |
| Energy minimization | Learning |
Hopfield (1982): Replace the lattice with a fully connected graph. Local energy minima become stored memories.
Boltzmann machines (1985): Add hidden units. Train by adjusting $J_{ij}$ to match data statistics.
The mathematical framework is identical — only the interpretation changes.
Critical slowing down: Measure how many sweeps it takes to reach equilibrium at $T = T_c$ vs. $T = 1.5$. Why is it slower near the critical point?
Energy vs. temperature: Plot the average energy $\langle E \rangle$ as a function of $T$. Compute the specific heat $C = \partial \langle E \rangle / \partial T$ and find its peak near $T_c$.
External field: Add an external magnetic field $h$ to the energy: $E = -J \sum s_i s_j - h \sum s_i$. How does the magnetization curve change?
Hopfield network: Modify the code so that $J_{ij}$ stores patterns via the Hebbian rule $J_{ij} = \frac{1}{P}\sum_{\mu=1}^P \xi_i^\mu \xi_j^\mu$. Initialize the grid near a stored pattern and watch it converge.
John Hopfield's insight: replace the Ising lattice with a fully connected network. Instead of nearest-neighbor coupling, every neuron connects to every other. The energy landscape has local minima that serve as stored memories.
Same energy as Ising, but with all-to-all learned weights $W_{ij}$ instead of uniform nearest-neighbor coupling $J$.
John Hopfield
Geoffrey Hinton
Nobel Prize in Physics 2024
Photos: Wikimedia Commons (CC BY 4.0)
The network operates as an associative memory: given a corrupted input, it recovers the closest stored pattern.
Ramsauer et al. (2021) showed that with continuous states and a log-sum-exp energy, the Hopfield update rule becomes:
Geoffrey Hinton and Terrence Sejnowski (1985) extended Hopfield networks with two ingredients:
A Restricted Boltzmann Machine (RBM) has no connections within the same layer (bipartite graph):
Goal: maximize the probability the model assigns to real data. The gradient has a beautiful structure:
Physics-inspired designs gave birth to modern deep learning:
Hopfield (1982)
Energy minimization
Associative memory
$\downarrow$
Modern Hopfield
$\rightarrow$ Transformers
Boltzmann (1985)
Gibbs distribution
Generative model
$\downarrow$
Pretraining
$\rightarrow$ VAEs, GANs, Diffusion
Ising (1920)
Phase transitions
Statistical mechanics
$\downarrow$
Energy-based learning
$\rightarrow$ Unifying framework
Learning dynamics in a hidden state space
Introduce a hidden state $h_t$ that captures information beyond the current observation:
Loss: $\mathcal{L} = \sum_t \|\hat{x}_{t+1} - x_{t+1}\|^2$ — minimize prediction error across the sequence.
Click Next to advance through the sequence. At each step, the hidden state $h_t$ absorbs the new input and produces a prediction.
Further reading: Dobilas, S. (2022). "RNN: How to Successfully Model Sequential Data in Python." Towards Data Science. Link
The RNN is a nonlinear generalization of the discrete-time state-space model:
| Linear State-Space | RNN | |
|---|---|---|
| State update | $h_{t+1} = A h_t + B x_t$ | $h_t = \tanh(W_{hh} h_{t-1} + W_{xh} x_t)$ |
| Output | $y_t = C h_t$ | $\hat{x}_{t+1} = W_{hy} h_t$ |
| Dynamics | $A$ (fixed matrix) | $W_{hh}$ (learned, nonlinear) |
| Input coupling | $B$ (fixed) | $W_{xh}$ (learned) |
| Readout | $C$ (fixed) | $W_{hy}$ (learned) |
To train the RNN, we unroll through time and apply the chain rule. The gradient at time $t$ involves all earlier hidden states:
Each step-to-step Jacobian: $\;\frac{\partial h_{k+1}}{\partial h_k} = W_{hh}^T \cdot \text{diag}(\tanh'(z_k))$, so:
The spectral radius $\rho(W_{hh})$ is the largest eigenvalue magnitude of $W_{hh}$. It controls how gradients scale through time: $\;\left|\frac{\partial h_k}{\partial h_0}\right| \sim \big(\rho(W_{hh}) \cdot \overline{\tanh'}\big)^k$
Hochreiter & Schmidhuber (1997) introduced gating mechanisms and a cell state highway:
Source: Wikipedia (CC BY-SA 4.0)
What if you never train the recurrent weights?
A radically different approach: the recurrent dynamics are random and fixed. Only a linear readout is trained.
Jaeger, H. (2001). "The echo state approach to analysing and training recurrent neural networks." GMD Report 148, German National Research Center for Information Technology.
For the reservoir to be useful, it must forget initial conditions:
A sinusoidal input $x(t)$ drives 4 reservoir neurons. Each neuron transforms the input differently via random weights. The spectral radius $\rho(W)$ controls how much memory the reservoir has.
Any physical system with sufficient complexity, nonlinearity, and fading memory can be a reservoir:
| Physical System | Reservoir Mechanism | Reference |
|---|---|---|
| Photonic circuits | Mach-Zehnder modulator + delay feedback | Larger et al. 2012 |
| Mechanical networks | Mass-spring nonlinear coupling | Dion et al. 2018 |
| Quantum systems | Interacting qubits, exponential Hilbert space | Fujii & Nakajima 2017 |
| Biological neurons | Cortical microcircuits (Liquid State Machines) | Maass et al. 2002 |
Pathak et al., Physical Review Letters (2018)
Developed independently by Kuramoto (1978, chemical oscillations) and Sivashinsky (1977, flame-front instabilities). It is one of the simplest PDEs exhibiting spatiotemporal chaos:
$-u \, u_x$: nonlinear advection — transfers energy between spatial scales
$-u_{xx}$: anti-diffusion — injects energy at small scales (destabilizing!)
$-u_{xxxx}$: hyper-diffusion — dissipates energy at the smallest scales
Simulated KS-like spatiotemporal pattern
Pathak, J., Hunt, B., Girvan, M., Lu, Z., & Ott, E. (2018). "Model-free prediction of large spatiotemporally chaotic systems from data: A reservoir computing approach." Physical Review Letters, 120(2), 024102. doi:10.1103/PhysRevLett.120.024102
| Feature | Vanilla RNN | LSTM | ESN |
|---|---|---|---|
| Recurrent weights | Trained (BPTT) | Trained (BPTT) | Fixed random |
| Training cost | $O(N^2 T \cdot \text{epochs})$ | $O(N^2 T \cdot \text{epochs})$ | $O(N^2 T + N^3)$ |
| Gradient issues | Vanishing / exploding | Mitigated (cell highway) | None (no BPTT) |
| Memory | Short | Long (gated) | $\leq N$ (hard limit) |
| Interpretability | Low | Low | High (linear readout) |
| Adaptability | Learned features | Learned features | Random features |
| Era | Architecture | Core Idea | Physics Connection |
|---|---|---|---|
| 1980s | Hopfield / Boltzmann | Energy minimization as computation | Ising model, stat mech |
| 1990s | RNN / LSTM | Learned dynamics in hidden space | Dynamical systems, state-space |
| 2000s | Echo State Networks | Random dynamics + linear readout | Edge of chaos, physical reservoirs |
| 2020s | Transformers / SSMs | Attention = Hopfield retrieval | Modern Hopfield energy |
Hopfield & Boltzmann
Hopfield (1982). Neural networks and physical systems with emergent collective computational abilities. PNAS.
Ramsauer et al. (2021). Hopfield networks is all you need. ICLR.
McEliece et al. (1987). The capacity of the Hopfield associative memory. IEEE TIT.
Hinton & Sejnowski (1983). Boltzmann machines. CVPR.
Hinton (2002). Contrastive divergence. Neural Computation.
Hinton et al. (2006). Deep belief nets. Neural Computation.
RNNs & LSTMs
Hochreiter & Schmidhuber (1997). Long short-term memory. Neural Computation.
Cho et al. (2014). GRU encoder-decoder. EMNLP.
Reservoir Computing
Jaeger (2001). Echo state networks. GMD Report 148.
Maass et al. (2002). Liquid state machines. Neural Computation.
Pathak et al. (2018). Predicting spatiotemporal chaos. PRL.
Dambre et al. (2012). Information processing capacity. Scientific Reports.
Gauthier et al. (2021). Next generation RC. Nature Comm.
Modern
Chen et al. (2018). Neural ODEs. NeurIPS.
LeCun et al. (2006). Energy-based learning. MIT Press.