# The central limit theorem in terms of convolutions

There are multiple versions of the central limit theorem. One common version says that, as ${n \to \infty}$, the mean of means looks like a Gaussian distribution. People in industry sometimes ignore the "goes to infinity" part, and assume that if $n$ is large, that's good enough. But is that true? When is it safe to assume that your means have converged? I heard of a case recently where the mean of means was assumed to have converged, hadn't, and the application it was a part of suffered accuracy problems for months without anyone knowing. This sequence will explore: under what conditions does the central limit theorem "fail" like this?

The central limit theorem is about convolutions
===============================================

There are multiple versions of the central limit theorem. They're all a version of the statement:

> If you have a bunch of distributions $f_i$ (say, $n$ of them), and you convolve them all together into a distribution $F^* := f_1 * f_2 * f_3... * f_n$, then the larger $n$ is, the more $F^*$  will resemble a Gaussian distribution.

The simplest version of the central limit theorem requires that the distributions $f_i$ must be 1) independent and 2) identically distributed. In this sequence, I'm gonna assume #1 is true. We'll find that while condition #2 is nice to have, even without it, distributions can converge to a Gaussian under convolution.

A Gaussian distribution is the same thing as a Normal distribution. Some examples of Gaussian distributions:

![Normal Distribution PDF.svg](https://upload.wikimedia.org/wikipedia/commons/thumb/7/74/Normal_Distribution_PDF.svg/1920px-Normal_Distribution_PDF.svg.png)

[Wikipedia](https://en.wikipedia.org/wiki/Normal_distribution)

Wait - this doesn't sound like the central limit theorem I know
---------------------------------------------------------------

Most statements of the central limit theorem, including Wikipedia's, talk in terms of the sums of random variables (and their density functions and expected values). But this is the same thing as our convolution-of-distributions, because [the density function of the sum of two random variables X, Y *is*](http://statweb.stanford.edu/~susan/courses/s116/node114.html) [the convolution of the density functions of X and Y](https://en.wikipedia.org/wiki/List_of_convolutions_of_probability_distributions). Looking at the central limit theorem in terms of convolutions will make it easier to see some things. It's also useful if your version of probability doesn't have the concept of a random variable, like [probability theory as extended logic](https://www.amazon.com/Probability-Theory-Science-T-Jaynes/dp/0521592712)*. 

Another statement of the central limit theorem, from [Jaynes](https://www.amazon.com/Probability-Theory-Science-T-Jaynes/dp/0521592712):

> The central limit theorem tells us what is essentially a simple combinatorial fact, that out of all conceivable error vectors ${e_1,..., e_n}$ that could be generated, the overwhelming majority have about the same degree of cancellation.

Hopefully this is enough to convince you that the central limit theorem need not be stated in terms of random variables or samples from a population.

(Also: the central limit theorems are sometimes talked about in terms of means only.  They do say things about means, but they also say very much about distributions. I'll talk  about both.)

*: *first three chapters* [*here*](https://bayes.wustl.edu/etj/prob/book.pdf)*.*

Convolutions
============

The central limit theorem is a statement about the result of a sequence of convolutions. So to understand the central limit theorem, it's really important to know what convolutions are and to develop a good intuition for them. 

Take two functions, $f$ and $g$. Reverse $g$ on the y-axis, then slide it and $f$ along each other, taking the product of each pair of numbers as you slide. The result is the convolution of $f$and $g$. Here's a picture - $f$ is blue, $g$ is red, and the convolution $f * g$ is black:

![Convolution of box signal with itself2.gif](https://upload.wikimedia.org/wikipedia/commons/6/6a/Convolution_of_box_signal_with_itself2.gif)

[Wikipedia](https://en.wikipedia.org/wiki/Convolution)

Another one, with a different function $f$:

![Convolution of spiky function with box2.gif](https://upload.wikimedia.org/wikipedia/commons/b/b9/Convolution_of_spiky_function_with_box2.gif)

You can write this as $f * g = (f * g)(x) = \int_{-\infty}^\infty f(y)g(x - y)dy$.  

The first two sections on [this page](https://colah.github.io/posts/2014-07-Understanding-Convolutions/) give a nice explanation of convolutions in terms of dropping a ball twice. [This page](https://lpsa.swarthmore.edu/Convolution/CI.html) lets you choose two functions to convolve visually, and I highly recommend it for getting a feel for the operation.

Convolution has nice properties
-------------------------------

Convolution is associative and commutative - if you want to convolve multiple functions together, it doesn't matter what order you do it in. (Also, nothing I've said in this section requires $f$ and $g$ to be probability distributions - they can be any two functions.) 

You can get the mean of a convolution without actually doing the convolutions. If the first moments of $f$ and g are $F_1$ and $G_1$  (for probability distributions, the first moment is the mean), then the first moment of $f * g$ is $F_1 + G_1$. There is a hint here about why people often talk about means when they talk about the central limit theorem - being able to get the mean of the convolution by just adding the means of the underlying distributions together is really nice.

You can get the second moment without actually convolving, too. (the second moment is closely related to the variance: if the mean is 0, the second moment and the variance are the same). For $f$ and $g$ with second moments $F_2$, $G_2$, the second moment of $f * g$ is $F_2 + 2F_1G_1 + G_2$. And so on for higher moments, for as long as $f$ and $g$ actually have those higher moments themselves.

If $\mathscr{F}\{f\}$ and $\mathscr{F}\{g\}$ are the Fourier transforms of $f$ and $g$, [then](https://en.wikipedia.org/wiki/Convolution_theorem) $\mathscr{F}\{f * g\} = \mathscr{F}\{f\}\mathscr{F}\{g\}$. This is very useful for computing convolutions numerically: evaluating $\int_{-\infty}^\infty f(y)g(x - y)dy$ naively would require doing an integral for every single $x$ value you were interested in. That's expensive, time-wise. Much easier to compute $\mathscr{F}\{f\}$ and $\mathscr{F}\{g\}$ and then just multiply them (multiplication is cheap). After that, applying the inverse Fourier transform gives $f * g$. This is how convolution is computed in popular [numerical](https://stat.ethz.ch/R-manual/R-patched/library/stats/html/convolve.html) [programming](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.fftconvolve.html#scipy.signal.fftconvolve) languages. 

If $f$ sums to 1 and $g$ sums to 1, then $f * g$ sums to 1. So if $f$ and $g$ are probability distributions, so is $f * g$.

In the next post, I'll look at what happens when you convolve a bunch of different distributions together, and explore how much of what happens depends on the form of those distributions.

* * *

*Post script: not neural networks*

You may have heard of convolutional neural networks from all their success in image processing. I think they involve the same convolution I'm talking about here, but in much higher dimensions. I'll only be talking about convolutions of one-dimensional functions in this sequence. Some (or a lot?) of the stuff I'll say about the central limit theorem probably applies in higher dimensions too, but I'm not sure what changes as the dimension increases. So, this sequence is not about the neural networks.