Skip to content

Neural spline flows: NeuralSplineCouplingFlow (rational-quadratic) - #52

Merged
davidkhjo merged 3 commits into
mainfrom
spline-flows
Aug 20, 2026
Merged

Neural spline flows: NeuralSplineCouplingFlow (rational-quadratic)#52
davidkhjo merged 3 commits into
mainfrom
spline-flows

Conversation

@davidkhjo

Copy link
Copy Markdown
Owner

nets.NeuralSplineCouplingFlow — a rational-quadratic neural spline flow (Durkan et al. 2019).

What

  • Monotonic rational-quadratic spline coupling layers dropped into the existing AffineCouplingFlow scaffold (same masks / transform / inverse / log_prob / sample / forward). Strictly more expressive per layer than affine, so it fits sharp, multi-modal 2D densities at a lower NLL for the same depth.
  • Same self-normalized contract: exact log p(x) = log N(f(x);0,I) + log|det| (no partition function), so forward(x) = -log_prob(x) is a valid EnergyFn with log Z = 0.
  • Slope-1 linear tails outside [-bound, bound], numerically stable inverse root 2c/(-b-√disc), zero-init conditioner head (≈identity at init). Defaults num_bins=8, bound=3, n_layers=6.

Validation (closed-form / distributional)

  • Exact invertibility including the linear tails, and analytic log|det| == autograd Jacobian to 1e-8 (double precision — the RQ map is exactly invertible; float32 loses a few digits per layer as all spline flows do).
  • Fits a Gaussian (log-density vs analytic) and the two-moons manifold (MMD, both crescents).

Notes

  • The spline only reshapes mass inside bound (identity tails) — scale data to fit, or widen bound. Documented on the class and in the example.
  • Exposed as ebm.nets.NeuralSplineCouplingFlow (alongside AffineCouplingFlow). torch-only; public API preserved; accumulates under the unreleased 0.15.0.

🤖 Generated with Claude Code

davidkhjo and others added 3 commits August 20, 2026 16:50
A monotonic rational-quadratic spline coupling (Durkan et al. 2019) dropped into
the affine-flow scaffold: strictly more expressive per layer while keeping the
same self-normalized contract (exact log_prob, one-pass sampling,
forward = -log_prob). Slope-1 linear tails outside [-bound, bound], numerically
stable inverse root, zero-init conditioner head for a near-identity start.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Double-precision checks pin the math: exact roundtrip including the linear tails
and analytic log|det| vs the autograd Jacobian to 1e-8. Float32 distributional
fits: recovers a Gaussian's log-density (vs analytic) and the two-moons manifold
(MMD, both crescents covered), plus practical float32 invertibility.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Trains an affine and a spline flow on two-moons at equal depth and prints both
held-out NLLs (spline wins). README energies row + examples list and the
unreleased CHANGELOG updated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@davidkhjo
davidkhjo merged commit ffbe6c1 into main Aug 20, 2026
5 checks passed
@davidkhjo davidkhjo mentioned this pull request Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant