4
$\begingroup$

I am learning about the cross entropy, defined by Wikipedia as $$H(P,Q)=-\text{E}_P[\log Q]$$ for distributions $P,Q$.

I'm not happy with that notation, because it implies symmetry, $H(X,Y)$ is often used for the joint entropy and lastly, I want to use a notation which is consistent with the notation for entropy: $$H(X)=-\text{E}_P[\log P(X)]$$

When dealing with multiple distributions, I like to write $H_P(X)$ so it's clear with respect to which distribution I'm taking the entropy. When dealing with multiple random variables, it thinks it's sensible to make precise the random variable with respect to which the expectation is taken by using the subscript $_{X\sim P}$. My notation for entropy thus becomes $$H_{X\sim P}(X)=-\text{E}_{X\sim P}[\log P(X)]$$

Now comes the point I don't understand about the definition of cross entropy: Why doesn't it reference a random variable $X$? Applying analogous reasoning as above, I would assume that cross entropy has the form \begin{equation}H_{X\sim P}(Q(X))=-\text{E}_{X\sim P}[\log Q(X)]\tag{1}\end{equation} however, Wikipedia makes no mention of any such random variable $X$ in the article on cross entropy. It speaks of

the cross-entropy between two probability distributions $p$ and $q$

which, like the notation $H(P,Q)$, implies a function whose argument is a pair of distributions, whereas entropy $H(X)$ is said to be a function of a random variable. In any case, to take an expected value I need a (function of) a random variable, which $P$ and $Q$ are not.

Comparing the definitions for the discrete case: $$H(p,q)=-\sum_{x\in\mathcal{X}}p(x)\log q(x)$$ and $$H(X)=-\sum_{i=1}^n P(x_i)\log P(x_i)$$

where $\mathcal{X}$ is the support of $P$ and $Q$, there would only be a qualitative difference if the events $x_i$ didn't cover the whole support (though I could just choose an $X$ which does).

My questions boil down to the following:

  1. Where is the random variable necessary to take the expected value which is used to define the cross entropy $H(P,Q)=-\text{E}_{P}[\log Q]$

  2. If I am correct in my assumption that one needs to choose a random variable $X$ to compute the cross entropy, is the notation I used for (1) free of ambiguities.

$\endgroup$
2
$\begingroup$

Your notation $H(X)=-\text{E}_P[\log P(X)]$ is really redundant. In general, if $X$ is a random variable, and $g$ is any function, then $E[g(X)]$ is defined without ambiguity, it's not necessary (actually is makes no sense) to specify "with respect to which variable the expectation is taken".

The confusion might arise here because we are dealing with two things, random variables and distributions, and using different letters for them. But, in essence, a random variable is a distribution.

If we understand that $X$ is a rv with distribution $p$ , and the same for $Y$ and $q$, then we can write, unambiguosly (let me use $\tilde H$ for the cross entropy to distinguish it from the joint entropy):

$$\tilde H(p,q) = - E[ \log q(X)] = - \sum_x p(x) \log q(x) $$

If the above causes some confusion, consider that $\log (q(\cdot))$ is just a function, like $\sin(\cdot)$ or $\sqrt{\cdot}$

It mightbe more clear and consistent (but also more verbose) to use $P_X()$ and $P_Y()$ to denote the distributions of random variables $X,Y$.

$$\tilde H(X,Y) = - E[ \log P_Y(X)] = - \sum_x P_X(x) \log P_Y(x) $$

Notice that the lowercase $x$, used in the sums, is a dummy variable (not a random variable!) and we could also use $u$ instead or any other letter.


Edit: An attempt to clarify.

First: if $X$ is a given random variable, then its probability distribution is given, and the expression $E[X]$ is perfectly well defined, with zero ambiguity: eg, in the discrete case, $E[X] = \sum_x x P(x) $ where $P(\cdot)$ is the pmf of $X$. Period. It would be nonsensical to specify "with respect with which variable or distribution" the expectation should be taken.

This is also true when some funcion is applied to the rv (which just produces another rv), as in $E[g(X)]$, or when the variable is multidimensional, as in $E[g(X,Y)]$.

Hence, the notations $E_Q[X]$, $E_Q[g(X)]$ , $E_Q[g(X,Y)]$ (where $Q$ is some distribution) are wrong, they make no sense.

Having said that: sometimes it's not feasible or practical to stick with that notation, where each random variable has a letter like $X$. For example, suppose we want consider the family of zero mean gaussian distributions, parametrized by the deviation $\sigma$, and we want to denote by $r(\sigma)$ the respective differential entropy. Letting $\phi(x;\sigma)$ be the gaussian density, we'd write

$$r(\sigma) = - \int \phi(x;\sigma) \log \phi(x;\sigma) dx$$

Notice that here $x$ is not a random variable, is just a dummy integration variable, and we could replace it with any letter. Now, surely, this is an expectation, and so might want to write something like

$$r(\sigma) = - E[\log \phi(x;\sigma)] \tag2$$

... but this is not right, because the argument of $E[\cdot]$ is not a random variable! We might instead write

$$r(\sigma) = - E[\log \phi(X_{\sigma};\sigma)] \tag3$$

adding the definition: "$X_{\sigma}$ is a rv that follows the distribution $N(0,\sigma^2)$", but this is rather ugly. Hence we often abuse the notation in the following way:

$$r(\sigma) = - E_{\phi(x;\sigma)}[\log \phi(x;\sigma)] \tag4$$

But, be careful, here the $E[]$ notation must be understood not in the probabilistic setting but mere as a functional operator; here random variables are not involved, only functions (some of them, densities or distributions). That is

$$E_{f(x)}[g(x)] \triangleq \int f(x) g(x) dx \tag 5 $$

In this setting, the original notation $H(P,Q)=-\text{E}_P[\log Q]$ is, indeed, totally correct.

And as for the plain entropy, it should either be

$$H(X) = -E [\log P(X)] \tag 6$$

(entropy of a random variable $X$ is a rv which has distribution $P$) or

$$H(P) = -E_P [\log P] \tag 7$$

(entropy of a distribution $P$, functional expection operator, no random variables appear). You are mixing both.

$\endgroup$
10
  • $\begingroup$ On the contrary, it makes a lot of sense. $\text{E}_{X\sim P}[g(X)]$ generalizes to the multi-variable case, $\text{E}_[g(X)]$ doesn't. $\text{E}[g(X,Y)]$ tells me neither with respect to which r.v. I am taking the expectation, nor which distribution belongs to which random variable. $\text{E}_{X\sim P}[g(X,Y)]$ on the other hand tells me unambiguously that I'm dealing with the integral $\int_\Omega g(X(\omega),Y(\omega))P(d\omega)$ for some underlying sample space $\Omega$. $\endgroup$ – azureai Mar 5 at 16:04
  • $\begingroup$ No, that's wrong. $\text{E}[g(X,Y)]$ is also unambiguous. Take any example. Say $X$ and $Y$ are iid uniform on $[0,1]$ , let $g(X,Y)=X+Y$ . Would it make sense to say $\text{E}[g(X,Y)]$ "with respect of $X$" ? $\endgroup$ – leonbloy Mar 5 at 16:06
  • $\begingroup$ $\text{E}$ does not tell you with respect to which distribution the expectation is taken. $X$ could be distributed differently from $Y$. $\endgroup$ – azureai Mar 5 at 16:07
  • 1
    $\begingroup$ BTW - I've made the same mistake, and I've been rightly corrected a while ago math.stackexchange.com/a/41543/312 (first comment) $\endgroup$ – leonbloy Mar 5 at 16:12
  • $\begingroup$ We might be talking about different things. In your first sentence, you write that $H(X)=-\text{E}_P[\log P(X)]$ is redundant, and then go on to write that it makes no sense to specify with respect to which random variable the expectation is taken. The cited notation doesn't do that. You might mean that $\text{E}_{X\sim P}$ is redundant, and I'm currently reading the thread you linked to understand that. But $E_P[X]$ makes sense, see the case of cross- entropy, where you're dealing with multiple distributions. You need to be able to express wrt which distribution you're taking the expectation. $\endgroup$ – azureai Mar 5 at 18:28
1
$\begingroup$

Personally, I feel that $H(X)$ is already a (very convenient) abuse of notation. After all, entropy is a function of purely the law of $X$ (and not the values it takes). So the IMO fundamental object is (for discrete laws), $H(p) := - \sum p_x \log p_x$ and writing $H(X)$ for the entropy of the law of a random variable $X$ is a convenient shorthand - more formally I'd write this as $H(X\mu)$, where $\mu$ is the measure of the underlying probability space, and $X\mu$ is its pushforward under $X$ (which is a fancy way of saying the law of $X$). There's an exact parallel for differential entropy, but with the catch that you need to have a base measure on the outcome space for differential entropy to make sense.

With this view, $H(p,q) := -\sum p_x \log q_x$ is a natural definition and notation -you don't really need to invoke a random variable, it's about the laws. In fact, I'd maybe go one step further - cross entropy, much like KL divergence, is not really about random variables, but it's a measure(in the non-mathematical sense) of how well aligned two laws are.

If you want to highlight the asymmetry, there's a couple of options that i've seen floating around -

  1. $H(p\|q)$, which highlights the connection between cross-entropy and KL-divergence - $H(p\|q) = D(p\|q) + H(p)$. The notation is nice because the asymmetry of cross entropy is entirely the same as that of KL divergence.

  2. $H_p(q)$ which is sort of expressing that the 'base measure' is $p$. I find this notation quite natural when I consider operational meanings of cross entropy - e.g. if one designs a good compression scheme for an iid $q$-source, but the actual law on which this code is used were iid $p$, the average code length per symbol one would get is (asymptotically) $H_p(q).$ So in this case the base measure $p$ is what's 'truly happening', while $q$ is what you're trying to 'impose'.

$\endgroup$
3
  • $\begingroup$ I know what a pushforward-measure is, but I'm not familiar with your $p_x$ notation. What are your respective sums running over? Also, in my understanding, to get a pushforward-measure/law I always need a random variable $X$. Where is this r.v. in your definition of $H(p,q)$ and, importantly, where does it come from? $\endgroup$ – azureai Mar 5 at 17:59
  • $\begingroup$ Well, any discrete distribution is some sequence of positive reals that add up to $1$. I was just denoting this sequence as $\{p_x\}.$ The larger point in the above is that laws make sense as objects beyond random variables, and if some quantities depend only on laws, then one doesn't need to introduce random variables to define them. If you like you can introduce some random variable $X \sim p$ and then say that $H(p\|q) = \mathbb{E}_X[\log q(X)],$ but I think this is not needed, it's enough to define cross entropy as a function from the space of pairs of distributions to the reals. $\endgroup$ – stochasticboy321 Mar 5 at 18:32
  • 1
    $\begingroup$ Oh, and, for completeness, in writing $\mathbb{E}_X[\log q(X)],$ I'm assuming that $q$ is a law on some set containing the values $X$ can take, and then treating $q$ as a function such that $q(x) = q_x$. $\endgroup$ – stochasticboy321 Mar 5 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.