## 13.5 Transforming between Distributions

In describing the inversion method, we introduced a technique that generates samples according to some distribution by transforming canonical uniform random variables in a particular manner. Here, we will investigate the more general question of which distribution results when we transform samples from an arbitrary distribution to some other distribution with a function .

Suppose we are given random variables that are already drawn from some PDF . Now, if we compute , we would like to find the distribution of the new random variable . This may seem like an esoteric problem, but we will see that understanding this kind of transformation is critical for drawing samples from multidimensional distribution functions.

The function must be a one-to-one transformation; if multiple values of mapped to the same value, then it would be impossible to unambiguously describe the probability density of a particular value. A direct consequence of being one-to-one is that its derivative must either be strictly greater than 0 or strictly less than 0, which implies that

and therefore

This relationship between CDFs leads directly to the relationship between their PDFs. If we assume that ’s derivative is greater than 0, differentiating gives

and so

In general, ’s derivative is either strictly positive or strictly negative, and the relationship between the densities is

How can we use this formula? Suppose that over the domain , and let . What is the PDF of the random variable ? Because we know that ,

This procedure may seem backward—usually we have some PDF that we want to sample from, not a given transformation. For example, we might have drawn from some and would like to compute from some distribution . What transformation should we use? All we need is for the CDFs to be equal, or , which immediately gives the transformation

This is a generalization of the inversion method, since if were uniformly distributed over then , and we have the same procedure as was introduced previously.

### 13.5.1 Transformation in Multiple Dimensions

In the general -dimensional case, a similar derivation gives the analogous relationship between different densities. We will not show the derivation here; it follows the same form as the 1D case. Suppose we have an -dimensional random variable with density function . Now let , where is a bijection. In this case, the densities are related by

where is the absolute value of the determinant of ’s Jacobian matrix, which is

where are defined by .

Suppose we draw samples from some density . What is the corresponding density ? The Jacobian of this transformation is

and the determinant is . So . Of course, this is backward from what we usually want—typically we start with a sampling strategy in Cartesian coordinates and want to transform it to one in polar coordinates. In that case, we would have

the Jacobian of this transformation has determinant , so the corresponding density function is

This transformation is important since it helps us represent directions as points on the unit sphere. Remember that solid angle is defined as the area of a set of points on the unit sphere. In spherical coordinates, we previously derived

So if we have a density function defined over a solid angle , this means that

The density with respect to and can therefore be derived: