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.

KDE & Gaussian-mixture CDFs

Smooth, differentiable, invertible marginal transforms — and how to pick their one knob

01 — KDE & Gaussian-mixture CDFs

The empirical CDF of notebook 00 is consistent but jagged (a staircase, not differentiable) and tail-blind (nothing beyond the data). Both problems vanish if we estimate a smooth density and integrate it into a CDF. Two estimators dominate practice: a kernel density estimate (nonparametric) and a Gaussian mixture (parametric) — the latter is the marginal bijector at the heart of gauss_flows.

What you will see

1. KDE-based CDF

A kernel density estimate sums a smooth bump at each sample,

f^h(x)=1nh∑i=1nK ⁣(x−xih),F^h(x)=∫−∞xf^h ,\hat f_h(x) = \frac{1}{nh}\sum_{i=1}^n K\!\Big(\frac{x-x_i}{h}\Big), \qquad \hat F_h(x) = \int_{-\infty}^{x}\hat f_h\,,

and with a Gaussian kernel that integral is itself a sum of normal CDFs — so F^h\hat F_h is smooth and strictly increasing, exactly what the probability integral transform wants. rbig.KDEGaussianizer builds Φ−1(F^h(x))\Phi^{-1}(\hat F_h(x)).

KDE Gaussianize: output std = 0.940, round-trip err = 4.99e-13
<Figure size 1100x420 with 2 Axes>

The red KDE density traces both modes, and its CDF is the smooth curve the ECDF staircase was approximating. The Gaussianized output is unit-variance and round-trips cleanly — no tail blow-up, because the kernel tails extend past the data automatically.

2. The Gaussian-mixture CDF

The parametric workhorse fits a mixture of KK Gaussians and uses its CDF directly,

F(x)=∑k=1Kπk Φ ⁣(x−μkσk),z=Φ−1(F(x)).F(x) = \sum_{k=1}^{K}\pi_k\,\Phi\!\Big(\frac{x-\mu_k}{\sigma_k}\Big), \qquad z = \Phi^{-1}\big(F(x)\big).

The forward map is a closed-form, differentiable sum; the inverse is the monotone root-find of Part 0 notebook 02; and the log-det is log⁡f(x)−log⁡ϕ(z)\log f(x) - \log\phi(z). This is rbig.GMMGaussianizer and gauss_flows.MixtureGaussianCDF — the marginal layer every parametric Gaussianization flow stacks.

MixtureGaussianCDF: output std = 0.863, round-trip err = 8.93e-14, log-det finite = True
<Figure size 1200x360 with 3 Axes>

The two-component mixture nails the bimodal density, its CDF is smooth and monotone, and the Gaussianized output is a clean standard normal — round-tripping to ~10-14 (the tail-inverse fix from gauss_flows#108). Unlike the KDE, the mixture has only 3K3K parameters, is trivially differentiable in them, and extrapolates sensibly — which is why it is the parametric default.

3. Choosing the knob: bandwidth hh and components KK

Each estimator has one capacity knob, and it is the usual bias/variance trade-off.

KDE bandwidth hh. Too small and f^h\hat f_h is a spiky over-fit (high variance); too large and it smears the two modes into one (high bias). Plug-in rules like Scott’s / Silverman’s Silverman (1986) give a sane default.

BIC by K: {1: 24593, 2: 19821, 3: 19873, 4: 19906, 5: 19939, 6: 19961, 7: 19984}
<Figure size 1100x420 with 2 Axes>

Left: the bandwidth sweep — the spiky orange curve would inject phantom wiggles into the CDF (and noisy gradients), while the oversmoothed red one erases the valley between modes. Right: BIC (log-likelihood penalised by parameter count) bottoms out at K=2K=2, the true number of modes — adding components past that buys no likelihood worth the penalty. Cross-validated held-out likelihood tells the same story.

4. The Jacobian — a smooth log-determinant

To use a marginal in a flow we need its per-coordinate log-determinant, the gradient T′(x)=dz/dxT'(x)=\mathrm{d}z/\mathrm{d}x of z=Φ−1(F(x))z=\Phi^{-1}(F(x)):

dzdx=f(x)φ(z),log⁡∣T′(x)∣=log⁡f(x)−log⁡φ(z),f(x)=∑kπk N(x;μk,σk).\frac{\mathrm{d}z}{\mathrm{d}x} = \frac{f(x)}{\varphi(z)}, \qquad \log\big|T'(x)\big| = \log f(x) - \log\varphi(z), \qquad f(x) = \sum_k \pi_k\,\mathcal{N}(x;\mu_k,\sigma_k).

Unlike the histogram’s piecewise-constant ff (notebook 00), the mixture density is smooth, so the log-det is smooth and differentiable — what gradient training needs. gauss_flows.MixtureGaussianCDF.transform_and_log_det returns exactly this log⁡∣T′∣\log|T'|; we confirm it against an autodiff Jacobian.

log|T'| from transform_and_log_det vs autodiff: max|Δ| = 3.23e-15
<Figure size 1100x420 with 2 Axes>

The package log-det matches autodiff to machine precision, and both are smooth functions of xx — the low-density valley between the two modes is the central dip in log⁡∣T′∣\log|T'|, which then rises toward the tails as φ(z)→0\varphi(z)\to 0. This smooth, exact log-det is precisely the per-coordinate term a flow sums in log_prob.

Recap

estimatorCDFknobselector
KDEsum of kernel CDFs (smooth)bandwidth hhScott/Silverman, CV
Gaussian mixture∑kπkΦ\sum_k\pi_k\Phi (closed form)components KKBIC / held-out NLL
toolrole
rbig.KDEGaussianizernonparametric smooth marginal
rbig.GMMGaussianizer / gf.MixtureGaussianCDFparametric marginal bijector

Next up. Mixtures are smooth and compact but their inverse needs a root-find. 02 — Monotone-spline CDFs builds marginals from monotone splines — including the rational-quadratic spline with an exact analytic inverse, the bijector behind modern neural spline flows.

References
  1. Silverman, B. W. (1986). Density Estimation for Statistics and Data Analysis. Chapman.