ContentsChapter 2 · Probability5 of 6

2.5

Change of variables

In this chapter
  1. 2.1Conditional probability and Bayes' rule
  2. 2.2Random variables
  3. 2.3Expectation, variance, covariance
  4. 2.4Bernoulli, binomial and Gaussian
  5. 2.5Change of variables
  6. 2.6Entropy and cross-entropy
Before you readX is uniform between 0 and 1. Is X2X^2 uniform too?
Watch: The determinant · 3Blue1Brown · Essence of Linear Algebra, ch. 6: the stretch factor below is the determinant in one dimension

Let Y=g(X)Y = g(X) for a smooth function g that only goes up or only goes down. Probability is conserved: the mass in a small interval dxdx around x moves to an interval dydy around y. So pY(y) ∣dy∣=pX(x) ∣dx∣p_Y(y)\,|dy| = p_X(x)\,|dx| which gives

pY(y)=pX(g−1(y))∣ddyg−1(y)∣.p_Y(y) = p_X\big(g^{-1}(y)\big) \left| \frac{d}{dy} g^{-1}(y) \right|.

Where g squashes values together, the density piles up; where it stretches them, the density thins out. For Y=X2Y = X^2 with X uniform, g−1(y)=yg^{-1}(y) = \sqrt y so pY(y)=12yp_Y(y) = \frac{1}{2\sqrt y} That is not uniform, which answers the question above.

A linear map Y=aX+bY = aX + b gives pY(y)=1∣a∣pX ⁣(y−ba)p_Y(y) = \frac{1}{|a|} p_X\!\left(\frac{y - b}{a}\right) That is why a shifted and scaled Gaussian is still Gaussian, and why z=(x−μ)/σz = (x - \mu)/\sigma is standard normal.

For vectors, y=g(x)y = g(x) the derivative becomes the Jacobian matrix JJ of g−1g^{-1} and the stretch factor becomes ∣det⁡J∣|\det J| the area scaling from Linear algebra. Machine learning uses this to sample from a model by transforming simple noise, as in variational autoencoders and normalising flows.

1234500.250.50.751
p_Y(0.5) = 0.71
X is uniform on [0, 1]: the dashed line at height 1. The bars are 4,000 evenly spread values of X, pushed through Y = Xᵏ. For k above 1 the map squashes values near 0 together, so they pile up there; the curve from the change-of-variables formula predicts the pile exactly.
Recall
Give the density of Y=g(X)Y = g(X) for a monotone gg
Recall
Why does the change-of-variables formula have a derivative in it?
Recall
What is the density of Y=aX+bY = aX + b
Exercise
X is uniform on [0,1][0, 1] and Y=X2Y = X^2 Find pY(0.04)p_Y(0.04)
Exercise
X is uniform on [0,1][0, 1] and Y=3X+1Y = 3X + 1 What is pY(y)p_Y(y) for 1≤y≤41 \le y \le 4
Exercise
X has density pX(x)=2xp_X(x) = 2x on [0,1][0, 1] and Y=X2Y = X^2 Find pY(0.5)p_Y(0.5)