So far, we have been looking at integrating functions of a single variable. We will now look at how integration works for multivariate functions.
Let's say we have the following function:
This is an instance of a 2-dimensional Gaussian curve and we will see this function again in future modules. For now, assume that integrating this function over a given interval provides us with valuable information on how likely values in these interval are.
Let's say that we want to integrate this function for and . We would write the integral as follows:
In this particular case, the integral above can be computed by first integrating with respect to and then with respect to :
The outer integral is concerned with the variable while the inner integral is concerned with the variable . Again in this case, this is equivalent to integrating first with respect to (inner integral) and then to (outer integral):
This is called iterated integration. We have included the parenthesis to make it clear that we are dealing with the computation of the inner integral followed by the computation of an outer integral. However, the parentheses are usually ommited to avoid clutter, so we can usually write
For most functions we're likely to encounter, the order in which we perform multiple integrations does not matter. However, that is not always the case: Fubini's theorem sets out the conditions under which the order of integration is irrelevant. We won't cover this here since it is rather unlikely you will encounter a function that violates Fubini's conditions in ML/AI.
Just like for univariate integration, multivariate integration follows the rules of linearity. For instance, for a 2-dimensional integration:
Integration by parts and the change of variables technique can also be applied in multiple dimensions. The next example demonstrates the latter in action.
Let's try to integrate the function we were working with above:
We start by applying the change of variables technique using a polar coordinate transformation where
Quick note: if you are wondering why , think about what is necessary to define an infinitesimal area in 2-d cartesian coordinates vs in polar coordinates. In 2-d cartesian coordinates, an infinitesimal area can be defined solely by and . However, in polar coordinates, and are not sufficient to express an infinitesimal area. For instance, consider a region defined by and another region defined by . Even though for both regions, their areas are quite different.
Coming back to our integral, we can now write
Let's break down what we have done above:
Applying Fubini's theorem, we can convert the double integral into an iterated integral, yielding
The integral with respect to is trivial and evaluates to , allowing us to write:
If we move the factor 2 into the integral, you'll notice we can apply the change of variables rule. Here, we assume that , and thus . We also assume that and thus its primitive is . By the change of variables rule, we can thus write:
We will see this integral later in the probability course, when we cover the normal distribution.
Just like with univariate integration, we can use Riemann sums to approximate the multiple integrals. Let's approximate the integral above over an increasingly larger integration interval—if we are correct, we should that the approximation tends to as we increase the integration interval.
Note that the Riemann sum scales the values of by , since we are now dealing with an area. As expected, our approximation gets progressively closer to as we increase the range over which we are approximating the integral.
In summary, in this section we introduced multiple integrals by covering a 2-dimensinal example. We also saw how 2-dimensional integrals can be approximated by Riemann sums.
It is of course possible to integrate in higher-dimensional spaces, but this naturally becomes trickier. Luckily, having a basic understanding of integrals in 1 and 2 dimensions is all we need to understand the next modules, so we won't go into complex integration topics here.