Today is a good day I think to talk about the Johnson-Lindenstrauss dimension reduction lemma!

The setting is as follows. Suppose you have a large number points, living in the Euclidean space of dimension . We’ll call these points , and think of both the number of points and the number of dimensions as being very large, much larger than the measly “3” of our easy-to-grasp physical world.

Now, you may wonder, “But we **do** live in a three dimensional world thank you very much, so where would I obtain such high dimensional data?” Well, these situations arise increasingly more often in computer science applications, where a point in -dimensional space may represent an abstraction of some actual real-world thing.

For example, imagine this not-too-farfetched biology experiment. A biologist wants to understand how a particular gene works in a bacterium, and she does this using the following procedure: first, she makes small changes in the DNA sections that code up the protein. Then she replaces the original gene in the bacterium by the new modified one. Finally, she measures the concentration of about 1000 different proteins in the bacterium. If the original gene was important, or if it was a key ingredient in a large protein pathway, then many of these concentrations will be different under the modified gene when compared to the unchanged gene.

Our biologist repeats this experiment many many times, each time changing a different part of the gene in a different way. Ultimately, she has performed say about 500 experiments. Each experiment results in a vector of 1000 numbers, one for each protein. She now has 500 points living in a 1000-dimensional space*. Our poor biologist must now analyze these points, and from them understand the way in which the original gene affects the proteins and operates within the cell. She will run many statistical and geometrical algorithms on these data, and these algorithms will usually have the downside that they really, really slow down as a function of dimension. What can she do?

* Actually, since a set of points always spans a space of dimension no larger than , these points only live in a 500-dimensional space. But that’s besides the point here, as we will see next.

Ok, back to mathematics. The Johnson-Lindenstrauss lemma roughly says the following. Suppose you have these points living in . You can actually put them into a very small space – logarithmic in – in such a way that the distances between the points are almost preserved: If two points were originally far away from each other, they’ll remain far away from each other, and if two points were close, they’ll remain close. More formally,

**Lemma**: Let and let be points in . Then there is a function such that for every two points and ,

with

This lemma is good if you want to run geometric algorithms on your data. For example, in our biologist’s case, she might decide that if two modifications to the gene resulted in protein densities that are more or less the same (that is, two points in that are close to each other), then the modifications changed the gene in functionally the same manner. She might then decide to look for clusters of points which are close to each other. This is usually easier to do in smaller dimensional spaces. Applying a Johnson-Lindenstrauss transformation allows our biologist to run the algorithms faster and on more data, while (hopefully) not losing much accuracy.

Of course, this is useful only if the the new dimension is much smaller than the original dimension . This often happens in applications; for example, in a future post, we will work with points in dimensions, and the transition from a space of dimension to space of dimension will be quite substantial.

The proof we will present here follows a paper by Dasgupta and Gupta, which uses random projections. We’ll first illustrate this concept in two dimensions.

Suppose you have a set of points in the plane:

A one-dimensional subspace of the plane is just a line that goes through the origin. Once we have such a line, we can perform an orthogonal projection of the original points onto that line, giving us a new set of points, all on the line:

If we choose a different line, we get a different projection:

For some lines, the projection will totally wreck the distances between the original points; for example, in this image, we sent two different original points to the same point:

However, for other lines, it may be that the projection is able to preserve the ratio of distances fairly accurately.

The proof the Johnson-Lindenstrauss lemma uses the same idea, only in higher dimensions. Instead of points in the plane, we have our original -dimensional space; and instead of projecting to a line, we try to find a subspace of dimension so that projecting on to it will almost preserve distances. [Actually, we project the points and then blow them up by a constant factor, since orthogonal projections can only decrease the length of vectors; but this doesn’t change the gist of the argument. From now on when we say “distance preserving”, we’ll mean actually mean “up to a constant factor”. See the actual calculations for exact treatment].

A-priori, there is no grounds to think that such a subspace exists. However, it turns out that it indeed does, for a reason called “the concentration of measure in high dimensions” Roughly, it says that in high dimensions, some random processes – such as the orthogonal projection of a point onto a random subspace, or the scalar product of a unit vector with a Gaussian vector – are heavily concentrated around their expected value. The probability for such processes to be even a tiny bit away from their mean is exponentially small in the dimension. We usually don’t see these phenomena in 3d, because the lowly and pathetic exponent of 3 isn’t enough to give a profound effect, but in higher dimensions they flourish.

After all of this verbosity, here is the proof outline: for any , we can choose a random dimensional subspace of and project our points on to it. Choose two particular points and from our original cast in . It may either be that the distance between them is preserved up to a factor of , or it may not be preserved; denote the probability that it is not preserved is some number . We can consider this “distance distortion” event for all of the pairs of points, and by the union bound, the probability for **at least one pair** of points to have their distance distorted is less than . If we can show that the probability is smaller than , then the probability that at least one distance is distorted is smaller than 1. This means there is a non-zero probability that all the distances are preserved! But then there **has** to exist a distance-preserving projection; otherwise it would be impossible for this probability to be greater than 0. And as it turns out, we can indeed make the probability that a single distance is preserved be this small, by choosing .

Actually, this proof not only shows that there exists such a transformation, it even tells you how to efficiently get one: the probability that a random projection gives a distance-preserving dimension reduction is actually quite high (and can be made very close to one if we just increase the number of dimensions by a bit). So you just need to take your points, project them randomly, and check that the distances are preserved; if not repeat, and sooner rather than later you are bound to get something that works.

Ok, let’s take a look the technical details. All we have to show is that with high probability, the length of a vector is nearly preserved when we project it to a random dimensional subspace. Now, when performing the calculations, instead of taking a fixed vector and a random subspace, we can take a fixed subspace and a random vector; all the results will be the same, since all we care about when projecting is the relative orientation between the vector and the subspace.

So let’s take a random unit vector, and see what happens to its length. A uniformly random unit vector can be obtained by taking a random distribution which is spherically symmetric and normalizing it. Specifically, let be independent Gaussian random variables with mean 0 and variance 1; in other words, the random vector distributes as a dimensional Gaussian vector . Then the vector

is a uniformly random unit vector. As for our fixed subspace, we’ll just take the space spanned by the first coordinates, and denote the projection by . What is the expected value of the square of the length of ? Well, we know that the squared length of is 1; this is by design: we normalized it. We thus have:

If this is true for , then it is also true for its expectation:

Notice that the sum is symmetric in the ‘s: in expectation, there is no reason for one to behave differently from the other. Thus each term should contribute equally to the sum, and so for every ,

Since is just the first terms of , we get

Oops, the expected value is , which is smaller than 1, the original norm of the vector! But not to worry, this can easily be fixed: after we project to a random subspace of dimension , we just blow up all the points by a factor of . That way, when we look at the norm squared, the expectation will be times larger, and the expectation will indeed by 1. This multiplication will not affect any of our probabilistic statements, since if is concentrated around its mean, so is .

Now to fulfil our promise and show that the squared length of is heavily concentrated around its mean. The calculations will be a bit lengthy, but do not despair (also, if you got up to here and understood everything, you are pretty much good-to-go for most of your Johnson-Lindenstrauss-ing needs).

We’ll show that for any positive real number smaller than 1, the probability for to be times smaller than its mean of is exponentially small in the dimension and in ; we’ll then take to show that the probability for a small deformation is small. The same calculations can also be repeated for checking when is greater than for , and then taking .

A standard method for showing such concentration of measure is using Markov’s inequality, which states that if is a positive random variable, then for every ,

Intuitively, all this inequality says is that if the expectation is small, then it’s impossible to have too large a probability of getting too large a value. Markov’s inequality is innocuous enough, but it becomes powerful when we combine it with exponential moments, that is, when we apply to instead of to itself. Let’s see how that works.

When written explicitly, becomes

So the probability can be written as

Here was some number greater than 0, and we will optimize over it soon in order to get the best possible bounds. Now we invoke Markov’s inequality with , getting

The various ‘s are independent, so the expectation of the product is the product of expectations:

and after grouping together the in our exponent, our probability is bounded by

This last equality we won’t go into, but it stems from knowledge about the moment generating function of Gaussians; in short, all that needs to be proven is that for .

All that is left is to minimize this last expression. This we also won't do here, because it mainly involves annoying calculus which you can let WolframAlpha do for you. This finally gives:

The expression on the right hand side is equal to to the power of its logarithm:

Finally, since for all , we can replace the second factor by , giving

Now we just need to clean up. Put , and get

By more calculus it can be shown that for , and at last we have

And indeed, if we choose , this exponent will be smaller than , just as we wanted (actually, we can choose just , but to deal with the second case of we will also need the term). A similar calculation for will give another factor of , and in total the probability of having a large distortion will be just per pair of points.

Cool! Enjoyed it a lot.