⚡

Energy-Based Model (EBM) Langevin Studio

v1.0 MIT

Unnormalized Densities, Score Matching & Stochastic Gradient Langevin Dynamics (SGLD)

Physics-Informed Generative AI: Unnormalized Densities & SGLD Sampling

Unlike autoregressive or normalized likelihood models, Energy-Based Models (EBMs) parameterize unnormalized probability distributions $p_\theta(\mathbf{x}) \propto \exp(-E_\theta(\mathbf{x})/T)$. Sampling bypasses the intractable partition function $Z_\theta$ via Stochastic Gradient Langevin Dynamics (SGLD), where a particle swarm drifts along the score field $\mathbf{s}(\mathbf{x}) = -\nabla_{\mathbf{x}} E(\mathbf{x})$ perturbed by Brownian thermal noise.

Langevin SDE & Score Matching
$$d\mathbf{x}_t = -\nabla_{\mathbf{x}} E(\mathbf{x}_t) dt + \sqrt{2T} d\mathbf{W}_t$$
$$\mathbf{x}_{t+1} = \mathbf{x}_t - \frac{\epsilon}{2} \nabla_{\mathbf{x}} E(\mathbf{x}_t) + \sqrt{\epsilon T} \boldsymbol{\xi}_t$$

Langevin MCMC Particle Swarm & Score Vector Field

Particles: 200

Particles stream down the negative energy gradient $-\nabla E(\mathbf{x})$ perturbed by thermal Brownian noise $\sqrt{\epsilon T} \xi_t$. Click canvas to drop particles!

Energy Basin Color: Low (Cyan) → High (Magenta)
Mean Energy ⟨E⟩
0.42
Mean Score ‖∇E‖
0.85
Thermal Noise σ
0.118

3D Energy Landscape $E(\mathbf{x})$

Potential Manifold

Continuous 3D perspective of the scalar energy function $E_\theta(x, y)$ depicting potential barriers and metastable attraction basins.

Energy Function: (x²-1)² + (y²-1)² + 0.3xy
Global Minima: 4 Symmetric Wells

Stationary MCMC Density vs Boltzmann Target $p(\mathbf{x}) \propto e^{-E/T}$

● Empirical Swarm Samples — Boltzmann Theory
Wasserstein-1 Error
0.038
MALA Acceptance
92.4%
Barrier Hopping Rate
14.2 hops/sec

Score Matching & Energy Compositionality

Partition-Free

Because energy functions are unnormalized, multiple models can be composed zero-shot via simple addition. The intersection of concepts corresponds to the sum of their energies!

Product of Experts (Conjunction)
$$E_{\text{joint}}(\mathbf{x}) = E_1(\mathbf{x}) + E_2(\mathbf{x}) \implies p_{\text{joint}}(\mathbf{x}) \propto p_1(\mathbf{x}) \cdot p_2(\mathbf{x})$$
Score Vector: $\nabla_{\mathbf{x}} \log p_{\text{joint}}(\mathbf{x}) = -\nabla E_1(\mathbf{x}) - \nabla E_2(\mathbf{x})$
Loss Objectives (No MCMC in Inner Loop)
Implicit Score Matching (Hyvärinen 2005):
$$\mathcal{L}_{\text{ISM}} = \mathbb{E}\left[ \frac{1}{2} \|\nabla E_\theta(\mathbf{x})\|^2 - \text{Tr}(\nabla^2 E_\theta(\mathbf{x})) \right]$$
Denoising Score Matching (Vincent 2011):
$$\mathcal{L}_{\text{DSM}} = \mathbb{E}_{\tilde{\mathbf{x}} \sim q(\tilde{\mathbf{x}}|\mathbf{x})}\left[ \left\| -\nabla E_\theta(\tilde{\mathbf{x}}) - \frac{\mathbf{x} - \tilde{\mathbf{x}}}{\sigma^2} \right\|^2 \right]$$