In a previous post we saw how entropy quantifies the 'volume' occupied by a discrete random variable. However, many random quantities are continuous, for example if we are measuring the strength of a magnetic field. To analyse these we have to define a continuous entropy. This has some strange features: it can be negative, and depends on parameterisation. What does it mean to have a negative amount of randomness? And how can it depend on the way that you describe your random variable?
In this post we will consider the entropy of a continuous random variable, again from the geometric viewpoint. Thinking in terms of 'volumes' makes the strange features above both intuitive and expected. It turns out that the continuous entropy is a slightly different beast to the discrete case, and the geometric picture is the best way to understand this.
Defining a continuous entropy #
If is a discrete random variable, with different outcomes and associated probabilities , the discrete entropy is defined as:
The meaning of this expression, and its interpretation as a volume of the sample space, was discussed in the previous post.
Now, suppose we have a continuous random variable . This doesn't have a discrete set of outcomes, but rather takes values in some range , according to a probability density . You should always include the part! You need the differential to have the right units, and transform correctly when you change variables — see the appendix. For example, let be a Gaussian with mean and variance . Then this can take value anywhere on the real line: , and the probability density is
The probability of attaining any particular point is zero, i.e. the chance of sampling a Gaussian and getting exactly is nil. Thus is not the probability that we will observe . Rather, gives the probability that if we measure , we will observe a value between and (provided is small). Returning to our Gaussian example and setting ,
which is the probability that if we measured , we would observe a value between and .
Given a random variable , we define the continuous entropy (also called differential entropy) by naïvely taking [eqDiscreteEntropy] and swapping the sum for an integral and the probability for the probability density:
At a first glance this may seem perfectly innocuous. However, the continuous case introduces several subtleties, which confused information theorists since it was first introduced. The continuous entropy is in fact a different beast to the discrete entropy, which is why it is written with a lowercase ''.
A parametrisation problem #
One of the first indicators that something is off about [eqContinuousEntropy] comes from thinking about units. As discussed in the appendix, if has units then so must for to be dimensionless. For example if is a
length, then will have units
1/length. However every time we use a special function such as sine, the exponential, or the logarithm, the argument should in general be dimensionless. To see this consider the Taylor series of the exponential:
If has units then each term on the right hand side will have different units. You can't add
length3+..., so the right hand side is undefined. The logarithm is a bit different in that you can take the log of a quantity with units — see the appendix, but this means that the entropy itself will also have units.
Mathematically, this shows up as an ambiguity in the definition [eqContinuousEntropy]. Suppose we choose a different parameterisation , and let be the probability distribution with respect to . We would hope that the entropy computed in these coordinates will be the same:
Otherwise given a random variable , how do you know which is the 'one true parameterisation?'. To verify this we transform the distribution:
from which we see . From this the entropy evaluates to
Thus if we have two different parameterisations for the same random variable, we will calculate two different entropies! This seems like a very big problem. If you ask "how random is the distribution of people's heights?", you don't make any reference as to if we measure those heights in centimeters or feet.
Continuous entropy as a length #
The resolution comes from looking at continuous entropy through the gemetric formulation. We discussed in the previous post that exponentiating the discrete entropy measured the volume of sample space occupied by a discrete random variable, where 'volume' was interpreted as 'number of points'. If we have a continuous (and one-dimensional) random variable, the continuous entropy also measures the occupied volume of sample space, but now by 'volume' we mean the one-dimensional 'length'.
To understand this better, consider a uniform distribution on the closed interval , where . If we let represent a point on the real line, this distribution has probability density
Performing the integral in [eqContinuousEntropy] we find the entropy to be . To get the geometric meaning we exponentiate this: , which is indeed the 'length' that the uniform distribution occupies.
Let's change coordinates to , in which case the probability density becomes
The random variable has half the 'length' as before, since it is uniformly distributed over the closed interval . We would therefore expect the entropy in these coordinates to be different — the paramerisation dependence isn't a bug, it's a feature! We can confirm this by computing
and taking the exponential gives a new length of .
If the random variable wasn't uniformly distributed, the probability density would cause it to become more concentrated on some parts of the sample space, so the overall volume would decrease. Thus the continuous entropy measures the volume of a random variable, where now by 'volume' we mean 'length'. This length must necessarily change in different coordinates, which is the reason for the parameterisation-dependence of the continuous entropy.
Continuous and discrete entropies #
Let's take a look at a Gaussian distribution with mean and variance :
The entropy of this works out to be . This is independent of , which is expected since translating the distribution doesn't change the volume of sample space it occupies. The entropy does however increase with , since the distribution becomes more spread out.
If grows smaller the entropy shrinks, eventually becoming negative. The discrete entropy is always positive, which in the geometric interpreation is equivalent to saying that a random variable can't occupy less than a single point in sample space. The continuous entropy however can be negative, but this isn't really an issue. Exponentiating we still end up with a positive volume, a negative continuous entropy simply means that the 'length' occupied by the random variable is less than one.
Something interesting happens when we let , in which case the continuous entropy approaches negative infinity. Then , i.e. the random variable has a volume of zero. The meaning of this is that a Gaussian with zero variance occupies only a single point.
This highlights the contrast between the discrete entropy and the continuous entropy . Both of these measure the 'volume' of a random variable, however with different definitons of 'volume'. For the discrete entropy we mean 'number of points', while for the continuous entropy we mean 'length'. If you have a mathematical bent, they correspond to choosing different measures on sample space, an idea I explore in §5.2 of my thesis.
With these ideas in mind, suppose is a continuous random variable. What would be the discrete entropy ? Recall that counts the number of points in the sample space that occupies. A continuous random variable occupies an inifinite number of points, thus we must have . Similarly, consider where is a discrete random variable. Any discrete subset of the real line has volume zero, so we must have , which immediately gives .
The continuous entropy is defined analogously to the discrete entropy, replacing the probability with probabillity density and sum with an integral. Despite this, the continuous entropy is not just the extension of the discrete entropy to continous random variables. They both quantify the volume of sample space occupied by a random variable, however the discrete entropy defines volume as 'number of points', while the continuous defines it as 'length'. Because of this the discrete entropy of a continuous random variable will be infinity, while the continuous entropy of a discrete random variable is negative infinity.
We can see then that the geometric interpretation unifies the concepts of discrete and continuous entropy, and shows how they relate to one another. Historically the continuous entropy has been regarded as strange and ill-defined, because it depends on the parameterisation and can be negative. However these features are not only natural, but expected, when we view entropy as quantifying a 'volume'.
We are now able to quantify the 'spread' of a random variable, whether it is discrete or continuous. In the next post we will see how this changes when we learn information, for example by measuring a system. This will let us analyse how 'good' a measurement is &mdas; by what factor does it shrink the spread?
Have any comments or questions? Let me know! Follow @ruvi_l on twitter for more posts like this, or join the discussion on Reddit:
Why you should always write the infinitesimal #
Suppose you are given a circle of random radius , where the probability density on the possible radii is . Then the probability of getting a radius between and is
Let's be concrete, and take to be Gaussian distributed about some mean with variance :
We may also describe the circles not by radius , but by their area , which is related by (or ). Then the mean area would be , and the bounds in [eqrProbIntegral] would become . Finally, we need to find the probability density in terms of the areas .
A common mistake is to takge and substitute . This would give us
where the question mark is to emphasise that this is not in fact correct. We can see this by considering units. The right hand side of [eqhSubstituted] has units of , where has units
length since it is the variance of our distribution of radii. However the integral
gives a probability, which is unitless. The infinitesimal has units of
area, so should have units of
The correct answer comes from transforming not the density but the integral [eqrProbIntegral]. From the chain rule , so the integral becomes
We can therefore see that
Thus when changing units, we must always remember to transform both the density function, and the infinitesimal. We don't substitute into , we substitute it into . The infinitesimal is part of the probability density, and that's why I recommend that you always include the infinitesimal.
More generally even if you aren't transforming the distribution, including the infinitesimal is still more natural. A probability density only becomes a probability when you include the infinitesimal, and you need to keep it there for the units to be dimensionless.
The logarithm and units #
Can you take the logarithm of a quantity with units? It is certainly possible if you are sufficiently determined, and in this section we will analyse the consequences of such a reckless decision. It turns out that you can, so long as you take appropriate care.
Firstly we should think about precisely what 'units' mean. We assume a quantity to scale by a given factor under transformations that we call 'change units'. For example, if a quantity has units of
centimetres, this means there is an object such that if we perform the transformation
centimeteres metres, we have .
With this in mind, let's take the logarithm of . Using , this becomes
If we perform
centimeteres metres, then will transform as described above, while a number such as will stay the same:
Putting this together, we see that if you take the logarithm of a quantity with units, it ends up with 'logarithmic units'. If you make a log-plot of a quantity with units of
centimetres, the axis should have , as a reminder that you need to have an extra to account for a change in units. Then if someone wants to know what the numbers would be in
metres, the answer is to add to each point. Compare this to a regular plot of a quantity in
centimeters, where you would multiply each point by when you change units.
Now let's see how this applies to the parameterisation problem discussed earlier. The parameterisations and can be seen as different units for the real line. To account for this, we will suppose that has some units of 'length' which we will call . Then also has units of , so the equation
requires to have units .
The continuous entropy is
The factors of and outside the logarithm cancel, giving
where denotes the entropy of the probability density when calculated in units of .
The transformation can be seen as choosing new units . Then:
This gives us the result that we found before.
The discussion on continuous entropy was mostly inspired by
[CT05] Cover, T. M., & Thomas, J. A. (2005). Elements of Information Theory. In Elements of Information Theory. John Wiley & Sons. https://doi.org/10.1002/047174882X