Exponential Families
In my last post I discussed log-linear models. In this post I'd like to take another perspective on log-linear models, by thinking of them as members of an exponential family. There are many reasons to take this perspective: exponential families give us efficient representations of log-linear models, which is important for continuous domains; they always have conjugate priors, which provide an analytically tractable regularization method; finally, they can be viewed as maximum-entropy models for a given set of sufficient statistics. Don't worry if these terms are unfamiliar; I will explain all of them by the end of this post. Also note that most of this material is available on the Wikipedia page on exponential families, which I used quite liberally in preparing the below exposition.
1. Exponential Families
An exponential family is a family of probability distributions, parameterized by , of the form
(1)
Notice the similarity to the definition of a log-linear model, which is
(2)
So, a log-linear model is simply an exponential family model with . Note that we can re-write the right-hand-side of (1) as , so an exponential family is really just a log-linear model with one of the coordinates of constrained to equal . Also note that the normalization constant in (1) is a function of (since fully specifies the distribution over ), so we can express (1) more explicitly as
(3)
where
(4)
Exponential families are capable of capturing almost all of the common distributions you are familiar with. There is an extensive table on Wikipedia; I've also included some of the most common below:
- Gaussian distributions. Let . Then . If we let , then . We therefore see that Gaussian distributions are an exponential family for .
- Poisson distributions. Let and . Then . If we let then we get ; we thus see that Poisson distributions are also an exponential family.
- Multinomial distributions. Suppose that . Let be an -dimensional vector whose th element is and where all other elements are zero. Then . If , then we obtain an arbitrary multinomial distribution. Therefore, multinomial distributions are also an exponential family.
2. Sufficient Statistics
A statistic of a random variable is any deterministic function of that variable. For instance, if is a vector of Gaussian random variables, then the sample mean and sample variance are both statistics.
Let be a family of distributions parameterized by , and let be a random variable with distribution given by some unknown . Then a vector of statistics are called sufficient statistics for if they contain all possible information about , that is, for any function , we have
(5)
for some function that has no dependence on .
For instance, let be a vector of independent Gaussian random variables with unknown mean and variance . It turns out that is a sufficient statistic for and . This is not immediately obvious; a very useful tool for determining whether statistics are sufficient is the Fisher-Neyman factorization theorem:
Theorem 1 (Fisher-Neyman) Suppose that has a probability density function . Then the statistics are sufficient for if and only if can be written in the form
(6)
In other words, the probability of can be factored into a part that does not depend on , and a part that depends on only via .
What is going on here, intuitively? If depended only on , then would definitely be a sufficient statistic. But that isn't the only way for to be a sufficient statistic --- could also just not depend on at all, in which case would trivially be a sufficient statistic (as would anything else). The Fisher-Neyman theorem essentially says that the only way in which can be a sufficient statistic is if its density is a product of these two cases.
Proof: If (6) holds, then we can check that (5) is satisfied:
$\begin{array}{rcl} \mathbb{E}[f(X) \mid T(X) = T_0, \theta = \theta_0] &=& \frac{\int_{T(X) = T_0} f(X) dp(X \mid \theta=\theta_0)}{\int_{T(X) = T_0} dp(X \mid \theta=\theta_0)}\ \ &=& \frac{\int_{T(X)=T_0} f(X)h(X)g_\theta(T_0) dX}{\int_{T(X)=T_0} h(X)g_\theta(T_0) dX}\ \ &=& \frac{\int_{T(X)=T_0} f(X)h(X)dX}{\int_{T(X)=T_0} h(X) dX}, \end{array} $
where the right-hand-side has no dependence on .
On the other hand, if we compute for an arbitrary density , we get
$\begin{array}{rcl} \mathbb{E}[f(X) \mid T(X) = T_0, \theta = \theta_0] &=& \int_{T(X) = T_0} f(X) \frac{p(X \mid \theta=\theta_0)}{\int_{T(X)=T_0} p(X \mid \theta=\theta_0) dX} dX. \end{array} $
If the right-hand-side cannot depend on for any choice of , then the term that we multiply by must not depend on ; that is, must be some function that depends only on and and not on . On the other hand, the denominator depends only on and ; call this dependence . Finally, note that is a deterministic function of , so let . We then see that , which is the same form as (6), thus completing the proof of the theorem.
Now, let us apply the Fisher-Neyman theorem to exponential families. By definition, the density for an exponential family factors as
$p(x \mid \theta) = h(x)\exp(\theta^T\phi(x)-A(\theta)). $
If we let and , then the Fisher-Neyman condition is met; therefore, is a vector of sufficient statistics for the exponential family. In fact, we can go further:
Theorem 2 *Let be drawn independently from an exponential family distribution with fixed parameter . Then the empirical expectation is a sufficient statistic for ._
Proof: The density for given is
$\begin{array}{rcl} p(X_1,\ldots,X_n \mid \theta) &=& h(X_1)\cdots h(X_n) \exp(\theta^T\sum_{i=1}^n \phi(X_i) - nA(\theta)) \ &=& h(X_1)\cdots h(X_n)\exp(n [\hat{\phi}-A(\theta)]). \end{array} $
Letting and , we see that the Fisher-Neyman conditions are satisfied, so that is indeed a sufficient statistic.
Finally, we note (without proof) the same relationship as in the log-linear case to the gradient and Hessian of with respect to the model parameters:
Theorem 3 Again let be drawn from an exponential family distribution with parameter . Then the gradient of with respect to is
$n \times \left(\hat{\phi}-\mathbb{E}[\phi \mid \theta]\right) $
and the Hessian is
$n \times \left(\mathbb{E}[\phi \mid \theta]\mathbb{E}[\phi \mid \theta]^T - \mathbb{E}[\phi\phi^T \mid \theta]\right). $
This theorem provides an efficient algorithm for fitting the parameters of an exponential family distribution (for details on the algorithm, see the part near the end of the log-linear models post on parameter estimation).
3. Moments of an Exponential Family
If is a real-valued random variable, then the th moment of is . In general, if is a random variable on , then for every sequence of non-negative integers, there is a corresponding moment .
In exponential families there is a very nice relationship between the normalization constant and the moments of . Before we establish this relationship, let us define the moment generating function of a random variable as .
Lemma 4 The moment generating function for a random variable is equal to
$\sum_{p_1,\ldots,p_n=0}^{\infty} M_{p_1,\cdots,p_n} \frac{\lambda_1^{p_1}\cdots \lambda_n^{p_n}}{p_1!\cdots p_n!}. $
The proof of Lemma 4 is a straightforward application of Taylor's theorem, together with linearity of expectation (note that in one dimension, the expression in Lemma 4 would just be ).
We now see why is called the moment generating function: it is the exponential generating function for the moments of . The moment generating function for the sufficient statistics of an exponential family is particularly easy to compute:
Lemma 5 If , then .
Proof:
$\begin{array}{rcl} \mathbb{E}[\exp(\lambda^Tx)] &=& \int \exp(\lambda^Tx) p(x \mid \theta) dx \ &=& \int \exp(\lambda^Tx)h(x)\exp(\theta^T\phi(x)-A(\theta)) dx \ &=& \int h(x)\exp((\theta+\lambda)^T\phi(x)-A(\theta)) dx \ &=& \int h(x)\exp((\theta+\lambda)^T\phi(x)-A(\theta+\lambda))dx \times \exp(A(\theta+\lambda)-A(\theta)) \ &=& \int p(x \mid \theta+\lambda) dx \times \exp(A(\theta+\lambda)-A(\theta)) \ &=& \exp(A(\theta+\lambda)-A(\theta)), \end{array} $
where the last step uses the fact that is a probability density and hence .
Now, by Lemma 4, is just the coefficient in the Taylor series for the moment generating function , and hence we can compute as . Combining this with Lemma 5 gives us a closed-form expression for in terms of the normalization constant :
Lemma 6 The moments of an exponential family can be computed as
$M_{p_1,\ldots,p_n} = \frac{\partial^{p_1+\cdots+p_n} \exp(A(\theta+\lambda)-A(\theta))}{\partial^{p_1}\lambda_1\cdots \partial^{p_n}\lambda_n}. $
For those who prefer cumulants to moments, I will note that there is a version of Lemma 6 for cumulants with an even simpler formula.
Exercise: Use Lemma 6 to compute , where is a Gaussian with mean and variance .
4. Conjugate Priors
Given a family of distributions , a conjugate prior family is a family that has the property that
$p(\theta \mid X, \alpha) = p(\theta \mid \alpha') $
for some depending on and . In other words, if the prior over lies in the conjugate family, and we observe , then the posterior over also lies in the conjugate family. This is very useful algebraically as it means that we can get our posterior simply by updating the parameters of the prior. The following are examples of conjugate families:
Gaussian-Gaussian
Let , and let . Then, by Bayes' rule,
$\begin{array}{rcl} p(\mu \mid X=x, \mu_0, \sigma_0) &\propto \exp((x-\mu)^2/2)\exp((\mu-\mu_0)^2/2\sigma_0^2) \ &= &\exp\left(\frac{(\mu-\mu_0)^2+\sigma_0^2(\mu-x)^2}{2\sigma_0^2}\right) \ &\propto& \exp\left(\frac{(1+\sigma_0)^2\mu^2-2(\mu_0+\sigma_0^2x)\mu}{2\sigma_0^2}\right) \ &\propto& \exp\left(\frac{\mu^2-2\frac{\mu_0+x\sigma_0^2}{1+\sigma_0^2}\mu}{2\sigma_0^2/(1+\sigma_0^2)}\right) \ &\propto& \exp\left(\frac{(\mu-(\mu_0+x\sigma_0^2)/(1+\sigma_0^2))^2}{2\sigma_0^2/(1+\sigma_0^2)}\right) \ &\propto& p\left(\mu \mid \frac{\mu_0+x\sigma_0^2}{1+\sigma_0^2}, \frac{\sigma_0}{\sqrt{1+\sigma_0^2}}\right). \end{array} $
Therefore, parameterize a family of priors over that is conjugate to .
Beta-Bernoulli
Let , , , and . The distribution over given is then called a Bernoulli distribution, and that of given and is called a beta distribution. Note that can also be written as . From this, we see that the family of beta distributions is a conjugate prior to the family of Bernoulli distributions, since
$\begin{array}{rcl} p(\theta \mid X=x, \alpha, \beta) &\propto& \theta^x(1-\theta)^{1-x} \times \theta^{\alpha-1}(1-\theta)^{\beta-1} \ &=& \theta^{\alpha+x-1}(1-\theta)^{\beta+(1-x)-1} \ &\propto& p(\theta \mid \alpha+x, \beta+(1-x)). \end{array} $
Gamma-Poisson
Let for . Let . As noted before, the distribution for given is called a Poisson distribution; the distribution for given and is called a gamma distribution. We can check that the family of gamma distributions is conjugate to the family of Poisson distributions.*Important note:_ unlike in the last two examples, the normalization constant for the Poisson distribution actually depends on , and so we need to include it in our calculations: $\begin{array}{rcl} p(\lambda \mid X=k, \alpha, \beta) &\propto& \frac{\lambda^k}{e^{\lambda}k!} \times \lambda^{\alpha-1}\exp(-\beta\lambda) \ &\propto& \lambda^{\alpha+k-1}\exp(-(\beta+1)\lambda) \ &\propto& p(\lambda \mid \alpha+k, \beta+1). \end{array} $ Note that, in general, a family of distributions will always have some conjugate family, as if nothing else the family of all probability distributions over will be a conjugate family. What we really care about is a conjugate family that itself has nice properties, such as tractably computable moments.
Conjugate priors have a very nice relationship to exponential families, established in the following theorem:
Theorem 7 Let be an exponential family. Then is a conjugate prior for for any choice of . The update formula is . Furthermore, is itself an exponential family, with sufficient statistics .
Checking the theorem is a matter of straightforward algebra, so I will leave the proof as an exercise to the reader. Note that, as before, there is no guarantee that will be tractable; however, in many cases the conjugate prior given by Theorem 7 is a well-behaved family. See this Wikipedia page for examples of conjugate priors, many of which correspond to exponential family distributions.
5. Maximum Entropy and Duality
The final property of exponential families I would like to establish is a certain duality property. What I mean by this is that exponential families can be thought of as the maximum entropy distributions subject to a constraint on the expected value of their sufficient statistics. For those unfamiliar with the term, the entropy of a distribution over with density is . Intuitively, higher entropy corresponds to higher uncertainty, so a maximum entropy distribution is one specifying as much uncertainty as possible given a certain set of information (such as the values of various moments). This makes them appealing, at least in theory, from a modeling perspective, since they "encode exactly as much information as is given and no more". (Caveat: this intuition isn't entirely valid, and in practice maximum-entropy distributions aren't always necessarily appropriate.)
In any case, the duality property is captured in the following theorem:
Theorem 8 The distribution over with maximum entropy such that lies in the exponential family with sufficient statistic and .
Proving this fully rigorously requires the calculus of variations; I will instead give the "physicist's proof". Proof: } Let be the density for . Then we can view as the solution to the constrained maximization problem:
$\begin{array}{rcl} \mathrm{maximize} && -\int p(X) \log p(X) dX \ \mathrm{subject \ to} && \int p(X) dX = 1 \ && \int p(X) \phi(X) dX = T. \end{array} $
By the method of Lagrange multipliers, there exist and such that
$\frac{d}{dp}\left(-\int p(X)\log p(X) dX - \alpha [\int p(X) dX-1] - \lambda^T[\int \phi(X) p(X) dX-T]\right) = 0. $
This simplifies to:
$-\log p(X) - 1 - \alpha -\lambda^T \phi(X) = 0, $
which implies
$p(X) = \exp(-1-\alpha-\lambda^T\phi(X)) $
for some and . In particular, if we let and , then we recover the exponential family with , as claimed.
6. Conclusion
Hopefully I have by now convinced you that exponential families have many nice properties: they have conjugate priors, simple-to-fit parameters, and easily-computed moments. While exponential families aren't always appropriate models for a given situation, their tractability makes them the model of choice when no other information is present; and, since they can be obtained as maximum-entropy families, they are actually appropriate models in a wide family of circumstances.