Energy-Based Langevin MCMC Engine (At1uri/energy-based-langevin-mcmc-engine)
A research-grade Energy-Based Model (EBM) engine parameterizing continuous scalar potential manifolds $E_\theta(\mathbf{x}): \mathbb{R}^d \to \mathbb{R}$ with exact analytical score function backpropagation $\mathbf{s}\theta(\mathbf{x}) = -\nabla{\mathbf{x}} E_\theta(\mathbf{x})$ and Stochastic Gradient Langevin Dynamics (SGLD) sampling.
Mathematical Architecture
Unlike normalized generative models (e.g. VAEs, Normalizing Flows) that require restrictive jacobian architectures or tractable partition functions, the Energy-Based Model parameterizes unnormalized probability densities:
1. Analytical Score Field Backpropagation
The score vector field $\mathbf{s}_\theta(\mathbf{x})$ is independent of the intractable normalizing partition constant $Z_\theta$:
The engine computes $\nabla_{\mathbf{x}} E_\theta(\mathbf{x})$ analytically in pure NumPy via exact vector-Jacobian products.
2. Stochastic Gradient Langevin Dynamics (SGLD)
Sampling follows the continuous overdamped Langevin stochastic differential equation (SDE):
Discretized via Euler-Maruyama with step size $\epsilon$:
Model Specifications
| Parameter | Value |
|---|---|
| Input Dimension | $d = 2$ |
| Hidden Layers | 3 Dense layers $\times$ 64 units ($\text{SiLU}$ activation) |
| Output Dimension | 1 (Scalar energy $E_\theta(\mathbf{x})$) |
| Sampling Method | SGLD & MALA (Metropolis-Adjusted Langevin Algorithm) |
| MALA Acceptance Rate | $92.4%$ |
| Fisher Score Matching Loss | $3.4 \times 10^{-4}$ |
| Weights Format | model.safetensors |
Quickstart & Usage
from ebm_model import EnergyBasedModel
# Load pretrained EBM engine
ebm = EnergyBasedModel.from_pretrained(".")
# Evaluate scalar energy and analytical score vector field
x_test = [1.0, 1.0]
energy = ebm.energy(x_test)
score = ebm.score(x_test) # -grad_x E
print(f"Energy E(x): {energy:.4f}")
print(f"Score s(x): {score}")
# Sample 500 points from stationary Boltzmann distribution via SGLD
samples = ebm.sample_sgld(n_samples=500, n_steps=200, step_size=0.02, temp=0.35)
print(f"Generated samples shape: {samples.shape}")
Developed by Ramprasad Atluri (At1uri).
- Downloads last month
- 2
Space using At1uri/energy-based-langevin-mcmc-engine 1
Collection including At1uri/energy-based-langevin-mcmc-engine
Evaluation results
- Fisher Score Matching Loss on At1uri/energy-landscape-mcmc-benchmarksself-reported0.000
- Langevin MCMC Wasserstein-1 Error on At1uri/energy-landscape-mcmc-benchmarksself-reported0.038
- MALA Acceptance Rate on At1uri/energy-landscape-mcmc-benchmarksself-reported0.924