Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Monotone-spline CDFs

Monotone cubic CDFs, and the rational-quadratic spline with an exact analytic inverse

02 — Monotone-spline CDFs

The mixture CDF of notebook 01 is smooth and compact, but its inverse needs a root-find. Splines keep the smoothness and compactness while buying something better: a parameterisation that is monotone by construction and — for the right spline — invertible in closed form. That is why splines are the marginal (and coupling) bijector of choice in modern flows.

What you will see

1. Monotonicity is the whole game

A CDF is non-decreasing, so any spline we use as a CDF must be monotone — otherwise FF is not a valid CDF, Φ−1(F(x))\Phi^{-1}(F(x)) is multivalued, and the transform is not invertible. Ordinary (natural) cubic splines do not respect monotonicity: between knots they can overshoot, dipping below the data or rising above it. Monotone cubic Hermite interpolation (Fritsch–Carlson Fritsch & Carlson (1980), a.k.a. PCHIP) limits the knot slopes so the interpolant stays monotone. Watch both interpolate the same monotone CDF knots.

natural cubic: min=-0.0049, max=1.0049  (leaves [0,1] -> invalid CDF)
PCHIP:         min=0.0000, max=1.0000, monotone=True
<Figure size 750x440 with 1 Axes>

The red natural cubic dips below 0 and pokes above 1 (shaded zones) — it is not a CDF. The green PCHIP curve honours the same knots while staying inside [0,1][0,1] and monotone. A monotone-spline CDF Gaussianizer (e.g. rbig.SplineGaussianizer, which fits a quantile spline) is built on exactly this guarantee:

rbig.SplineGaussianizer on gamma data: output std = 1.011, round-trip err = 3.33e-02

2. The rational-quadratic spline (RQS)

The monotone cubic is invertible, but only by root-find (it is a cubic). The rational-quadratic spline Durkan et al. (2019) is the modern alternative: on each bin it is a ratio of quadratics,

F(x)=α ξ2+β ξ+γa ξ2+b ξ+c,ξ=x−xkxk+1−xk,F(x) = \frac{\alpha\,\xi^2 + \beta\,\xi + \gamma}{a\,\xi^2 + b\,\xi + c}, \qquad \xi = \frac{x - x_k}{x_{k+1}-x_k},

which is (i) monotone by construction for positive knot derivatives, (ii) invertible in closed form — inverting it solves one quadratic per bin, no iteration — and (iii) has an analytic log-det. Outside the spline interval it falls back to identity (linear) tails. This is gauss_flows.RQSplineMarginal, the bijector behind neural spline flows.

RQS exact-inverse round-trip: max err = 1.33e-15 (closed form, no iteration)
monotone forward: True
<Figure size 1100x420 with 2 Axes>

The forward map is a smooth monotone S inside the interval and identity in the tails; the inverse round-trips at machine precision in one shot. Contrast the mixture-CDF of notebook 01, which reaches the same accuracy only after ~40 bisection steps — the RQS trades a slightly more complex forward for a free, exact inverse. That asymmetry is why spline flows are the default when you need fast sampling and fast density.

3. The Jacobian — an analytic log-determinant

A flow needs each layer’s log-determinant log⁡∣T′(x)∣\log|T'(x)| (Part 0 00). The RQS’s third virtue — after monotonicity and the exact inverse — is that this gradient is analytic: on each bin TT is a ratio of quadratics, so T′(x)T'(x) is a closed-form rational expression and log⁡∣T′∣=∑binslog⁡T′\log|T'| = \sum_{\text{bins}} \log T' needs no autodiff and no quadrature. (For the monotone-cubic CDF the same role is played by the spline’s slope, dz/dx=F′(x)/φ(z)\mathrm{d}z/\mathrm{d}x = F'(x)/\varphi(z).) We plot the RQS Jacobian and confirm transform_and_log_det matches an autodiff Jacobian.

analytic log|T'| vs autodiff: max|Δ| = 1.17e-15
<Figure size 750x420 with 1 Axes>

The derivative is a smooth, strictly-positive curve inside the spline interval (the rational-quadratic segments join C1C^1 at the knots) and flattens to slope 1 in the identity tails; transform_and_log_det reproduces it to machine precision. An exact inverse and an exact log-det, both in closed form, is what makes the RQS the workhorse coupling/marginal bijector of modern flows.

Recap

splinemonotone?inverselog-dettool
natural cubic✗ (overshoots)——(don’t use as CDF)
monotone cubic (PCHIP)✓root-findnumericrbig.SplineGaussianizer
rational-quadratic (RQS)✓ by constructionclosed formanalyticgf.RQSplineMarginal

Next up. So far we have fit marginals by quantiles or EM. 03 — Mixture-CDF as a learnable bijector trains the mixture-CDF parameters end-to-end by maximum likelihood, and differentiates through its root-find inverse with the implicit-function trick from Part 0.

References
  1. Fritsch, F. N., & Carlson, R. E. (1980). Monotone Piecewise Cubic Interpolation. SIAM Journal on Numerical Analysis, 17(2), 238–246. 10.1137/0717021
  2. Durkan, C., Bekasov, A., Murray, I., & Papamakarios, G. (2019). Neural Spline Flows. Advances in Neural Information Processing Systems (NeurIPS).