Deconstructing Normalizing Flows from Scratch
Explore the mathematics of invertible transformations, exact likelihood, and density estimation — built entirely from scratch in pure PyTorch.
Part 1
The Math of Invertible Transforms
Breaking down the change of variables formula, Jacobian determinants, planar flows, and affine coupling layers.
Part 2
PyTorch Implementation
Building Planar Flows, Affine Coupling Layers, and RealNVP with alternating masks — entirely from scratch.
View Code on GitHub
Part 3
Exact Likelihood Generation
2D density estimation on Two Moons and Two Circles, with RealNVP achieving 54% lower NLL than Planar Flow.