RealNVP Triangular Density Coupling
An invertible triangular warp makes a flexible density while keeping its inverse and volume correction explicit.
By Riano · Published · Updated · Report a correction
RealNVP Triangular Density Coupling
In RealNVP, an affine coupling layer partitions dimensions to keep the Jacobian determinant triangular, ensuring fast, analytical inversion and exact density evaluation while allowing expressive scale and shift warps driven by arbitrary neural functions.
Worked Example
Consider a 2D standard normal base distribution, with an affine coupling that maps latent variable z to observed variable x. Suppose we observe x_1 = 1 and x_2 = 0, with a scale slope s = 1 and a shift slope t = 1. We want to find the corresponding latent z and the exact density evaluated at x.
x1 = 1.0, x2 = 0.0 s = 1.0, t = 1.0 Inverse Mapping: z1 = x1 = 1.0 z2 = (x2 - t * x1) * exp(-s * x1) z2 = (0.0 - 1.0 * 1.0) * exp(-1.0 * 1.0) z2 = -1.0 * exp(-1.0) = -0.36787944117144233 Density Computation: forward log Jacobian determinant = s * z1 = 1.0 * 1.0 = 1.0 log p(Z) = -log(2*pi) - 0.5 * (z1^2 + z2^2) = -1.8378770664093453 - 0.5 * (1.0 + 0.135335) = -2.4055447080276515 log p(X) = log p(Z) - forward log Jacobian determinant = -2.4055447080276515 - 1.0 = -3.4055447080276515 p(X) = exp(-3.4055447080276515) = 0.033188736985970184Experiment
In the interactive module, you can alter the observed values for x_1 and x_2 as well as the geometric warp parameters s and t. The interactive view visualizes how a regular grid in the latent standard normal space transforms into the warped grid of the observed space.
- Select Observed x1 and Observed x2 to set the target point.
- Modify the Scale slope and Shift slope controls to see how shear (s=0, t ≠ 0) preserves density volume (0 log-determinant) but warps geometry, whereas a non-zero Scale slope fundamentally stretches or squashes the area element.
- Observe the recomputed Observed density and Latent coordinates in the results pane.
Limitations
This module isolates a single 2D affine coupling layer using linear scale and shift parameters to build intuition for the exact volume correction. In practice, RealNVP stacks multiple such coupling layers—each alternating the partitioned identity dimensions—and uses deep neural networks (which need not be invertible themselves) to compute s and t. This model does not demonstrate neural training, cascading compositions, or high-dimensional alternating checkerboard/channel masks.
References
The primary reference for this density coupling mechanism is:
- Dinh, L., Sohl-Dickstein, J., & Bengio, S. (2016). Density estimation using Real NVP.arXiv:1605.08803
Experience it interactively
Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive RealNVP Triangular Density Coupling module.
Try RealNVP Triangular Density Coupling on Riano →