Neural spline flows: NeuralSplineCouplingFlow (rational-quadratic) - #52
Merged
Conversation
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>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
nets.NeuralSplineCouplingFlow— a rational-quadratic neural spline flow (Durkan et al. 2019).What
AffineCouplingFlowscaffold (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.log p(x) = log N(f(x);0,I) + log|det|(no partition function), soforward(x) = -log_prob(x)is a validEnergyFnwithlog Z = 0.[-bound, bound], numerically stable inverse root2c/(-b-√disc), zero-init conditioner head (≈identity at init). Defaultsnum_bins=8, bound=3, n_layers=6.Validation (closed-form / distributional)
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).Notes
bound(identity tails) — scale data to fit, or widenbound. Documented on the class and in the example.ebm.nets.NeuralSplineCouplingFlow(alongsideAffineCouplingFlow). torch-only; public API preserved; accumulates under the unreleased 0.15.0.🤖 Generated with Claude Code