Boltzmann generators and normalizing flows
This application illustrates, in one dimension, the principle of Boltzmann generators: an invertible transformation is trained to map a simple, easily sampled distribution onto the Boltzmann distribution of a physical system.
1 · The sampling problem
In equilibrium statistical mechanics a configuration x occurs with probability
p*(x) = e−U(x)/kBT / Z ,
where U(x) is the potential energy, kBT the thermal energy and Z the partition function, which is generally unknown. If U has several deep wells, p* is concentrated in well-separated regions, and molecular dynamics or Monte Carlo simulations require long trajectories to move between them. A Boltzmann generator avoids this problem: it produces statistically independent samples by transforming samples of a simple distribution.
2 · Change of variables
Consider a latent variable z with a simple density pz(z) (top left panel) and an invertible, differentiable map x = fθ(z) (centre panel). The transformed variable has the density
px(x) = pz(z) |dfθ/dz|−1 , z = fθ−1(x) .
Where the map expands intervals (Jacobian |J| = |dfθ/dz| > 1), probability is spread over a larger range and the density decreases; where the map contracts, the density increases. The bottom left panel shows the factor |J|−1. Since fθ is invertible, px is normalized by construction. This construction is called a normalizing flow.
3 · Training the flow
The parameters θ are adjusted by gradient descent such that px approaches the target p*. Two standard objectives are available.
Energy-based training minimises the reverse Kullback–Leibler divergence,
L = 〈 U(fθ(z))/kBT − log |J(z)| 〉z∼pz = KL(px ‖ p*) + const .
Only the potential energy function is required; samples of the target are not needed. The first term drives the samples towards low energies; the second term, an entropy, prevents the distribution from collapsing onto the energy minimum.
Example-based training minimises the negative log-likelihood of data points xi distributed according to p* (forward Kullback–Leibler divergence),
NLL = 〈 −log pz( fθ−1(x)) + log |J| 〉data = KL(p* ‖ px) + const .
The loss panel shows both contributions separately (blue and orange) together with their sum (dark line).
While the target is displayed, the figure reports two free energies. The variational free energy of the flow, βFflow = 〈ln pz〉 + 〈U/kBT − ln |J|〉, is the free energy of the model distribution px in the target potential; βFexact = −ln Z is the free energy of the target itself. The two are related by the Gibbs–Bogoliubov inequality,
Fflow = Fexact + kBT KL(px ‖ p*) ≥ Fexact ,
which holds because the Kullback–Leibler divergence is non-negative. The gap between the two values shown in the figure is therefore exactly kBT KL(px ‖ p*); it closes when the flow reproduces the target, and training can be read as the minimisation of the variational free energy towards the exact one.
4 · Reweighting
A trained flow approximates the target but does not reproduce it exactly. Exact averages can nevertheless be obtained by importance sampling, in which each sample x is weighted with
w(x) = p*(x) / px(x) , 〈A〉 = Σ wiA(xi) / Σ wi .
The effective sample size Neff = (Σw)2/Σw2 quantifies the overlap between px and p* (activate Show importance weights after sampling).
5 · The transformation families
Polynomial maps are simple but not necessarily invertible; the application marks turning points and estimates px by a kernel density estimate in this case. The single-layer perceptron adds K sigmoid steps with positive weights to an increasing linear function and is therefore strictly monotonic and invertible. The rational-quadratic spline is a flexible monotonic spline on [−B, B] and is the building block of neural spline flows.
In one dimension an exact transformation exists, x*(z) = F*−1(Fz(z)), constructed from the two cumulative distribution functions (Show exact transformation). In higher dimensions no such formula exists and the transformation must be learned; this is the setting in which normalizing flows are applied in practice.
Further reading
F. Noé, S. Olsson, J. Köhler, H. Wu,
Boltzmann generators: Sampling equilibrium states of many-body
systems with deep learning, Science 365, eaaw1147
(2019).
D. Rezende, S. Mohamed, Variational inference with normalizing
flows, ICML (2015).
C. Durkan, A. Bekasov, I. Murray, G. Papamakarios, Neural
spline flows, NeurIPS (2019).
G. Papamakarios et al., Normalizing flows for
probabilistic modeling and inference, JMLR 22, 1
(2021).
A. Coretti, S. Falkner, J. Weinreich, C. Dellago,
O. A. von Lilienfeld, Boltzmann generators and the new
frontier of computational sampling in many-body systems,
KIM Review 2, 03 (2024).