If x = g(y), probability in a thin interval is conserved, so py(y) = px(g(y)) |g′(y)|. The extra factor is what separates a density from an ordinary function: plug g(y) into px without it and the curve no longer matches a histogram of transformed samples, and the maximum of the true density sits somewhere else. In several dimensions the factor becomes |det J|, the local ratio of volumes, which is the quantity normalizing flows (Chapter 18) are built around.
Click or tap the left panel to move the yellow probe square.
code/ch02_probabilities.py (functions ms_py, ms_modes, t2d, t2d_jac, t2d_inv, t2d_density).