Why ratios want geometric means
2020-08-28 · view article source
You may have heard that when taking the average of a set of ratios, it’s best to use the geometric mean instead of the normal arithmetic mean. For years, I took this as received wisdom, but recently I decided to think about it more carefully. It makes sense to me now—here’s my thought process.
Suppose that you have two computer programs, Program A and Program B. You want to compare how fast the two programs run on a variety of test cases. You time them, and observe the following results:
- Trial 1: Program A is 2× faster.
- Trial 2: Program A is 4× faster.
- Trial 3: Program A is 0.2× as fast.
Call these ratios , , and . Program A is faster than Program B on trial if . We can see that Program A is sometimes faster, but Program B is sometimes faster, too. Which program is faster “on average”?
With a simple arithmetic mean, we could compute:
So, “on average”, it looks like Program A is times faster.
But something’s not quite right here. Suppose that we had looked at the exact same timing data from the perspective of Program B instead. We would have observed these results:
- Trial 1: Program B is 0.5× as fast.
- Trial 2: Program B is 0.25× as fast.
- Trial 3: Program B is 5× faster.
That is, we have , , and , where each . Taking an arithmetic mean again, we find:
But then we are forced to conclude that, “on average”, Program A is times faster than Program B, and Program B is also times faster than Program A! Surely any framework that leads us to such a conclusion must be flawed. An arithmetic mean must not be the right tool: let’s return to the drawing board.
Consider for a moment what the arithmetic mean means. It says, “combine your three quantities by adding them together, then scale them down by a factor of three to counteract the change in magnitude”. It we have three quantities of distance, or of mass, or of time, this makes sense. If you travel meters and then travel meters, you’ve traveled meters.
But that’s not how ratios compose. If you make a program times faster, and then make it times faster again, you haven’t made it times faster—you’ve made it times faster. Thus, to take an average in the same spirit as the arithmetic mean, we should combine our three ratios by multiplying them together, and then scale them down by a third root to counteract the change in magnitude. And this is precisely the geometric mean.
Returning to our speed comparison example, we can reëvaluate how much faster Program A is “on average”…
…and Program B:
Now our results are consistent: Program A is faster, and Program B is slower. Moreover, note that , which makes sense. This is another property that carries over in spirit from arithmetic means. If you travel, on average, meters farther than me, then I travel meters farther than you; and just as ratios compose with multiplication rather than addition, they invert with reciprocation rather than negation.
The logarithmic connection
Look more closely at these analogies that hold “in spirit” between ratios and the more general real numbers:
- Ratios live in , and reals live in .
- Ratios combine with multiplication, and reals with addition.
- Ratios scale down with th roots, and reals with division.
- Ratios invert with reciprocation, and reals with negation.
The common structure underlying these mappings is the logarithm:
- The image of under the logarithm is .
- For ratios and , we have .
- For a ratio and positive scalar , we have .
- For a ratio , we have .
Because the logarithm preserves all the structure that we care about, we say that it is a homomorphism (“same shape”) from the ratios to the reals. Moreover, since the logarithm is invertible (via the exponential function), and its inverse likewise preserves this structure, it is an isomorphism, which means that these two spaces are really just different characterizations of the same thing. Thus, another way to think about the geometric mean is that it uses the logarithm to bring the ratios into “linear space”, takes their arithmetic mean, and then returns them to their natural habitat:
This also suggests that if we wanted to, say, summarize the distribution of a random variable representing ratios, we should probably not take its expectation. We would get a more meaningful result by taking the exponential of the expectation of its logarithm, . And this in turn brings to mind Jensen’s inequality, with which we immediately obtain a nice proof of the AM–GM inequality by taking to be a uniform random variable over a set :
with the second step due to Jensen’s inequality, the concavity of the logarithm, and the monotonicity of the exponential. All the pieces fit nicely together… one connection at a time.