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:

pθ(x)=1Zθ(T)exp⁡(−Eθ(x)T),Zθ(T)=∫Rdexp⁡(−Eθ(x)T)dxp_\theta(\mathbf{x}) = \frac{1}{Z_\theta(T)} \exp\left( -\frac{E_\theta(\mathbf{x})}{T} \right), \quad Z_\theta(T) = \int_{\mathbb{R}^d} \exp\left( -\frac{E_\theta(\mathbf{x})}{T} \right) d\mathbf{x}

1. Analytical Score Field Backpropagation

The score vector field $\mathbf{s}_\theta(\mathbf{x})$ is independent of the intractable normalizing partition constant $Z_\theta$:

sθ(x)=∇xlog⁡pθ(x)=−1T∇xEθ(x)\mathbf{s}_\theta(\mathbf{x}) = \nabla_{\mathbf{x}} \log p_\theta(\mathbf{x}) = -\frac{1}{T} \nabla_{\mathbf{x}} E_\theta(\mathbf{x})

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):

dxt=−∇xEθ(xt)dt+2TdWtd\mathbf{x}_t = -\nabla_{\mathbf{x}} E_\theta(\mathbf{x}_t) dt + \sqrt{2T} d\mathbf{W}_t

Discretized via Euler-Maruyama with step size $\epsilon$:

xt+1=xt−ϵ2∇xEθ(xt)+ϵTξt,ξt∼N(0,I)\mathbf{x}_{t+1} = \mathbf{x}_t - \frac{\epsilon}{2} \nabla_{\mathbf{x}} E_\theta(\mathbf{x}_t) + \sqrt{\epsilon T} \boldsymbol{\xi}_t, \quad \boldsymbol{\xi}_t \sim \mathcal{N}(0, \mathbf{I})


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
Safetensors
Model size
8.58k params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

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-benchmarks
    self-reported
    0.000
  • Langevin MCMC Wasserstein-1 Error on At1uri/energy-landscape-mcmc-benchmarks
    self-reported
    0.038
  • MALA Acceptance Rate on At1uri/energy-landscape-mcmc-benchmarks
    self-reported
    0.924