Physics for Machine Learning: Why the Same Equations Keep Coming Back
Published:
The pattern worth noticing
An interviewer rarely asks “what is the second law of thermodynamics”. They ask why diffusion models need many small steps, or why Hamiltonian Monte Carlo uses a leapfrog integrator, or what temperature does in a softmax. Each of those has a one-line answer if you know the physics and a confused one if you do not.
The reason is historical and not accidental. Sampling from a complicated high-dimensional distribution is the central computational problem of statistical mechanics, and it has been for a century. Machine learning inherited the problem — and, with it, the solutions.
Four lines of descent
Diffusion models come from non-equilibrium thermodynamics. The founding paper, Sohl-Dickstein et al. (2015), is explicit about it: take a data distribution, drive it towards a simple equilibrium with a slow stochastic process, and learn to reverse the drive. The mathematics of “slowly destroy structure, then undo it” is the mathematics of annealed importance sampling and of the Jarzynski equality. Entropy and thermodynamics covers that ancestry; diffusion and Brownian motion covers the stochastic process itself.
Energy-based models come from statistical mechanics. Write any positive density as
where \(E_\theta\) is a learned energy and $Z(\theta)$ the partition function. This is the Boltzmann distribution at unit temperature. Every difficulty in training such a model — the intractable normaliser, the need for MCMC in the gradient, the role of temperature — is a difficulty statistical physics met first.
Hamiltonian Monte Carlo comes from mechanics. HMC invents a fictitious momentum, writes down a Hamiltonian, and integrates the resulting dynamics. It works because Hamiltonian flow preserves phase-space volume and is reversible, which is exactly what makes the Metropolis–Hastings acceptance ratio collapse to an energy difference. Neal’s review (2011) is the standard reference.
Symmetry arguments come from Noether. Every continuous symmetry of the action gives a conserved quantity. The modern echo is equivariant networks: build the symmetry into the architecture and the model no longer has to learn it from data.
Temperature, in one example
The clearest single case is temperature. The Boltzmann distribution over states with energies $E_i$ at temperature $T$ is $p_i \propto e^{-E_i/T}$. A softmax over logits $z_i$ is $p_i \propto e^{z_i/T}$. These are the same expression with $E_i = -z_i$. Take logits $(2.0,\,1.0,\,0.5)$:
| $T$ | resulting probabilities |
|---|---|
| 0.5 | 0.844, 0.114, 0.042 |
| 1.0 | 0.629, 0.231, 0.140 |
| 2.0 | 0.481, 0.292, 0.227 |
Low temperature concentrates on the lowest-energy state; high temperature flattens towards uniform. Simulated annealing, nucleus sampling and the noise schedule of a diffusion model are all versions of the same lever.
What the rest of the book covers
- Lagrangian mechanics — stationary action, $L = T - V$, the Euler–Lagrange equation, and why a variational formulation travels better than force balance.
- Hamiltonian dynamics — phase space, Liouville’s theorem, and why HMC needs a symplectic integrator.
- Statistical mechanics — microstates, the Boltzmann distribution, and what the partition function really is.
- Entropy and thermodynamics — Gibbs versus Shannon entropy, free energy as the ELBO, and the non-equilibrium origin of diffusion.
- Diffusion and Brownian motion — Wiener processes, Langevin and Fokker–Planck, and the sampler behind score-based models.
- Symmetry and conservation — Noether’s theorem and equivariant architectures.
Recap
- Sampling from an unnormalised high-dimensional density is a physics problem first and a machine learning problem second; the algorithms transferred wholesale.
- Softmax temperature and the Boltzmann distribution are the same formula with \(E = -z\).
- HMC works because of volume preservation and reversibility, not because Hamiltonian dynamics is a good heuristic.
- Diffusion models descend directly from non-equilibrium thermodynamics (Sohl-Dickstein et al., 2015), not by analogy.
- Noether's theorem is the reason symmetry constraints buy generalisation: a symmetry of the objective is a structural fact, not a regulariser.
References
- Sohl-Dickstein, J., Weiss, E., Maheswaranathan, N., & Ganguli, S. Deep Unsupervised Learning using Nonequilibrium Thermodynamics. ICML 2015.
- Neal, R. M. MCMC using Hamiltonian dynamics. Handbook of Markov Chain Monte Carlo, 2011.
- Song, Y., & Ermon, S. Generative Modeling by Estimating Gradients of the Data Distribution. NeurIPS 2019.
- LeCun, Y., Chopra, S., Hadsell, R., Ranzato, M., & Huang, F. A Tutorial on Energy-Based Learning. Predicting Structured Data, MIT Press, 2006.
