Quadratically Independent Monomials

Today Arun asked me the following question:

“Under what conditions will a set ![\{p_1,\ldots,p_n\}](https://s0.wp.com/latex.php?latex=%5C%7Bp_1%2C%5Cldots%2Cp_n%5C%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) of polynomials be quadratically independent, in the sense that ![\{p_1^2, p_1p_2, p_2^2, p_1p_3,\ldots,p_{n-1}p_n, p_n^2\}](https://s0.wp.com/latex.php?latex=%5C%7Bp_1%5E2%2C+p_1p_2%2C+p_2%5E2%2C+p_1p_3%2C%5Cldots%2Cp_%7Bn-1%7Dp_n%2C+p_n%5E2%5C%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) is a linearly independent set?”

I wasn’t able to make much progress on this general question, but in the specific setting where the ![p_i](https://s0.wp.com/latex.php?latex=p_i&bg=f0f0f0&fg=555555&s=0&c=20201002) are all polynomials in one variable, and we further restrict to just monomials, (i.e. ![p_i(x) = x^{d_i}](https://s0.wp.com/latex.php?latex=p_i%28x%29+%3D+x%5E%7Bd_i%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) for some ![d_i](https://s0.wp.com/latex.php?latex=d_i&bg=f0f0f0&fg=555555&s=0&c=20201002)), the condition is just that there are no distinct unordered pairs ![(i_1,j_1),(i_2,j_2)](https://s0.wp.com/latex.php?latex=%28i_1%2Cj_1%29%2C%28i_2%2Cj_2%29&bg=f0f0f0&fg=555555&s=0&c=20201002) such that ![d_{i_1} + d_{j_1} = d_{i_2} + d_{j_2}](https://s0.wp.com/latex.php?latex=d_%7Bi_1%7D+%2B+d_%7Bj_1%7D+%3D+d_%7Bi_2%7D+%2B+d_%7Bj_2%7D&bg=f0f0f0&fg=555555&s=0&c=20201002). Arun was interested in the largest such a set could be for a given maximum degree ![D](https://s0.wp.com/latex.php?latex=D&bg=f0f0f0&fg=555555&s=0&c=20201002), so we are left with the following interesting combinatorics problem:

“What is the largest subset ![S](https://s0.wp.com/latex.php?latex=S&bg=f0f0f0&fg=555555&s=0&c=20201002) of ![\{1,\ldots,D\}](https://s0.wp.com/latex.php?latex=%5C%7B1%2C%5Cldots%2CD%5C%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) such that no two distinct pairs of elements of ![S](https://s0.wp.com/latex.php?latex=S&bg=f0f0f0&fg=555555&s=0&c=20201002) have the same sum?”

For convenience of notation let ![n](https://s0.wp.com/latex.php?latex=n&bg=f0f0f0&fg=555555&s=0&c=20201002) denote the size of ![S](https://s0.wp.com/latex.php?latex=S&bg=f0f0f0&fg=555555&s=0&c=20201002). A simple upper bound is ![\binom{N+1}{2} \leq 2D-1](https://s0.wp.com/latex.php?latex=%5Cbinom%7BN%2B1%7D%7B2%7D+%5Cleq+2D-1&bg=f0f0f0&fg=555555&s=0&c=20201002), since there are ![\binom{N+1}{2}](https://s0.wp.com/latex.php?latex=%5Cbinom%7BN%2B1%7D%7B2%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) pairs to take a sum of, and all pairwise sums lie between ![2](https://s0.wp.com/latex.php?latex=2&bg=f0f0f0&fg=555555&s=0&c=20201002) and ![2D](https://s0.wp.com/latex.php?latex=2D&bg=f0f0f0&fg=555555&s=0&c=20201002). We therefore have ![n = O(\sqrt{D})](https://s0.wp.com/latex.php?latex=n+%3D+O%28%5Csqrt%7BD%7D%29&bg=f0f0f0&fg=555555&s=0&c=20201002).

What about lower bounds on n? If we let S be the powers of 2 less than or equal to D, then we get a lower bound of ![\log_2(D)](https://s0.wp.com/latex.php?latex=%5Clog_2%28D%29&bg=f0f0f0&fg=555555&s=0&c=20201002); we can do slightly better by taking the Fibonacci numbers instead, but this still only gives us logarithmic growth. So the question is, can we find sets that grow polynomially in D?

It turns out the answer is yes, and we can do so by choosing randomly. Let each element of ![\{1,\ldots,D\}](https://s0.wp.com/latex.php?latex=%5C%7B1%2C%5Cldots%2CD%5C%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) be placed in S with probability p. Now consider any k, ![2 \leq k \leq 2D](https://s0.wp.com/latex.php?latex=2+%5Cleq+k+%5Cleq+2D&bg=f0f0f0&fg=555555&s=0&c=20201002). If k is odd, then there are (k-1)/2 possible pairs that could add up to k: (1,k-1), (2,k-2),…,((k-1)/2,(k+1)/2). The probability of each such pair existing is ![p^2](https://s0.wp.com/latex.php?latex=p%5E2&bg=f0f0f0&fg=555555&s=0&c=20201002). Note that each of these events is independent.

S is invalid if and only if there exists some k such that more than one of these pairs is active in S. The probability of any two given pairs being simultaneously active is ![p^4](https://s0.wp.com/latex.php?latex=p%5E4&bg=f0f0f0&fg=555555&s=0&c=20201002), and there are ![\binom{(k-1)/2}{2} \leq \binom{D}{2}](https://s0.wp.com/latex.php?latex=%5Cbinom%7B%28k-1%29%2F2%7D%7B2%7D+%5Cleq+%5Cbinom%7BD%7D%7B2%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) such pairs for a given ![k](https://s0.wp.com/latex.php?latex=k&bg=f0f0f0&fg=555555&s=0&c=20201002), hence ![(D-1)\binom{D}{2} \leq D^3/2](https://s0.wp.com/latex.php?latex=%28D-1%29%5Cbinom%7BD%7D%7B2%7D+%5Cleq+D%5E3%2F2&bg=f0f0f0&fg=555555&s=0&c=20201002) such pairs total (since we were just looking at odd k). Therefore, the probability of an odd value of k invalidating S is at most ![p^4D^3/2](https://s0.wp.com/latex.php?latex=p%5E4D%5E3%2F2&bg=f0f0f0&fg=555555&s=0&c=20201002).

For even ![k](https://s0.wp.com/latex.php?latex=k&bg=f0f0f0&fg=555555&s=0&c=20201002) we get much the same result except that the probability for a given value of ![k](https://s0.wp.com/latex.php?latex=k&bg=f0f0f0&fg=555555&s=0&c=20201002) comes out to the slightly more complicated formula ![\binom{k/2-1}{2}p^4 + (k/2-1)p^3 + p^2 \leq D^2p^4/2 + Dp^3 + p^2](https://s0.wp.com/latex.php?latex=%5Cbinom%7Bk%2F2-1%7D%7B2%7Dp%5E4+%2B+%28k%2F2-1%29p%5E3+%2B+p%5E2+%5Cleq+D%5E2p%5E4%2F2+%2B+Dp%5E3+%2B+p%5E2&bg=f0f0f0&fg=555555&s=0&c=20201002), so that the total probability of an even value of k invalidating S is at most ![p^4D^3/2 + p^3D^2 + p^2D](https://s0.wp.com/latex.php?latex=p%5E4D%5E3%2F2+%2B+p%5E3D%5E2+%2B+p%5E2D&bg=f0f0f0&fg=555555&s=0&c=20201002).

Putting this all together gives us a bound of ![p^4D^3 + p^3D^2 + p^2D](https://s0.wp.com/latex.php?latex=p%5E4D%5E3+%2B+p%5E3D%5E2+%2B+p%5E2D&bg=f0f0f0&fg=555555&s=0&c=20201002). If we set p to be $\frac{1}{2}D^{-\frac{3}{4}}$ then the probability of S being invalid is then at most ![\frac{1}{16} + \frac{1}{8} D^{-\frac{1}{4}} + \frac{1}{4}D^{-\frac{1}{2}} \leq \frac{7}{16}](https://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7B16%7D+%2B+%5Cfrac%7B1%7D%7B8%7D+D%5E%7B-%5Cfrac%7B1%7D%7B4%7D%7D+%2B+%5Cfrac%7B1%7D%7B4%7DD%5E%7B-%5Cfrac%7B1%7D%7B2%7D%7D+%5Cleq+%5Cfrac%7B7%7D%7B16%7D&bg=f0f0f0&fg=555555&s=0&c=20201002), so with probability at least ![\frac{7}{16}](https://s0.wp.com/latex.php?latex=%5Cfrac%7B7%7D%7B16%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) a set S with elements chosen randomly with probability ![\frac{1}{2}D^{-\frac{3}{4}}](https://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7B2%7DD%5E%7B-%5Cfrac%7B3%7D%7B4%7D%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) will be valid. On the other hand, such a set has ![D^{1/4}](https://s0.wp.com/latex.php?latex=D%5E%7B1%2F4%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) elements in expectation, and asymptotically the probability of having at least this many elements is ![\frac{1}{2}](https://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7B2%7D&bg=f0f0f0&fg=555555&s=0&c=20201002). Therefore, with probability at least ![\frac{1}{16}](https://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7B16%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) a randomly chosen set will be both valid and have size greater than ![\frac{1}{2}](https://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7B2%7D&bg=f0f0f0&fg=555555&s=0&c=20201002), which shows that the largest value of ![n](https://s0.wp.com/latex.php?latex=n&bg=f0f0f0&fg=555555&s=0&c=20201002) is at least ![\Omega\left(D^{1/4}\right)](https://s0.wp.com/latex.php?latex=%5COmega%5Cleft%28D%5E%7B1%2F4%7D%5Cright%29&bg=f0f0f0&fg=555555&s=0&c=20201002).

We can actually do better: if all elements are chosen with probability ![\frac{1}{2}D^{-2/3}](https://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7B2%7DD%5E%7B-2%2F3%7D&bg=f0f0f0&fg=555555&s=0&c=20201002), then one can show that the expected number of invalid pairs is at most ![\frac{1}{8}D^{1/3} + O(1)](https://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7B8%7DD%5E%7B1%2F3%7D+%2B+O%281%29&bg=f0f0f0&fg=555555&s=0&c=20201002), and hence we can pick randomly with probability ![p = \frac{1}{2}D^{-2/3}](https://s0.wp.com/latex.php?latex=p+%3D+%5Cfrac%7B1%7D%7B2%7DD%5E%7B-2%2F3%7D&bg=f0f0f0&fg=555555&s=0&c=20201002), remove one element of each of the invalid pairs, and still be left with ![\Omega(D^{1/3})](https://s0.wp.com/latex.php?latex=%5COmega%28D%5E%7B1%2F3%7D%29&bg=f0f0f0&fg=555555&s=0&c=20201002) elements in S.

So, to recap: choosing elements randomly gives us S of size ![\Omega(D^{1/4})](https://s0.wp.com/latex.php?latex=%5COmega%28D%5E%7B1%2F4%7D%29&bg=f0f0f0&fg=555555&s=0&c=20201002); choosing randomly and then removing any offending pairs gives us S of size ![\Omega(D^{1/3})](https://s0.wp.com/latex.php?latex=%5COmega%28D%5E%7B1%2F3%7D%29&bg=f0f0f0&fg=555555&s=0&c=20201002); and we have an upper bound of ![O(D^{1/2})](https://s0.wp.com/latex.php?latex=O%28D%5E%7B1%2F2%7D%29&bg=f0f0f0&fg=555555&s=0&c=20201002). What is the actual asymptotic answer? I don’t actually know the answer to this, but I thought I’d share what I have so far because I think the techniques involved are pretty cool.

Quadratically Independent Monomials


Exponential Families

In my [last post](https://jsteinhardt.wordpress.com/2012/12/06/log-linear-models/) 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 ![{\theta \in \mathbb{R}^n}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta+%5Cin+%5Cmathbb%7BR%7D%5En%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), of the form

![\displaystyle p(x \mid \theta) \propto h(x)\exp(\theta^T\phi(x)). \ \ \ \ \ (1)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+p%28x+%5Cmid+%5Ctheta%29+%5Cpropto+h%28x%29%5Cexp%28%5Ctheta%5ET%5Cphi%28x%29%29.+%5C+%5C+%5C+%5C+%5C+%281%29&bg=f0f0f0&fg=000000&s=0&c=20201002)

Notice the similarity to the definition of a log-linear model, which is

![\displaystyle p(x \mid \theta) \propto \exp(\theta^T\phi(x)). \ \ \ \ \ (2)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+p%28x+%5Cmid+%5Ctheta%29+%5Cpropto+%5Cexp%28%5Ctheta%5ET%5Cphi%28x%29%29.+%5C+%5C+%5C+%5C+%5C+%282%29&bg=f0f0f0&fg=000000&s=0&c=20201002)

So, a log-linear model is simply an exponential family model with ![{h(x) = 1}](https://s0.wp.com/latex.php?latex=%7Bh%28x%29+%3D+1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Note that we can re-write the right-hand-side of ([1](https://jsteinhardt.wordpress.com/feed/?paged=3#eqnexp-def-0)) as ![{\exp(\theta^T\phi(x)+\log h(x))}](https://s0.wp.com/latex.php?latex=%7B%5Cexp%28%5Ctheta%5ET%5Cphi%28x%29%2B%5Clog+h%28x%29%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), so an exponential family is really just a log-linear model with one of the coordinates of ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) constrained to equal ![{1}](https://s0.wp.com/latex.php?latex=%7B1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Also note that the normalization constant in ([1](https://jsteinhardt.wordpress.com/feed/?paged=3#eqnexp-def-0)) is a function of ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) (since ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) fully specifies the distribution over ![{x}](https://s0.wp.com/latex.php?latex=%7Bx%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)), so we can express ([1](https://jsteinhardt.wordpress.com/feed/?paged=3#eqnexp-def-0)) more explicitly as

![\displaystyle p(x \mid \theta) = h(x)\exp(\theta^T\phi(x)-A(\theta)), \ \ \ \ \ (3)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+p%28x+%5Cmid+%5Ctheta%29+%3D+h%28x%29%5Cexp%28%5Ctheta%5ET%5Cphi%28x%29-A%28%5Ctheta%29%29%2C+%5C+%5C+%5C+%5C+%5C+%283%29&bg=f0f0f0&fg=000000&s=0&c=20201002)

where

![\displaystyle A(\theta) = \log\left(\int h(x)\exp(\theta^T\phi(x)) d(x)\right). \ \ \ \ \ (4)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+A%28%5Ctheta%29+%3D+%5Clog%5Cleft%28%5Cint+h%28x%29%5Cexp%28%5Ctheta%5ET%5Cphi%28x%29%29+d%28x%29%5Cright%29.+%5C+%5C+%5C+%5C+%5C+%284%29&bg=f0f0f0&fg=000000&s=0&c=20201002)

Exponential families are capable of capturing almost all of the common distributions you are familiar with. There is an extensive [table](http://en.wikipedia.org/wiki/Exponential_family#Table_of_distributions) on Wikipedia; I’ve also included some of the most common below:

1. *Gaussian distributions.* Let ![{\phi(x) = \left[ \begin{array}{c} x \\ x^2\end{array} \right]}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%28x%29+%3D+%5Cleft%5B+%5Cbegin%7Barray%7D%7Bc%7D+x+%5C%5C+x%5E2%5Cend%7Barray%7D+%5Cright%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Then ![{p(x \mid \theta) \propto \exp(\theta_1x+\theta_2x^2)}](https://s0.wp.com/latex.php?latex=%7Bp%28x+%5Cmid+%5Ctheta%29+%5Cpropto+%5Cexp%28%5Ctheta_1x%2B%5Ctheta_2x%5E2%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). If we let ![{\theta = \left[\frac{\mu}{\sigma^2},-\frac{1}{2\sigma^2}\right]}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta+%3D+%5Cleft%5B%5Cfrac%7B%5Cmu%7D%7B%5Csigma%5E2%7D%2C-%5Cfrac%7B1%7D%7B2%5Csigma%5E2%7D%5Cright%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), then ![{p(x \mid \theta) \propto \exp(\frac{\mu x}{\sigma^2}-\frac{x^2}{2\sigma^2}) \propto \exp(-\frac{1}{2\sigma^2}(x-\mu)^2)}](https://s0.wp.com/latex.php?latex=%7Bp%28x+%5Cmid+%5Ctheta%29+%5Cpropto+%5Cexp%28%5Cfrac%7B%5Cmu+x%7D%7B%5Csigma%5E2%7D-%5Cfrac%7Bx%5E2%7D%7B2%5Csigma%5E2%7D%29+%5Cpropto+%5Cexp%28-%5Cfrac%7B1%7D%7B2%5Csigma%5E2%7D%28x-%5Cmu%29%5E2%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). We therefore see that Gaussian distributions are an exponential family for ![{\phi(x) = \left[ \begin{array}{c} x \\ x^2 \end{array} \right]}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%28x%29+%3D+%5Cleft%5B+%5Cbegin%7Barray%7D%7Bc%7D+x+%5C%5C+x%5E2+%5Cend%7Barray%7D+%5Cright%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).
2. *Poisson distributions.* Let ![{\phi(x) = [x]}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%28x%29+%3D+%5Bx%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{h(x) = \left\{\begin{array}{ccc} \frac{1}{x!} & : & x \in \{0,1,2,\ldots\} \\ 0 & : & \mathrm{else} \end{array}\right.}](https://s0.wp.com/latex.php?latex=%7Bh%28x%29+%3D+%5Cleft%5C%7B%5Cbegin%7Barray%7D%7Bccc%7D+%5Cfrac%7B1%7D%7Bx%21%7D+%26+%3A+%26+x+%5Cin+%5C%7B0%2C1%2C2%2C%5Cldots%5C%7D+%5C%5C+0+%26+%3A+%26+%5Cmathrm%7Belse%7D+%5Cend%7Barray%7D%5Cright.%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Then ![{p(k \mid \theta) \propto \frac{1}{k!}\exp(\theta x)}](https://s0.wp.com/latex.php?latex=%7Bp%28k+%5Cmid+%5Ctheta%29+%5Cpropto+%5Cfrac%7B1%7D%7Bk%21%7D%5Cexp%28%5Ctheta+x%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). If we let ![{\theta_1 = \log(\lambda)}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta_1+%3D+%5Clog%28%5Clambda%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) then we get ![{p(k \mid \theta) \propto \frac{\lambda^k}{k!}}](https://s0.wp.com/latex.php?latex=%7Bp%28k+%5Cmid+%5Ctheta%29+%5Cpropto+%5Cfrac%7B%5Clambda%5Ek%7D%7Bk%21%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002); we thus see that Poisson distributions are also an exponential family.
3. *Multinomial distributions.* Suppose that ![{X = \{1,2,\ldots,n\}}](https://s0.wp.com/latex.php?latex=%7BX+%3D+%5C%7B1%2C2%2C%5Cldots%2Cn%5C%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Let ![{\phi(k)}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%28k%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) be an ![{n}](https://s0.wp.com/latex.php?latex=%7Bn%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)-dimensional vector whose ![{k}](https://s0.wp.com/latex.php?latex=%7Bk%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)th element is ![{1}](https://s0.wp.com/latex.php?latex=%7B1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and where all other elements are zero. Then ![{p(k \mid \theta) \propto \exp(\theta_k) \propto \frac{\exp(\theta_k)}{\sum_{k=1}^n \exp(\theta_k)}}](https://s0.wp.com/latex.php?latex=%7Bp%28k+%5Cmid+%5Ctheta%29+%5Cpropto+%5Cexp%28%5Ctheta_k%29+%5Cpropto+%5Cfrac%7B%5Cexp%28%5Ctheta_k%29%7D%7B%5Csum_%7Bk%3D1%7D%5En+%5Cexp%28%5Ctheta_k%29%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). If ![{\theta_k = \log P(x=k)}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta_k+%3D+%5Clog+P%28x%3Dk%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), then we obtain an arbitrary multinomial distribution. Therefore, multinomial distributions are also an exponential family.

**2. Sufficient Statistics**

A *statistic* of a random variable ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is any deterministic function of that variable. For instance, if ![{X = [X_1,\ldots,X_n]^T}](https://s0.wp.com/latex.php?latex=%7BX+%3D+%5BX_1%2C%5Cldots%2CX_n%5D%5ET%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a vector of Gaussian random variables, then the sample mean ![{\hat{\mu} := (X_1+\ldots+X_n)/n}](https://s0.wp.com/latex.php?latex=%7B%5Chat%7B%5Cmu%7D+%3A%3D+%28X_1%2B%5Cldots%2BX_n%29%2Fn%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and sample variance ![{\hat{\sigma}^2 := (X_1^2+\cdots+X_n^2)/n-(X_1+\cdots+X_n)^2/n^2}](https://s0.wp.com/latex.php?latex=%7B%5Chat%7B%5Csigma%7D%5E2+%3A%3D+%28X_1%5E2%2B%5Ccdots%2BX_n%5E2%29%2Fn-%28X_1%2B%5Ccdots%2BX_n%29%5E2%2Fn%5E2%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) are both statistics.

Let ![{\mathcal{F}}](https://s0.wp.com/latex.php?latex=%7B%5Cmathcal%7BF%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) be a family of distributions parameterized by ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002), and let ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) be a random variable with distribution given by some unknown ![{\theta_0}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta_0%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Then a vector ![{T(X)}](https://s0.wp.com/latex.php?latex=%7BT%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) of statistics are called *sufficient statistics* for ![{\theta_0}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta_0%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) if they contain all possible information about ![{\theta_0}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta_0%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), that is, for any function ![{f}](https://s0.wp.com/latex.php?latex=%7Bf%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), we have

![\displaystyle \mathbb{E}[f(X) \mid T(X) = T_0, \theta = \theta_0] = S(f,T_0), \ \ \ \ \ (5)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cmathbb%7BE%7D%5Bf%28X%29+%5Cmid+T%28X%29+%3D+T_0%2C+%5Ctheta+%3D+%5Ctheta_0%5D+%3D+S%28f%2CT_0%29%2C+%5C+%5C+%5C+%5C+%5C+%285%29&bg=f0f0f0&fg=000000&s=0&c=20201002)

for some function ![{S}](https://s0.wp.com/latex.php?latex=%7BS%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) that has no dependence on ![{\theta_0}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta_0%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).

For instance, let ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) be a vector of ![{n}](https://s0.wp.com/latex.php?latex=%7Bn%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) independent Gaussian random variables ![{X_1,\ldots,X_n}](https://s0.wp.com/latex.php?latex=%7BX_1%2C%5Cldots%2CX_n%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) with unknown mean ![{\mu}](https://s0.wp.com/latex.php?latex=%7B%5Cmu%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and variance ![{\sigma}](https://s0.wp.com/latex.php?latex=%7B%5Csigma%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). It turns out that ![{T(X) := [\hat{\mu},\hat{\sigma}^2]}](https://s0.wp.com/latex.php?latex=%7BT%28X%29+%3A%3D+%5B%5Chat%7B%5Cmu%7D%2C%5Chat%7B%5Csigma%7D%5E2%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a sufficient statistic for ![{\mu}](https://s0.wp.com/latex.php?latex=%7B%5Cmu%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{\sigma}](https://s0.wp.com/latex.php?latex=%7B%5Csigma%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). 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 ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) has a probability density function ![{p(X \mid \theta)}](https://s0.wp.com/latex.php?latex=%7Bp%28X+%5Cmid+%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Then the statistics ![{T(X)}](https://s0.wp.com/latex.php?latex=%7BT%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) are sufficient for ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) if and only if ![{p(X \mid \theta)}](https://s0.wp.com/latex.php?latex=%7Bp%28X+%5Cmid+%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) can be written in the form*
>
>
>
> ![\displaystyle p(X \mid \theta) = h(X)g_\theta(T(X)). \ \ \ \ \ (6)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+p%28X+%5Cmid+%5Ctheta%29+%3D+h%28X%29g_%5Ctheta%28T%28X%29%29.+%5C+%5C+%5C+%5C+%5C+%286%29&bg=f0f0f0&fg=000000&s=0&c=20201002)
>
>
>
>
> In other words, the probability of ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) can be factored into a part that does not depend on ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002), and a part that depends on ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) only via ![{T(X)}](https://s0.wp.com/latex.php?latex=%7BT%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).
>
>

What is going on here, intuitively? If ![{p(X \mid \theta)}](https://s0.wp.com/latex.php?latex=%7Bp%28X+%5Cmid+%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) depended only on ![{T(X)}](https://s0.wp.com/latex.php?latex=%7BT%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), then ![{T(X)}](https://s0.wp.com/latex.php?latex=%7BT%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) would definitely be a sufficient statistic. But that isn’t the only way for ![{T(X)}](https://s0.wp.com/latex.php?latex=%7BT%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) to be a sufficient statistic — ![{p(X \mid \theta)}](https://s0.wp.com/latex.php?latex=%7Bp%28X+%5Cmid+%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) could also just not depend on ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) at all, in which case ![{T(X)}](https://s0.wp.com/latex.php?latex=%7BT%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) would trivially be a sufficient statistic (as would anything else). The Fisher-Neyman theorem essentially says that the only way in which ![{T(X)}](https://s0.wp.com/latex.php?latex=%7BT%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) can be a sufficient statistic is if its density is a product of these two cases.

*Proof:* If ([6](https://jsteinhardt.wordpress.com/feed/?paged=3#eqnfisher-neyman)) holds, then we can check that ([5](https://jsteinhardt.wordpress.com/feed/?paged=3#eqnsuff-def)) is satisfied:

![\displaystyle \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} ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cbegin%7Barray%7D%7Brcl%7D+%5Cmathbb%7BE%7D%5Bf%28X%29+%5Cmid+T%28X%29+%3D+T_0%2C+%5Ctheta+%3D+%5Ctheta_0%5D+%26%3D%26+%5Cfrac%7B%5Cint_%7BT%28X%29+%3D+T_0%7D+f%28X%29+dp%28X+%5Cmid+%5Ctheta%3D%5Ctheta_0%29%7D%7B%5Cint_%7BT%28X%29+%3D+T_0%7D+dp%28X+%5Cmid+%5Ctheta%3D%5Ctheta_0%29%7D%5C%5C+%5C%5C+%26%3D%26+%5Cfrac%7B%5Cint_%7BT%28X%29%3DT_0%7D+f%28X%29h%28X%29g_%5Ctheta%28T_0%29+dX%7D%7B%5Cint_%7BT%28X%29%3DT_0%7D+h%28X%29g_%5Ctheta%28T_0%29+dX%7D%5C%5C+%5C%5C+%26%3D%26+%5Cfrac%7B%5Cint_%7BT%28X%29%3DT_0%7D+f%28X%29h%28X%29dX%7D%7B%5Cint_%7BT%28X%29%3DT_0%7D+h%28X%29+dX%7D%2C+%5Cend%7Barray%7D+&bg=f0f0f0&fg=000000&s=0&c=20201002)

where the right-hand-side has no dependence on ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002).

On the other hand, if we compute ![{\mathbb{E}[f(X) \mid T(X) = T_0, \theta = \theta_0]}](https://s0.wp.com/latex.php?latex=%7B%5Cmathbb%7BE%7D%5Bf%28X%29+%5Cmid+T%28X%29+%3D+T_0%2C+%5Ctheta+%3D+%5Ctheta_0%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) for an arbitrary density ![{p(X)}](https://s0.wp.com/latex.php?latex=%7Bp%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), we get

![\displaystyle \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} ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cbegin%7Barray%7D%7Brcl%7D+%5Cmathbb%7BE%7D%5Bf%28X%29+%5Cmid+T%28X%29+%3D+T_0%2C+%5Ctheta+%3D+%5Ctheta_0%5D+%26%3D%26+%5Cint_%7BT%28X%29+%3D+T_0%7D+f%28X%29+%5Cfrac%7Bp%28X+%5Cmid+%5Ctheta%3D%5Ctheta_0%29%7D%7B%5Cint_%7BT%28X%29%3DT_0%7D+p%28X+%5Cmid+%5Ctheta%3D%5Ctheta_0%29+dX%7D+dX.+%5Cend%7Barray%7D+&bg=f0f0f0&fg=000000&s=0&c=20201002)

If the right-hand-side cannot depend on ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) for *any* choice of ![{f}](https://s0.wp.com/latex.php?latex=%7Bf%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), then the term that we multiply ![{f}](https://s0.wp.com/latex.php?latex=%7Bf%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) by must not depend on ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002); that is, ![{\frac{p(X \mid \theta=\theta_0)}{\int_{T(X) = T_0} p(X \mid \theta=\theta_0) dX}}](https://s0.wp.com/latex.php?latex=%7B%5Cfrac%7Bp%28X+%5Cmid+%5Ctheta%3D%5Ctheta_0%29%7D%7B%5Cint_%7BT%28X%29+%3D+T_0%7D+p%28X+%5Cmid+%5Ctheta%3D%5Ctheta_0%29+dX%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) must be some function ![{h_0(X, T_0)}](https://s0.wp.com/latex.php?latex=%7Bh_0%28X%2C+T_0%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) that depends only on ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{T_0}](https://s0.wp.com/latex.php?latex=%7BT_0%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and not on ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002). On the other hand, the denominator ![{\int_{T(X)=T_0} p(X \mid \theta=\theta_0) dX}](https://s0.wp.com/latex.php?latex=%7B%5Cint_%7BT%28X%29%3DT_0%7D+p%28X+%5Cmid+%5Ctheta%3D%5Ctheta_0%29+dX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) depends only on ![{\theta_0}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta_0%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{T_0}](https://s0.wp.com/latex.php?latex=%7BT_0%7D&bg=f0f0f0&fg=000000&s=0&c=20201002); call this dependence ![{g_{\theta_0}(T_0)}](https://s0.wp.com/latex.php?latex=%7Bg_%7B%5Ctheta_0%7D%28T_0%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Finally, note that ![{T_0}](https://s0.wp.com/latex.php?latex=%7BT_0%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a deterministic function of ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), so let ![{h(X) := h_0(X,T(X))}](https://s0.wp.com/latex.php?latex=%7Bh%28X%29+%3A%3D+h_0%28X%2CT%28X%29%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). We then see that ![{p(X \mid \theta=\theta_0) = h_0(X, T_0)g_{\theta_0}(T_0) = h(X)g_{\theta_0}(T(X))}](https://s0.wp.com/latex.php?latex=%7Bp%28X+%5Cmid+%5Ctheta%3D%5Ctheta_0%29+%3D+h_0%28X%2C+T_0%29g_%7B%5Ctheta_0%7D%28T_0%29+%3D+h%28X%29g_%7B%5Ctheta_0%7D%28T%28X%29%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), which is the same form as ([6](https://jsteinhardt.wordpress.com/feed/?paged=3#eqnfisher-neyman)), thus completing the proof of the theorem. ![\Box](https://s0.wp.com/latex.php?latex=%5CBox&bg=f0f0f0&fg=000000&s=0&c=20201002)

Now, let us apply the Fisher-Neyman theorem to exponential families. By definition, the density for an exponential family factors as

![\displaystyle p(x \mid \theta) = h(x)\exp(\theta^T\phi(x)-A(\theta)). ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+p%28x+%5Cmid+%5Ctheta%29+%3D+h%28x%29%5Cexp%28%5Ctheta%5ET%5Cphi%28x%29-A%28%5Ctheta%29%29.+&bg=f0f0f0&fg=000000&s=0&c=20201002)

If we let ![{T(x) = \phi(x)}](https://s0.wp.com/latex.php?latex=%7BT%28x%29+%3D+%5Cphi%28x%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{g_\theta(\phi(x)) = \exp(\theta^T\phi(x)-A(\theta))}](https://s0.wp.com/latex.php?latex=%7Bg_%5Ctheta%28%5Cphi%28x%29%29+%3D+%5Cexp%28%5Ctheta%5ET%5Cphi%28x%29-A%28%5Ctheta%29%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), then the Fisher-Neyman condition is met; therefore, ![{\phi(x)}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%28x%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a vector of sufficient statistics for the exponential family. In fact, we can go further:

> **Theorem 2**  *Let ![{X_1,\ldots,X_n}](https://s0.wp.com/latex.php?latex=%7BX_1%2C%5Cldots%2CX_n%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) be drawn independently from an exponential family distribution with fixed parameter ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002). Then the empirical expectation ![{\hat{\phi} := \frac{1}{n} \sum_{i=1}^n \phi(X_i)}](https://s0.wp.com/latex.php?latex=%7B%5Chat%7B%5Cphi%7D+%3A%3D+%5Cfrac%7B1%7D%7Bn%7D+%5Csum_%7Bi%3D1%7D%5En+%5Cphi%28X_i%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a sufficient statistic for ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002).*
>
>

*Proof:* The density for ![{X_1,\ldots,X_n}](https://s0.wp.com/latex.php?latex=%7BX_1%2C%5Cldots%2CX_n%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) given ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) is

![\displaystyle \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} ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cbegin%7Barray%7D%7Brcl%7D+p%28X_1%2C%5Cldots%2CX_n+%5Cmid+%5Ctheta%29+%26%3D%26+h%28X_1%29%5Ccdots+h%28X_n%29+%5Cexp%28%5Ctheta%5ET%5Csum_%7Bi%3D1%7D%5En+%5Cphi%28X_i%29+-+nA%28%5Ctheta%29%29+%5C%5C+%26%3D%26+h%28X_1%29%5Ccdots+h%28X_n%29%5Cexp%28n+%5B%5Chat%7B%5Cphi%7D-A%28%5Ctheta%29%5D%29.+%5Cend%7Barray%7D+&bg=f0f0f0&fg=000000&s=0&c=20201002)

Letting ![{h(X_1,\ldots,X_n) = h(X_1)\cdots h(X_n)}](https://s0.wp.com/latex.php?latex=%7Bh%28X_1%2C%5Cldots%2CX_n%29+%3D+h%28X_1%29%5Ccdots+h%28X_n%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{g_\theta(\hat{\phi}) = \exp(n[\hat{\phi}-A(\theta)])}](https://s0.wp.com/latex.php?latex=%7Bg_%5Ctheta%28%5Chat%7B%5Cphi%7D%29+%3D+%5Cexp%28n%5B%5Chat%7B%5Cphi%7D-A%28%5Ctheta%29%5D%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), we see that the Fisher-Neyman conditions are satisfied, so that ![{\hat{\phi}}](https://s0.wp.com/latex.php?latex=%7B%5Chat%7B%5Cphi%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is indeed a sufficient statistic. ![\Box](https://s0.wp.com/latex.php?latex=%5CBox&bg=f0f0f0&fg=000000&s=0&c=20201002)

Finally, we note (without proof) the same relationship as in the log-linear case to the gradient and Hessian of ![{p(X_1,\ldots,X_n \mid \theta)}](https://s0.wp.com/latex.php?latex=%7Bp%28X_1%2C%5Cldots%2CX_n+%5Cmid+%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) with respect to the model parameters:

> **Theorem 3**  *Again let ![{X_1,\ldots,X_n}](https://s0.wp.com/latex.php?latex=%7BX_1%2C%5Cldots%2CX_n%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) be drawn from an exponential family distribution with parameter ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002). Then the gradient of ![{p(X_1,\ldots,X_n \mid \theta)}](https://s0.wp.com/latex.php?latex=%7Bp%28X_1%2C%5Cldots%2CX_n+%5Cmid+%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) with respect to ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) is*
>
>
> ![\displaystyle n \times \left(\hat{\phi}-\mathbb{E}[\phi \mid \theta]\right) ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+n+%5Ctimes+%5Cleft%28%5Chat%7B%5Cphi%7D-%5Cmathbb%7BE%7D%5B%5Cphi+%5Cmid+%5Ctheta%5D%5Cright%29+&bg=f0f0f0&fg=000000&s=0&c=20201002)
>
>
> and the Hessian is
>
>
> ![\displaystyle n \times \left(\mathbb{E}[\phi \mid \theta]\mathbb{E}[\phi \mid \theta]^T - \mathbb{E}[\phi\phi^T \mid \theta]\right). ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+n+%5Ctimes+%5Cleft%28%5Cmathbb%7BE%7D%5B%5Cphi+%5Cmid+%5Ctheta%5D%5Cmathbb%7BE%7D%5B%5Cphi+%5Cmid+%5Ctheta%5D%5ET+-+%5Cmathbb%7BE%7D%5B%5Cphi%5Cphi%5ET+%5Cmid+%5Ctheta%5D%5Cright%29.+&bg=f0f0f0&fg=000000&s=0&c=20201002)
>
>
>

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](https://jsteinhardt.wordpress.com/2012/12/06/log-linear-models/) on parameter estimation).

**3. Moments of an Exponential Family**

If ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a real-valued random variable, then the *![{p}](https://s0.wp.com/latex.php?latex=%7Bp%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)th moment* of ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is ![{\mathbb{E}[X^p]}](https://s0.wp.com/latex.php?latex=%7B%5Cmathbb%7BE%7D%5BX%5Ep%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). In general, if ![{X = [X_1,\ldots,X_n]^T}](https://s0.wp.com/latex.php?latex=%7BX+%3D+%5BX_1%2C%5Cldots%2CX_n%5D%5ET%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a random variable on ![{\mathbb{R}^n}](https://s0.wp.com/latex.php?latex=%7B%5Cmathbb%7BR%7D%5En%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), then for every sequence ![{p_1,\ldots,p_n}](https://s0.wp.com/latex.php?latex=%7Bp_1%2C%5Cldots%2Cp_n%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) of non-negative integers, there is a corresponding moment ![{M_{p_1,\cdots,p_n} := \mathbb{E}[X_1^{p_1}\cdots X_n^{p_n}]}](https://s0.wp.com/latex.php?latex=%7BM_%7Bp_1%2C%5Ccdots%2Cp_n%7D+%3A%3D+%5Cmathbb%7BE%7D%5BX_1%5E%7Bp_1%7D%5Ccdots+X_n%5E%7Bp_n%7D%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).

In exponential families there is a very nice relationship between the normalization constant ![{A(\theta)}](https://s0.wp.com/latex.php?latex=%7BA%28%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and the moments of ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Before we establish this relationship, let us define the *moment generating function* of a random variable ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) as ![{f(\lambda) = \mathbb{E}[\exp(\lambda^TX)]}](https://s0.wp.com/latex.php?latex=%7Bf%28%5Clambda%29+%3D+%5Cmathbb%7BE%7D%5B%5Cexp%28%5Clambda%5ETX%29%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).

> **Lemma 4**  *The moment generating function for a random variable ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is equal to*
>
>
> ![\displaystyle \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!}. ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Csum_%7Bp_1%2C%5Cldots%2Cp_n%3D0%7D%5E%7B%5Cinfty%7D+M_%7Bp_1%2C%5Ccdots%2Cp_n%7D+%5Cfrac%7B%5Clambda_1%5E%7Bp_1%7D%5Ccdots+%5Clambda_n%5E%7Bp_n%7D%7D%7Bp_1%21%5Ccdots+p_n%21%7D.+&bg=f0f0f0&fg=000000&s=0&c=20201002)
>
>
>

The proof of Lemma [4](https://jsteinhardt.wordpress.com/feed/?paged=3#lemmgf) is a straightforward application of Taylor’s theorem, together with linearity of expectation (note that in one dimension, the expression in Lemma [4](https://jsteinhardt.wordpress.com/feed/?paged=3#lemmgf) would just be ![{\sum_{p=0}^{\infty} \mathbb{E}[X^p] \frac{\lambda^p}{p!}}](https://s0.wp.com/latex.php?latex=%7B%5Csum_%7Bp%3D0%7D%5E%7B%5Cinfty%7D+%5Cmathbb%7BE%7D%5BX%5Ep%5D+%5Cfrac%7B%5Clambda%5Ep%7D%7Bp%21%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)).

We now see why ![{f(\lambda)}](https://s0.wp.com/latex.php?latex=%7Bf%28%5Clambda%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is called the moment generating function: it is the [exponential generating function](http://en.wikipedia.org/wiki/Generating_function#Exponential_generating_function) for the moments of ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). The moment generating function for the sufficient statistics of an exponential family is particularly easy to compute:

> **Lemma 5**  *If ![{p(x \mid \theta) = h(x)\exp(\theta^T\phi(x)-A(\theta))}](https://s0.wp.com/latex.php?latex=%7Bp%28x+%5Cmid+%5Ctheta%29+%3D+h%28x%29%5Cexp%28%5Ctheta%5ET%5Cphi%28x%29-A%28%5Ctheta%29%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), then ![{\mathbb{E}[\exp(\lambda^T\phi(x))] = \exp(A(\theta+\lambda)-A(\theta))}](https://s0.wp.com/latex.php?latex=%7B%5Cmathbb%7BE%7D%5B%5Cexp%28%5Clambda%5ET%5Cphi%28x%29%29%5D+%3D+%5Cexp%28A%28%5Ctheta%2B%5Clambda%29-A%28%5Ctheta%29%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).*
>
>

*Proof:*

![\displaystyle \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} ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cbegin%7Barray%7D%7Brcl%7D+%5Cmathbb%7BE%7D%5B%5Cexp%28%5Clambda%5ETx%29%5D+%26%3D%26+%5Cint+%5Cexp%28%5Clambda%5ETx%29+p%28x+%5Cmid+%5Ctheta%29+dx+%5C%5C+%26%3D%26+%5Cint+%5Cexp%28%5Clambda%5ETx%29h%28x%29%5Cexp%28%5Ctheta%5ET%5Cphi%28x%29-A%28%5Ctheta%29%29+dx+%5C%5C+%26%3D%26+%5Cint+h%28x%29%5Cexp%28%28%5Ctheta%2B%5Clambda%29%5ET%5Cphi%28x%29-A%28%5Ctheta%29%29+dx+%5C%5C+%26%3D%26+%5Cint+h%28x%29%5Cexp%28%28%5Ctheta%2B%5Clambda%29%5ET%5Cphi%28x%29-A%28%5Ctheta%2B%5Clambda%29%29dx+%5Ctimes+%5Cexp%28A%28%5Ctheta%2B%5Clambda%29-A%28%5Ctheta%29%29+%5C%5C+%26%3D%26+%5Cint+p%28x+%5Cmid+%5Ctheta%2B%5Clambda%29+dx+%5Ctimes+%5Cexp%28A%28%5Ctheta%2B%5Clambda%29-A%28%5Ctheta%29%29+%5C%5C+%26%3D%26+%5Cexp%28A%28%5Ctheta%2B%5Clambda%29-A%28%5Ctheta%29%29%2C+%5Cend%7Barray%7D+&bg=f0f0f0&fg=000000&s=0&c=20201002)

where the last step uses the fact that ![{p(x \mid \theta+\lambda)}](https://s0.wp.com/latex.php?latex=%7Bp%28x+%5Cmid+%5Ctheta%2B%5Clambda%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a probability density and hence ![{\int p(x \mid \theta+\lambda) dx = 1}](https://s0.wp.com/latex.php?latex=%7B%5Cint+p%28x+%5Cmid+%5Ctheta%2B%5Clambda%29+dx+%3D+1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). ![\Box](https://s0.wp.com/latex.php?latex=%5CBox&bg=f0f0f0&fg=000000&s=0&c=20201002)

Now, by Lemma [4](https://jsteinhardt.wordpress.com/feed/?paged=3#lemmgf), ![{M_{p_1,\cdots,p_n}}](https://s0.wp.com/latex.php?latex=%7BM_%7Bp_1%2C%5Ccdots%2Cp_n%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is just the ![{(p_1,\ldots,p_n)}](https://s0.wp.com/latex.php?latex=%7B%28p_1%2C%5Cldots%2Cp_n%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) coefficient in the Taylor series for the moment generating function ![{f(\lambda)}](https://s0.wp.com/latex.php?latex=%7Bf%28%5Clambda%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), and hence we can compute ![{M_{p_1,\cdots,p_n}}](https://s0.wp.com/latex.php?latex=%7BM_%7Bp_1%2C%5Ccdots%2Cp_n%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) as ![{\frac{\partial^{p_1+\cdots+p_n} f(\lambda)}{\partial^{p_1}\lambda_1\cdots \partial^{p_n}\lambda_n}}](https://s0.wp.com/latex.php?latex=%7B%5Cfrac%7B%5Cpartial%5E%7Bp_1%2B%5Ccdots%2Bp_n%7D+f%28%5Clambda%29%7D%7B%5Cpartial%5E%7Bp_1%7D%5Clambda_1%5Ccdots+%5Cpartial%5E%7Bp_n%7D%5Clambda_n%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Combining this with Lemma [5](https://jsteinhardt.wordpress.com/feed/?paged=3#lemmgf-exp) gives us a closed-form expression for ![{M_{p_1,\cdots,p_n}}](https://s0.wp.com/latex.php?latex=%7BM_%7Bp_1%2C%5Ccdots%2Cp_n%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) in terms of the normalization constant ![{A(\theta)}](https://s0.wp.com/latex.php?latex=%7BA%28%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002):

> **Lemma 6**  *The moments of an exponential family can be computed as*
>
>
> ![\displaystyle 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}. ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+M_%7Bp_1%2C%5Cldots%2Cp_n%7D+%3D+%5Cfrac%7B%5Cpartial%5E%7Bp_1%2B%5Ccdots%2Bp_n%7D+%5Cexp%28A%28%5Ctheta%2B%5Clambda%29-A%28%5Ctheta%29%29%7D%7B%5Cpartial%5E%7Bp_1%7D%5Clambda_1%5Ccdots+%5Cpartial%5E%7Bp_n%7D%5Clambda_n%7D.+&bg=f0f0f0&fg=000000&s=0&c=20201002)
>
>
>

For those who prefer [cumulants](http://en.wikipedia.org/wiki/Cumulant) to moments, I will note that there is a version of Lemma [6](https://jsteinhardt.wordpress.com/feed/?paged=3#lemexp-moment) for cumulants with an even simpler formula.

**Exercise:** Use Lemma [6](https://jsteinhardt.wordpress.com/feed/?paged=3#lemexp-moment) to compute ![{\mathbb{E}[X^6]}](https://s0.wp.com/latex.php?latex=%7B%5Cmathbb%7BE%7D%5BX%5E6%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), where ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a Gaussian with mean ![{\mu}](https://s0.wp.com/latex.php?latex=%7B%5Cmu%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and variance ![{\sigma^2}](https://s0.wp.com/latex.php?latex=%7B%5Csigma%5E2%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).

**4. Conjugate Priors**

Given a family of distributions ![{p(X \mid \theta)}](https://s0.wp.com/latex.php?latex=%7Bp%28X+%5Cmid+%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), a *conjugate prior family* ![{p(\theta \mid \alpha)}](https://s0.wp.com/latex.php?latex=%7Bp%28%5Ctheta+%5Cmid+%5Calpha%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a family that has the property that

![\displaystyle p(\theta \mid X, \alpha) = p(\theta \mid \alpha') ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+p%28%5Ctheta+%5Cmid+X%2C+%5Calpha%29+%3D+p%28%5Ctheta+%5Cmid+%5Calpha%27%29+&bg=f0f0f0&fg=000000&s=0&c=20201002)

for some ![{\alpha'}](https://s0.wp.com/latex.php?latex=%7B%5Calpha%27%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) depending on ![{\alpha}](https://s0.wp.com/latex.php?latex=%7B%5Calpha%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). In other words, if the prior over ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) lies in the conjugate family, and we observe ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), then the posterior over ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) 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:

1. (Gaussian-Gaussian) Let ![{p(X \mid \mu) \propto \exp((X-\mu)^2/2)}](https://s0.wp.com/latex.php?latex=%7Bp%28X+%5Cmid+%5Cmu%29+%5Cpropto+%5Cexp%28%28X-%5Cmu%29%5E2%2F2%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), and let ![{p(\mu \mid \mu_0, \sigma_0) \propto \exp((\mu-\mu_0)^2/2\sigma_0^2)}](https://s0.wp.com/latex.php?latex=%7Bp%28%5Cmu+%5Cmid+%5Cmu_0%2C+%5Csigma_0%29+%5Cpropto+%5Cexp%28%28%5Cmu-%5Cmu_0%29%5E2%2F2%5Csigma_0%5E2%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Then, by Bayes’ rule,

![\displaystyle \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} ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cbegin%7Barray%7D%7Brcl%7D+p%28%5Cmu+%5Cmid+X%3Dx%2C+%5Cmu_0%2C+%5Csigma_0%29+%26%5Cpropto+%5Cexp%28%28x-%5Cmu%29%5E2%2F2%29%5Cexp%28%28%5Cmu-%5Cmu_0%29%5E2%2F2%5Csigma_0%5E2%29+%5C%5C+%26%3D+%26%5Cexp%5Cleft%28%5Cfrac%7B%28%5Cmu-%5Cmu_0%29%5E2%2B%5Csigma_0%5E2%28%5Cmu-x%29%5E2%7D%7B2%5Csigma_0%5E2%7D%5Cright%29+%5C%5C+%26%5Cpropto%26+%5Cexp%5Cleft%28%5Cfrac%7B%281%2B%5Csigma_0%29%5E2%5Cmu%5E2-2%28%5Cmu_0%2B%5Csigma_0%5E2x%29%5Cmu%7D%7B2%5Csigma_0%5E2%7D%5Cright%29+%5C%5C+%26%5Cpropto%26+%5Cexp%5Cleft%28%5Cfrac%7B%5Cmu%5E2-2%5Cfrac%7B%5Cmu_0%2Bx%5Csigma_0%5E2%7D%7B1%2B%5Csigma_0%5E2%7D%5Cmu%7D%7B2%5Csigma_0%5E2%2F%281%2B%5Csigma_0%5E2%29%7D%5Cright%29+%5C%5C+%26%5Cpropto%26+%5Cexp%5Cleft%28%5Cfrac%7B%28%5Cmu-%28%5Cmu_0%2Bx%5Csigma_0%5E2%29%2F%281%2B%5Csigma_0%5E2%29%29%5E2%7D%7B2%5Csigma_0%5E2%2F%281%2B%5Csigma_0%5E2%29%7D%5Cright%29+%5C%5C+%26%5Cpropto%26+p%5Cleft%28%5Cmu+%5Cmid+%5Cfrac%7B%5Cmu_0%2Bx%5Csigma_0%5E2%7D%7B1%2B%5Csigma_0%5E2%7D%2C+%5Cfrac%7B%5Csigma_0%7D%7B%5Csqrt%7B1%2B%5Csigma_0%5E2%7D%7D%5Cright%29.+%5Cend%7Barray%7D+&bg=f0f0f0&fg=000000&s=0&c=20201002)

Therefore, ![{\mu_0, \sigma_0}](https://s0.wp.com/latex.php?latex=%7B%5Cmu_0%2C+%5Csigma_0%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) parameterize a family of priors over ![{\mu}](https://s0.wp.com/latex.php?latex=%7B%5Cmu%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) that is conjugate to ![{X \mid \mu}](https://s0.wp.com/latex.php?latex=%7BX+%5Cmid+%5Cmu%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).

* (Beta-Bernoulli) Let ![{X \in \{0,1\}}](https://s0.wp.com/latex.php?latex=%7BX+%5Cin+%5C%7B0%2C1%5C%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), ![{\theta \in [0,1]}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta+%5Cin+%5B0%2C1%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), ![{p(X=1 \mid \theta) = \theta}](https://s0.wp.com/latex.php?latex=%7Bp%28X%3D1+%5Cmid+%5Ctheta%29+%3D+%5Ctheta%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), and ![{p(\theta \mid \alpha, \beta) \propto \theta^{\alpha-1}(1-\theta)^{\beta-1}}](https://s0.wp.com/latex.php?latex=%7Bp%28%5Ctheta+%5Cmid+%5Calpha%2C+%5Cbeta%29+%5Cpropto+%5Ctheta%5E%7B%5Calpha-1%7D%281-%5Ctheta%29%5E%7B%5Cbeta-1%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). The distribution over ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) given ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) is then called a *Bernoulli distribution*, and that of ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) given ![{\alpha}](https://s0.wp.com/latex.php?latex=%7B%5Calpha%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{\beta}](https://s0.wp.com/latex.php?latex=%7B%5Cbeta%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is called a *beta distribution*. Note that ![{p(X\mid \theta)}](https://s0.wp.com/latex.php?latex=%7Bp%28X%5Cmid+%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) can also be written as ![{\theta^X(1-\theta)^{1-X}}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta%5EX%281-%5Ctheta%29%5E%7B1-X%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). From this, we see that the family of beta distributions is a conjugate prior to the family of Bernoulli distributions, since

![\displaystyle \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} ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cbegin%7Barray%7D%7Brcl%7D+p%28%5Ctheta+%5Cmid+X%3Dx%2C+%5Calpha%2C+%5Cbeta%29+%26%5Cpropto%26+%5Ctheta%5Ex%281-%5Ctheta%29%5E%7B1-x%7D+%5Ctimes+%5Ctheta%5E%7B%5Calpha-1%7D%281-%5Ctheta%29%5E%7B%5Cbeta-1%7D+%5C%5C+%26%3D%26+%5Ctheta%5E%7B%5Calpha%2Bx-1%7D%281-%5Ctheta%29%5E%7B%5Cbeta%2B%281-x%29-1%7D+%5C%5C+%26%5Cpropto%26+p%28%5Ctheta+%5Cmid+%5Calpha%2Bx%2C+%5Cbeta%2B%281-x%29%29.+%5Cend%7Barray%7D+&bg=f0f0f0&fg=000000&s=0&c=20201002)

* (Gamma-Poisson) Let ![{p(X=k \mid \lambda) = \frac{\lambda^k}{e^{\lambda}k!}}](https://s0.wp.com/latex.php?latex=%7Bp%28X%3Dk+%5Cmid+%5Clambda%29+%3D+%5Cfrac%7B%5Clambda%5Ek%7D%7Be%5E%7B%5Clambda%7Dk%21%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) for ![{k \in \mathbb{Z}_{\geq 0}}](https://s0.wp.com/latex.php?latex=%7Bk+%5Cin+%5Cmathbb%7BZ%7D_%7B%5Cgeq+0%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Let ![{p(\lambda \mid \alpha, \beta) \propto \lambda^{\alpha-1}\exp(-\beta \lambda)}](https://s0.wp.com/latex.php?latex=%7Bp%28%5Clambda+%5Cmid+%5Calpha%2C+%5Cbeta%29+%5Cpropto+%5Clambda%5E%7B%5Calpha-1%7D%5Cexp%28-%5Cbeta+%5Clambda%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). As noted before, the distribution for ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) given ![{\lambda}](https://s0.wp.com/latex.php?latex=%7B%5Clambda%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is called a *Poisson distribution*; the distribution for ![{\lambda}](https://s0.wp.com/latex.php?latex=%7B%5Clambda%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) given ![{\alpha}](https://s0.wp.com/latex.php?latex=%7B%5Calpha%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{\beta}](https://s0.wp.com/latex.php?latex=%7B%5Cbeta%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) 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 ![{\lambda}](https://s0.wp.com/latex.php?latex=%7B%5Clambda%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), and so we need to include it in our calculations:
![\displaystyle \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} ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cbegin%7Barray%7D%7Brcl%7D+p%28%5Clambda+%5Cmid+X%3Dk%2C+%5Calpha%2C+%5Cbeta%29+%26%5Cpropto%26+%5Cfrac%7B%5Clambda%5Ek%7D%7Be%5E%7B%5Clambda%7Dk%21%7D+%5Ctimes+%5Clambda%5E%7B%5Calpha-1%7D%5Cexp%28-%5Cbeta%5Clambda%29+%5C%5C+%26%5Cpropto%26+%5Clambda%5E%7B%5Calpha%2Bk-1%7D%5Cexp%28-%28%5Cbeta%2B1%29%5Clambda%29+%5C%5C+%26%5Cpropto%26+p%28%5Clambda+%5Cmid+%5Calpha%2Bk%2C+%5Cbeta%2B1%29.+%5Cend%7Barray%7D+&bg=f0f0f0&fg=000000&s=0&c=20201002)

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 ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) 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 ![{p(x \mid \theta) = h(x)\exp(\theta^T\phi(x)-A(\theta))}](https://s0.wp.com/latex.php?latex=%7Bp%28x+%5Cmid+%5Ctheta%29+%3D+h%28x%29%5Cexp%28%5Ctheta%5ET%5Cphi%28x%29-A%28%5Ctheta%29%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) be an exponential family. Then ![{p(\theta \mid \eta, \kappa) \propto h_2(\theta)\exp\left(\eta^T\theta-\kappa A(\theta)\right)}](https://s0.wp.com/latex.php?latex=%7Bp%28%5Ctheta+%5Cmid+%5Ceta%2C+%5Ckappa%29+%5Cpropto+h_2%28%5Ctheta%29%5Cexp%5Cleft%28%5Ceta%5ET%5Ctheta-%5Ckappa+A%28%5Ctheta%29%5Cright%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a conjugate prior for ![{x \mid \theta}](https://s0.wp.com/latex.php?latex=%7Bx+%5Cmid+%5Ctheta%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) for any choice of ![{h_2}](https://s0.wp.com/latex.php?latex=%7Bh_2%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). The update formula is ![{p(\theta \mid x, \eta, \kappa) = p(\theta \mid \eta+\phi(x), \kappa+1)}](https://s0.wp.com/latex.php?latex=%7Bp%28%5Ctheta+%5Cmid+x%2C+%5Ceta%2C+%5Ckappa%29+%3D+p%28%5Ctheta+%5Cmid+%5Ceta%2B%5Cphi%28x%29%2C+%5Ckappa%2B1%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Furthermore, ![{\theta \mid \phi, \kappa}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta+%5Cmid+%5Cphi%2C+%5Ckappa%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is itself an exponential family, with sufficient statistics ![{[\theta; A(\theta)]}](https://s0.wp.com/latex.php?latex=%7B%5B%5Ctheta%3B+A%28%5Ctheta%29%5D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).*
>
>

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 ![{p(\theta \mid \eta, \kappa)}](https://s0.wp.com/latex.php?latex=%7Bp%28%5Ctheta+%5Cmid+%5Ceta%2C+%5Ckappa%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) will be tractable; however, in many cases the conjugate prior given by Theorem [7](https://jsteinhardt.wordpress.com/feed/?paged=3#thmconjugate) is a well-behaved family. See [this Wikipedia page](http://en.wikipedia.org/wiki/Conjugate_prior#Table_of_conjugate_distributions) 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 ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) with density ![{p(X)}](https://s0.wp.com/latex.php?latex=%7Bp%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is ![{\mathbb{E}[-\log p(X)] := -\int p(x)\log(p(x)) dx}](https://s0.wp.com/latex.php?latex=%7B%5Cmathbb%7BE%7D%5B-%5Clog+p%28X%29%5D+%3A%3D+-%5Cint+p%28x%29%5Clog%28p%28x%29%29+dx%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). 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 ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) with maximum entropy such that ![{\mathbb{E}[\phi(X)] = T}](https://s0.wp.com/latex.php?latex=%7B%5Cmathbb%7BE%7D%5B%5Cphi%28X%29%5D+%3D+T%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) lies in the exponential family with sufficient statistic ![{\phi(X)}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{h(X) = 1}](https://s0.wp.com/latex.php?latex=%7Bh%28X%29+%3D+1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).*
>
>

Proving this fully rigorously requires the calculus of variations; I will instead give the “physicist’s proof”. *Proof:* } Let ![{p(X)}](https://s0.wp.com/latex.php?latex=%7Bp%28X%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) be the density for ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Then we can view ![{p}](https://s0.wp.com/latex.php?latex=%7Bp%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) as the solution to the constrained maximization problem:

![\displaystyle \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} ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cbegin%7Barray%7D%7Brcl%7D+%5Cmathrm%7Bmaximize%7D+%26%26+-%5Cint+p%28X%29+%5Clog+p%28X%29+dX+%5C%5C+%5Cmathrm%7Bsubject+%5C+to%7D+%26%26+%5Cint+p%28X%29+dX+%3D+1+%5C%5C+%26%26+%5Cint+p%28X%29+%5Cphi%28X%29+dX+%3D+T.+%5Cend%7Barray%7D+&bg=f0f0f0&fg=000000&s=0&c=20201002)

By the method of Lagrange multipliers, there exist ![{\alpha}](https://s0.wp.com/latex.php?latex=%7B%5Calpha%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{\lambda}](https://s0.wp.com/latex.php?latex=%7B%5Clambda%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) such that

![\displaystyle \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. ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7Bd%7D%7Bdp%7D%5Cleft%28-%5Cint+p%28X%29%5Clog+p%28X%29+dX+-+%5Calpha+%5B%5Cint+p%28X%29+dX-1%5D+-+%5Clambda%5ET%5B%5Cint+%5Cphi%28X%29+p%28X%29+dX-T%5D%5Cright%29+%3D+0.+&bg=f0f0f0&fg=000000&s=0&c=20201002)

This simplifies to:

![\displaystyle -\log p(X) - 1 - \alpha -\lambda^T \phi(X) = 0, ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+-%5Clog+p%28X%29+-+1+-+%5Calpha+-%5Clambda%5ET+%5Cphi%28X%29+%3D+0%2C+&bg=f0f0f0&fg=000000&s=0&c=20201002)

which implies

![\displaystyle p(X) = \exp(-1-\alpha-\lambda^T\phi(X)) ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+p%28X%29+%3D+%5Cexp%28-1-%5Calpha-%5Clambda%5ET%5Cphi%28X%29%29+&bg=f0f0f0&fg=000000&s=0&c=20201002)

for some ![{\alpha}](https://s0.wp.com/latex.php?latex=%7B%5Calpha%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{\lambda}](https://s0.wp.com/latex.php?latex=%7B%5Clambda%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). In particular, if we let ![{\lambda = -\theta}](https://s0.wp.com/latex.php?latex=%7B%5Clambda+%3D+-%5Ctheta%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{\alpha = A(\theta)-1}](https://s0.wp.com/latex.php?latex=%7B%5Calpha+%3D+A%28%5Ctheta%29-1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), then we recover the exponential family with ![{h(X) = 1}](https://s0.wp.com/latex.php?latex=%7Bh%28X%29+%3D+1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), as claimed. ![\Box](https://s0.wp.com/latex.php?latex=%5CBox&bg=f0f0f0&fg=000000&s=0&c=20201002)

**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.

Exponential Families


Algebra trick of the day

I’ve decided to start recording algebra tricks as I end up using them. Today I actually have two tricks, but they end up being used together a lot. I don’t know if they have more formal names, but I call them the “trace trick” and the “rank 1 relaxation”.

Suppose that we want to maximize the [Rayleigh quotient](http://en.wikipedia.org/wiki/Rayleigh_quotient) ![\frac{x^TAx}{x^Tx}](https://s0.wp.com/latex.php?latex=%5Cfrac%7Bx%5ETAx%7D%7Bx%5ETx%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) of a matrix ![A](https://s0.wp.com/latex.php?latex=A&bg=f0f0f0&fg=555555&s=0&c=20201002). There are many reasons we might want to do this, for instance of ![A](https://s0.wp.com/latex.php?latex=A&bg=f0f0f0&fg=555555&s=0&c=20201002) is symmetric then the maximum corresponds to the largest eigenvalue. There are also many ways to do this, and the one that I’m about to describe is definitely not the most efficient, but it has the advantage of being flexible, in that it easily generalizes to constrained maximizations, etc.

The first observation is that ![\frac{x^TAx}{x^Tx}](https://s0.wp.com/latex.php?latex=%5Cfrac%7Bx%5ETAx%7D%7Bx%5ETx%7D&bg=f0f0f0&fg=555555&s=0&c=20201002) is homogeneous, meaning that scaling ![x](https://s0.wp.com/latex.php?latex=x&bg=f0f0f0&fg=555555&s=0&c=20201002) doesn’t affect the result. So, we can assume without loss of generality that ![x^Tx = 1](https://s0.wp.com/latex.php?latex=x%5ETx+%3D+1&bg=f0f0f0&fg=555555&s=0&c=20201002), and we end up with the optimization problem:

maximize ![x^TAx](https://s0.wp.com/latex.php?latex=x%5ETAx&bg=f0f0f0&fg=555555&s=0&c=20201002)

subject to ![x^Tx = 1](https://s0.wp.com/latex.php?latex=x%5ETx+%3D+1&bg=f0f0f0&fg=555555&s=0&c=20201002)

This is where the trace trick comes in. Recall that the trace of a matrix is the sum of its diagonal entries. We are going to use two facts: first, the trace of a number is just the number itself. Second, trace(AB) = trace(BA). (Note, however, that trace(ABC) is *not* in general equal to trace(BAC), although trace(ABC) *is* equal to trace(CAB).) We use these two properties as follows — first, we re-write the optimization problem as:

maximize ![Trace(x^TAx)](https://s0.wp.com/latex.php?latex=Trace%28x%5ETAx%29&bg=f0f0f0&fg=555555&s=0&c=20201002)

subject to ![Trace(x^Tx) = 1](https://s0.wp.com/latex.php?latex=Trace%28x%5ETx%29+%3D+1&bg=f0f0f0&fg=555555&s=0&c=20201002)

Second, we re-write it again using the invariance of trace under cyclic permutations:

maximize ![Trace(Axx^T)](https://s0.wp.com/latex.php?latex=Trace%28Axx%5ET%29&bg=f0f0f0&fg=555555&s=0&c=20201002)

subject to ![Trace(xx^T) = 1](https://s0.wp.com/latex.php?latex=Trace%28xx%5ET%29+%3D+1&bg=f0f0f0&fg=555555&s=0&c=20201002)

Now we make the substitution ![X = xx^T](https://s0.wp.com/latex.php?latex=X+%3D+xx%5ET&bg=f0f0f0&fg=555555&s=0&c=20201002):

maximize ![Trace(AX)](https://s0.wp.com/latex.php?latex=Trace%28AX%29&bg=f0f0f0&fg=555555&s=0&c=20201002)

subject to ![Trace(X) = 1, X = xx^T](https://s0.wp.com/latex.php?latex=Trace%28X%29+%3D+1%2C+X+%3D+xx%5ET&bg=f0f0f0&fg=555555&s=0&c=20201002)

Finally, note that a matrix ![X](https://s0.wp.com/latex.php?latex=X&bg=f0f0f0&fg=555555&s=0&c=20201002) can be written as ![xx^T](https://s0.wp.com/latex.php?latex=xx%5ET&bg=f0f0f0&fg=555555&s=0&c=20201002) if and only if ![X](https://s0.wp.com/latex.php?latex=X&bg=f0f0f0&fg=555555&s=0&c=20201002) is positive semi-definite and has rank 1. Therefore, we can further write this as

maximize ![Trace(AX)](https://s0.wp.com/latex.php?latex=Trace%28AX%29&bg=f0f0f0&fg=555555&s=0&c=20201002)

subject to ![Trace(X) = 1, Rank(X) = 1, X \succeq 0](https://s0.wp.com/latex.php?latex=Trace%28X%29+%3D+1%2C+Rank%28X%29+%3D+1%2C+X+%5Csucceq+0&bg=f0f0f0&fg=555555&s=0&c=20201002)

Aside from the rank 1 constraint, this would be a [semidefinite program](http://en.wikipedia.org/wiki/Semidefinite_programming#Equivalent_formulations), a type of problem that can be solved efficiently. What happens if we drop the rank 1 constraint? Then I claim that the solution to this program would be the same as if I had kept the constraint in! Why is this? Let’s look at the eigendecomposition of ![X](https://s0.wp.com/latex.php?latex=X&bg=f0f0f0&fg=555555&s=0&c=20201002), written as ![\sum_{i=1}^n \lambda_i x_ix_i^T](https://s0.wp.com/latex.php?latex=%5Csum_%7Bi%3D1%7D%5En+%5Clambda_i+x_ix_i%5ET&bg=f0f0f0&fg=555555&s=0&c=20201002), with ![\lambda_i \geq 0](https://s0.wp.com/latex.php?latex=%5Clambda_i+%5Cgeq+0&bg=f0f0f0&fg=555555&s=0&c=20201002) (by positive semidefiniteness) and ![\sum_{i=1}^n \lambda_i = 1](https://s0.wp.com/latex.php?latex=%5Csum_%7Bi%3D1%7D%5En+%5Clambda_i+%3D+1&bg=f0f0f0&fg=555555&s=0&c=20201002) (by the trace constraint). Let’s also look at ![Trace(AX)](https://s0.wp.com/latex.php?latex=Trace%28AX%29&bg=f0f0f0&fg=555555&s=0&c=20201002), which can be written as ![\sum_{i=1}^n \lambda_i Trace(Ax_ix_i^T)](https://s0.wp.com/latex.php?latex=%5Csum_%7Bi%3D1%7D%5En+%5Clambda_i+Trace%28Ax_ix_i%5ET%29&bg=f0f0f0&fg=555555&s=0&c=20201002). Since ![Trace(AX)](https://s0.wp.com/latex.php?latex=Trace%28AX%29&bg=f0f0f0&fg=555555&s=0&c=20201002) is just a convex combination of the ![Trace(Ax_ix_i^T)](https://s0.wp.com/latex.php?latex=Trace%28Ax_ix_i%5ET%29&bg=f0f0f0&fg=555555&s=0&c=20201002), we might as well have just picked ![X](https://s0.wp.com/latex.php?latex=X&bg=f0f0f0&fg=555555&s=0&c=20201002) to be ![x_ix_i^T](https://s0.wp.com/latex.php?latex=x_ix_i%5ET&bg=f0f0f0&fg=555555&s=0&c=20201002), where ![i](https://s0.wp.com/latex.php?latex=i&bg=f0f0f0&fg=555555&s=0&c=20201002) is chosen to maximize ![Trace(Ax_ix_i^T)](https://s0.wp.com/latex.php?latex=Trace%28Ax_ix_i%5ET%29&bg=f0f0f0&fg=555555&s=0&c=20201002). If we set that ![\lambda_i](https://s0.wp.com/latex.php?latex=%5Clambda_i&bg=f0f0f0&fg=555555&s=0&c=20201002) to 1 and all the rest to 0, then we maintain all of the constraints while increasing ![Trace(AX)](https://s0.wp.com/latex.php?latex=Trace%28AX%29&bg=f0f0f0&fg=555555&s=0&c=20201002), meaning that we couldn’t have been at the optimum value of ![X](https://s0.wp.com/latex.php?latex=X&bg=f0f0f0&fg=555555&s=0&c=20201002) unless ![n](https://s0.wp.com/latex.php?latex=n&bg=f0f0f0&fg=555555&s=0&c=20201002) was equal to 1. What we have shown, then, is that the rank of ![X](https://s0.wp.com/latex.php?latex=X&bg=f0f0f0&fg=555555&s=0&c=20201002) must be 1, so that the rank 1 constraint was unnecessary.

Technically, ![X](https://s0.wp.com/latex.php?latex=X&bg=f0f0f0&fg=555555&s=0&c=20201002) could be a linear combination of rank 1 matrices that all have the same value of ![Trace(AX)](https://s0.wp.com/latex.php?latex=Trace%28AX%29&bg=f0f0f0&fg=555555&s=0&c=20201002), but in that case we could just pick any one of those matrices. So what I have really shown is that *at least one* optimal point has rank 1, and we can recover such a point from any solution, even if the original solution was not rank 1.

Here is a problem that uses a similar trick. Suppose we want to find ![x](https://s0.wp.com/latex.php?latex=x&bg=f0f0f0&fg=555555&s=0&c=20201002) that simultaneously satisfies the equations:

![b_i = |a_i^Tx|^2](https://s0.wp.com/latex.php?latex=b_i+%3D+%7Ca_i%5ETx%7C%5E2&bg=f0f0f0&fg=555555&s=0&c=20201002)

for each ![i = 1,\ldots,n](https://s0.wp.com/latex.php?latex=i+%3D+1%2C%5Cldots%2Cn&bg=f0f0f0&fg=555555&s=0&c=20201002) (this example was inspired from the recent NIPS paper by [Ohlsson, Yang, Dong, and Sastry](http://www.eecs.berkeley.edu/~yang/paper/nips2012.pdf), although the idea itself goes at least back to [Candes, Strohmer, and Voroninski](http://arxiv.org/abs/1109.4499)). Note that this is basically equivalent to solving a system of linear equations where we only know each equation up to a sign (or a phase, in the complex case). Therefore, in general, this problem will not have a unique solution. To ensure the solution is unique, let us assume the very strong condition that whenever ![a_i^TVa_i = 0](https://s0.wp.com/latex.php?latex=a_i%5ETVa_i+%3D+0&bg=f0f0f0&fg=555555&s=0&c=20201002) for all ![i = 1,\ldots,n](https://s0.wp.com/latex.php?latex=i+%3D+1%2C%5Cldots%2Cn&bg=f0f0f0&fg=555555&s=0&c=20201002), the matrix ![V](https://s0.wp.com/latex.php?latex=V&bg=f0f0f0&fg=555555&s=0&c=20201002) must itself be zero (note: Candes et al. get away with a much weaker condition). Given this, can we phrase the problem as a semidefinite program? I highly recommend trying to solve this problem on your own, or at least reducing it to a rank-constrained SDP, so I’ll include the solution below a fold.

**Solution.** We can, as before, re-write the equations as:

![b_i = Trace(a_ia_i^Txx^T)](https://s0.wp.com/latex.php?latex=b_i+%3D+Trace%28a_ia_i%5ETxx%5ET%29&bg=f0f0f0&fg=555555&s=0&c=20201002)

and further write this as

![b_i = Trace(a_ia_i^TX), X \succeq 0, rank(X) = 1](https://s0.wp.com/latex.php?latex=b_i+%3D+Trace%28a_ia_i%5ETX%29%2C+X+%5Csucceq+0%2C+rank%28X%29+%3D+1&bg=f0f0f0&fg=555555&s=0&c=20201002)

As before, drop the rank 1 constraint and let ![X = \sum_{j=1}^m \lambda_j x_jx_j^T](https://s0.wp.com/latex.php?latex=X+%3D+%5Csum_%7Bj%3D1%7D%5Em+%5Clambda_j+x_jx_j%5ET&bg=f0f0f0&fg=555555&s=0&c=20201002). Then we get:

![b_i = \sum_{j=1}^m Trace(a_ia_i^Tx_jx_j^T)\lambda_j](https://s0.wp.com/latex.php?latex=b_i+%3D+%5Csum_%7Bj%3D1%7D%5Em+Trace%28a_ia_i%5ETx_jx_j%5ET%29%5Clambda_j&bg=f0f0f0&fg=555555&s=0&c=20201002),

which we can re-write as ![b_i = a_i^T\left(\sum_{j=1}^m \lambda_jx_jx_j^T\right)a_i](https://s0.wp.com/latex.php?latex=b_i+%3D+a_i%5ET%5Cleft%28%5Csum_%7Bj%3D1%7D%5Em+%5Clambda_jx_jx_j%5ET%5Cright%29a_i&bg=f0f0f0&fg=555555&s=0&c=20201002). But if ![x^*](https://s0.wp.com/latex.php?latex=x%5E%2A&bg=f0f0f0&fg=555555&s=0&c=20201002) is the true solution, then we also know that ![b_i = a_i^Tx^*(x^*)^Ta_i](https://s0.wp.com/latex.php?latex=b_i+%3D+a_i%5ETx%5E%2A%28x%5E%2A%29%5ETa_i&bg=f0f0f0&fg=555555&s=0&c=20201002), so that ![a_i^T\left(-x^*(x^*)^T+\sum_{j=1}^m \lambda_jx_jx_j^T\right) = 0](https://s0.wp.com/latex.php?latex=a_i%5ET%5Cleft%28-x%5E%2A%28x%5E%2A%29%5ET%2B%5Csum_%7Bj%3D1%7D%5Em+%5Clambda_jx_jx_j%5ET%5Cright%29+%3D+0&bg=f0f0f0&fg=555555&s=0&c=20201002) for all ![i](https://s0.wp.com/latex.php?latex=i&bg=f0f0f0&fg=555555&s=0&c=20201002). By the non-degeneracy assumption, this implies that

![x^*(x^*)^T = \sum_{j=1}^m \lambda_jx_jx_j^T](https://s0.wp.com/latex.php?latex=x%5E%2A%28x%5E%2A%29%5ET+%3D+%5Csum_%7Bj%3D1%7D%5Em+%5Clambda_jx_jx_j%5ET&bg=f0f0f0&fg=555555&s=0&c=20201002),

so in particular ![X = x^*(x^*)^T](https://s0.wp.com/latex.php?latex=X+%3D+x%5E%2A%28x%5E%2A%29%5ET&bg=f0f0f0&fg=555555&s=0&c=20201002). Therefore, ![X = x^*(x^*)^T](https://s0.wp.com/latex.php?latex=X+%3D+x%5E%2A%28x%5E%2A%29%5ET&bg=f0f0f0&fg=555555&s=0&c=20201002) is the only solution to the semidefinite program even after dropping the rank constraint.

Algebra trick of the day


Log-Linear Models

I’ve spent most of my research career trying to build big, complex [nonparametric models](http://jmlr.csail.mit.edu/proceedings/papers/v22/steinhardt12/steinhardt12.pdf); however, I’ve more recently delved into the realm of natural language processing, where how awesome your model looks on paper is irrelevant compared to how well it models your data. In the spirit of this new work (and to lay the groundwork for a later post on NLP), I’d like to go over a family of models that I think is often overlooked due to not being terribly sexy (or at least, I overlooked it for a good while). This family is the family of log-linear models, which are models of the form:

![\displaystyle p(x \mid \theta) \propto e^{\phi(x)^T\theta}, ](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+p%28x+%5Cmid+%5Ctheta%29+%5Cpropto+e%5E%7B%5Cphi%28x%29%5ET%5Ctheta%7D%2C+&bg=f0f0f0&fg=000000&s=0&c=20201002)

where ![{\phi}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) maps a data point to a feature vector; they are called log-linear because the log of the probability is a linear function of ![{\phi(x)}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%28x%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). We refer to ![{\phi(x)^T\theta}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%28x%29%5ET%5Ctheta%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) as the *score* of ![{x}](https://s0.wp.com/latex.php?latex=%7Bx%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).

This model class might look fairly restricted at first, but the real magic comes in with the feature vector ![{\phi}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). In fact, every probabilistic model that is [absolutely continuous](http://en.wikipedia.org/wiki/Radon-Nikodym_theorem) with respect to Lebesgue measure can be represented as a log-linear model for sufficient choices of ![{\phi}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002). This is actually trivially true, as we can just take ![{\phi : X \rightarrow \mathbb{R}}](https://s0.wp.com/latex.php?latex=%7B%5Cphi+%3A+X+%5Crightarrow+%5Cmathbb%7BR%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) to be ![{\log p(x)}](https://s0.wp.com/latex.php?latex=%7B%5Clog+p%28x%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) to be ![{1}](https://s0.wp.com/latex.php?latex=%7B1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).

You might object to this choice of ![{\phi}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), since it maps into ![{\mathbb{R}}](https://s0.wp.com/latex.php?latex=%7B%5Cmathbb%7BR%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) rather than ![{\{0,1\}^n}](https://s0.wp.com/latex.php?latex=%7B%5C%7B0%2C1%5C%7D%5En%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), and feature vectors are typically discrete. However, we can do just as well by letting ![{\phi : X \rightarrow \{0,1\}^{\infty}}](https://s0.wp.com/latex.php?latex=%7B%5Cphi+%3A+X+%5Crightarrow+%5C%7B0%2C1%5C%7D%5E%7B%5Cinfty%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), where the ![{i}](https://s0.wp.com/latex.php?latex=%7Bi%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)th coordinate of ![{\phi(x)}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%28x%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is the ![{i}](https://s0.wp.com/latex.php?latex=%7Bi%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)th digit in the binary representation of ![{\log p(x)}](https://s0.wp.com/latex.php?latex=%7B%5Clog+p%28x%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), then let ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) be the vector ![{\left(\frac{1}{2},\frac{1}{4},\frac{1}{8},\ldots\right)}](https://s0.wp.com/latex.php?latex=%7B%5Cleft%28%5Cfrac%7B1%7D%7B2%7D%2C%5Cfrac%7B1%7D%7B4%7D%2C%5Cfrac%7B1%7D%7B8%7D%2C%5Cldots%5Cright%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).

It is important to distinguish between the ability to represent an arbitrary model as log-linear and the ability to represent an arbitrary *family* of models as a log-linear family (that is, as the set of models we get if we fix a choice of features ![{\phi}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and then vary ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002)). When we don’t know the correct model in advance and want to learn it, this latter consideration can be crucial. Below, I give two examples of model families and discuss how they fit (or do not fit) into the log-linear framework. **Important caveat:** in both of the models below, it is typically the case that at least some of the variables involved are unobserved. However, we will ignore this for now, and assume that, at least at training time, all of the variables are fully observed (in other words, we can see ![{x_i}](https://s0.wp.com/latex.php?latex=%7Bx_i%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{y_i}](https://s0.wp.com/latex.php?latex=%7By_i%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) in the hidden Markov model and we can see the full tree of productions in the probabilistic context free grammar).

**Hidden Markov Models.** A hidden Markov model, or HMM, is a model with *latent* (unobserved) variables ![{x_1,\ldots,x_n}](https://s0.wp.com/latex.php?latex=%7Bx_1%2C%5Cldots%2Cx_n%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) together with observed variables ![{y_1,\ldots,y_n}](https://s0.wp.com/latex.php?latex=%7By_1%2C%5Cldots%2Cy_n%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). The distribution for ![{y_i}](https://s0.wp.com/latex.php?latex=%7By_i%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) depends only on ![{x_i}](https://s0.wp.com/latex.php?latex=%7Bx_i%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), and the distribution for ![{x_i}](https://s0.wp.com/latex.php?latex=%7Bx_i%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) depends only on ![{x_{i-1}}](https://s0.wp.com/latex.php?latex=%7Bx_%7Bi-1%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) (in the sense that ![{x_i}](https://s0.wp.com/latex.php?latex=%7Bx_i%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is conditionally independent of ![{x_1,\ldots,x_{i-2}}](https://s0.wp.com/latex.php?latex=%7Bx_1%2C%5Cldots%2Cx_%7Bi-2%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) given ![{x_{i-1}}](https://s0.wp.com/latex.php?latex=%7Bx_%7Bi-1%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)). We can thus summarize the information in an HMM with the distributions ![{p(x_{i} = t \mid x_{i-1} = s)}](https://s0.wp.com/latex.php?latex=%7Bp%28x_%7Bi%7D+%3D+t+%5Cmid+x_%7Bi-1%7D+%3D+s%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{p(y_i = u \mid x_i = s)}](https://s0.wp.com/latex.php?latex=%7Bp%28y_i+%3D+u+%5Cmid+x_i+%3D+s%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).

We can express a hidden Markov model as a log-linear model by defining two classes of features: (i) features ![{\phi_{s,t}}](https://s0.wp.com/latex.php?latex=%7B%5Cphi_%7Bs%2Ct%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) that count the number of ![{i}](https://s0.wp.com/latex.php?latex=%7Bi%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) such that ![{x_{i-1} = s}](https://s0.wp.com/latex.php?latex=%7Bx_%7Bi-1%7D+%3D+s%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{x_i = t}](https://s0.wp.com/latex.php?latex=%7Bx_i+%3D+t%7D&bg=f0f0f0&fg=000000&s=0&c=20201002); and (ii) features ![{\psi_{s,u}}](https://s0.wp.com/latex.php?latex=%7B%5Cpsi_%7Bs%2Cu%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) that count the number of ![{i}](https://s0.wp.com/latex.php?latex=%7Bi%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) such that ![{x_i = s}](https://s0.wp.com/latex.php?latex=%7Bx_i+%3D+s%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{y_i = u}](https://s0.wp.com/latex.php?latex=%7By_i+%3D+u%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). While this choice of features yields a model family capable of expressing an arbitrary hidden Markov model, it is also capable of learning models that are not hidden Markov models. In particular, we would like to think of ![{\theta_{s,t}}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta_%7Bs%2Ct%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) (the index of ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) corresponding to ![{\phi_{s,t}}](https://s0.wp.com/latex.php?latex=%7B%5Cphi_%7Bs%2Ct%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)) as ![{\log p(x_i=t \mid x_{i-1}=s)}](https://s0.wp.com/latex.php?latex=%7B%5Clog+p%28x_i%3Dt+%5Cmid+x_%7Bi-1%7D%3Ds%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), but there is no constraint that ![{\sum_{t} \exp(\theta_{s,t}) = 1}](https://s0.wp.com/latex.php?latex=%7B%5Csum_%7Bt%7D+%5Cexp%28%5Ctheta_%7Bs%2Ct%7D%29+%3D+1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) for each ![{s}](https://s0.wp.com/latex.php?latex=%7Bs%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), whereas we do necessarily have ![{\sum_{t} p(x_i = t \mid x_{i-1}=s) = 1}](https://s0.wp.com/latex.php?latex=%7B%5Csum_%7Bt%7D+p%28x_i+%3D+t+%5Cmid+x_%7Bi-1%7D%3Ds%29+%3D+1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) for each ![{s}](https://s0.wp.com/latex.php?latex=%7Bs%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). If ![{n}](https://s0.wp.com/latex.php?latex=%7Bn%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is fixed, we still do obtain an HMM for any setting of ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002), although ![{\theta_{s,t}}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta_%7Bs%2Ct%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) will have no simple relationship with ![{\log p(x_i = t \mid x_{i-1} = s)}](https://s0.wp.com/latex.php?latex=%7B%5Clog+p%28x_i+%3D+t+%5Cmid+x_%7Bi-1%7D+%3D+s%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). Furthermore, the relationship depends on ![{n}](https://s0.wp.com/latex.php?latex=%7Bn%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), and will therefore not work if we care about multiple Markov chains with different lengths.

Is the ability to express models that are not HMMs good or bad? It depends. If we know for certain that our data satisfy the HMM assumption, then expanding our model family to include models that violate that assumption can only end up hurting us. If the data do not satisfy the HMM assumption, then increasing the size of the model family may allow us to overcome what would otherwise be a model mis-specification. I personally would prefer to have as much control as possible about what assumptions I make, so I tend to see the over-expressivity of HMMs as a bug rather than a feature.

**Probabilistic Context Free Grammars.** A probabilistic context free grammar, or PCFG, is simply a context free grammar where we place a probability distribution over the production rules for each non-terminal. For those unfamiliar with context free grammars, a *context free grammar* is specified by:

1. A set ![{\mathcal{S}}](https://s0.wp.com/latex.php?latex=%7B%5Cmathcal%7BS%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) of non-terminal symbols, including a distinguished *initial symbol* ![{E}](https://s0.wp.com/latex.php?latex=%7BE%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).
2. A set ![{\mathcal{T}}](https://s0.wp.com/latex.php?latex=%7B%5Cmathcal%7BT%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) of terminal symbols.
3. For each ![{s \in S}](https://s0.wp.com/latex.php?latex=%7Bs+%5Cin+S%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), one or more *production rules* of the form ![{s \mapsto w_1w_2\cdots w_k}](https://s0.wp.com/latex.php?latex=%7Bs+%5Cmapsto+w_1w_2%5Ccdots+w_k%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), where ![{k \geq 0}](https://s0.wp.com/latex.php?latex=%7Bk+%5Cgeq+0%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{w_i \in \mathcal{S} \cup \mathcal{T}}](https://s0.wp.com/latex.php?latex=%7Bw_i+%5Cin+%5Cmathcal%7BS%7D+%5Ccup+%5Cmathcal%7BT%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).

For instance, a context free grammar for arithmetic expressions might have ![{\mathcal{S} = \{E\}}](https://s0.wp.com/latex.php?latex=%7B%5Cmathcal%7BS%7D+%3D+%5C%7BE%5C%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), ![{\mathcal{T} = \{+,-,\times,/,(,)\} \cup \mathbb{R}}](https://s0.wp.com/latex.php?latex=%7B%5Cmathcal%7BT%7D+%3D+%5C%7B%2B%2C-%2C%5Ctimes%2C%2F%2C%28%2C%29%5C%7D+%5Ccup+%5Cmathbb%7BR%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), and the following production rules:

* ![{E \mapsto x}](https://s0.wp.com/latex.php?latex=%7BE+%5Cmapsto+x%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) for all ![{x \in \mathbb{R}}](https://s0.wp.com/latex.php?latex=%7Bx+%5Cin+%5Cmathbb%7BR%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)
* ![{E \mapsto E + E}](https://s0.wp.com/latex.php?latex=%7BE+%5Cmapsto+E+%2B+E%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)
* ![{E \mapsto E - E}](https://s0.wp.com/latex.php?latex=%7BE+%5Cmapsto+E+-+E%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)
* ![{E \mapsto E \times E}](https://s0.wp.com/latex.php?latex=%7BE+%5Cmapsto+E+%5Ctimes+E%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)
* ![{E \mapsto E / E}](https://s0.wp.com/latex.php?latex=%7BE+%5Cmapsto+E+%2F+E%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)
* ![{E \mapsto (E)}](https://s0.wp.com/latex.php?latex=%7BE+%5Cmapsto+%28E%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)

The *language* corresponding to a context free grammar is the set of all strings that can be obtained by starting from ![{E}](https://s0.wp.com/latex.php?latex=%7BE%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and applying production rules until we only have terminal symbols. The language corresponding to the above grammar is, in fact, the set of well-formed arithmetic expressions, such as ![{5-4-2}](https://s0.wp.com/latex.php?latex=%7B5-4-2%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), ![{2-3\times (4.3)}](https://s0.wp.com/latex.php?latex=%7B2-3%5Ctimes+%284.3%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), and ![{5/9927.12/(3-3\times 1)}](https://s0.wp.com/latex.php?latex=%7B5%2F9927.12%2F%283-3%5Ctimes+1%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002).

As mentioned above, a probabilistic context free grammar simply places a distribution over the production rules for any given non-terminal symbol. By repeatedly sampling from these distributions until we are left with only terminal symbols, we obtain a probability distribution over the language of the grammar.

We can represent a PCFG as a log-linear model by using a feature ![{\phi_r}](https://s0.wp.com/latex.php?latex=%7B%5Cphi_r%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) for each production rule ![{r}](https://s0.wp.com/latex.php?latex=%7Br%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). For instance, we have a feature that counts the number of times that the rule ![{E \mapsto E + E}](https://s0.wp.com/latex.php?latex=%7BE+%5Cmapsto+E+%2B+E%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) gets applied, and another feature that counts the number of times that ![{E \mapsto (E)}](https://s0.wp.com/latex.php?latex=%7BE+%5Cmapsto+%28E%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) gets applied. Such features yield a log-linear model family that contains all probabilistic context free grammars for a given (deterministic) context free grammar. However, it also contains additional models that do not correspond to PCFGs; this is because we run into the same problem as for HMMs, which is that the sum of ![{\exp(\theta_r)}](https://s0.wp.com/latex.php?latex=%7B%5Cexp%28%5Ctheta_r%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) over production rules of a given non-terminal does not necessarily add up to ![{1}](https://s0.wp.com/latex.php?latex=%7B1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). In fact, the problem is even worse here. For instance, suppose that ![{\theta_{E \mapsto E + E} = 0.1}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta_%7BE+%5Cmapsto+E+%2B+E%7D+%3D+0.1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) in the model above. Then the expression ![{E+E+E+E+E+E}](https://s0.wp.com/latex.php?latex=%7BE%2BE%2BE%2BE%2BE%2BE%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) gets a score of ![{0.5}](https://s0.wp.com/latex.php?latex=%7B0.5%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), and longer chains of ![{E}](https://s0.wp.com/latex.php?latex=%7BE%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)s get even higher scores. In particular, there is an infinite sequence of expressions with increasing scores and therefore the model doesn’t normalize (since the sum of the exponentiated scores of all possible productions is infinite).

So, log-linear models over-represent PCFGs in the same way as they over-represent HMMs, but the problems are even worse than before. Let’s ignore these issues for now, and suppose that we want to learn PCFGs with an *unknown* underlying CFG. To be a bit more concrete, suppose that we have a large collection of possible production rules for each non-terminal ![{s \in \mathcal{S}}](https://s0.wp.com/latex.php?latex=%7Bs+%5Cin+%5Cmathcal%7BS%7D%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), and we think that a small but unknown subset of those production rules should actually appear in the grammar. Then there is no way to encode this directly within the context of a log-linear model family, although we can encode such “sparsity constraints” using simple extensions to log-linear models (for instance, by adding a penalty for the number of non-zero entries in ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002)). So, we have found another way in which the log-linear representation is not entirely adequate.

**Conclusion.** Based on the examples above, we have seen that log-linear models have difficulty placing constraints on latent variables. This showed up in two different ways: first, we are unable to constrain subsets of variables to add up to ![{1}](https://s0.wp.com/latex.php?latex=%7B1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) (what I call “local normalization” constraints); second, we are unable to encode sparsity constraints within the model. In both of these cases, it is possible to extend the log-linear framework to address these sorts of constraints, although that is outside the scope of this post.

 **Parameter Estimation for Log-Linear Models**

I’ve explained what a log-linear model is, and partially characterized its representational power. I will now answer the practical question of how to estimate the parameters of a log-linear model (i.e., how to fit ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) based on observed data). Recall that a log-linear model places a distribution over a space ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) by choosing ![{\phi : X \rightarrow \mathbb{R}^n}](https://s0.wp.com/latex.php?latex=%7B%5Cphi+%3A+X+%5Crightarrow+%5Cmathbb%7BR%7D%5En%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and ![{\theta \in \mathbb{R}^n}](https://s0.wp.com/latex.php?latex=%7B%5Ctheta+%5Cin+%5Cmathbb%7BR%7D%5En%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and defining

![\displaystyle p(x \mid \theta) \propto \exp(\phi(x)^T\theta)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+p%28x+%5Cmid+%5Ctheta%29+%5Cpropto+%5Cexp%28%5Cphi%28x%29%5ET%5Ctheta%29&bg=f0f0f0&fg=555555&s=0&c=20201002)

More precisely (assuming ![{X}](https://s0.wp.com/latex.php?latex=%7BX%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) is a discrete space), we have

![\displaystyle p(x \mid \theta) = \frac{\exp(\phi(x)^T\theta)}{\sum_{x' \in X} \exp(\phi(x')^T\theta)}](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+p%28x+%5Cmid+%5Ctheta%29+%3D+%5Cfrac%7B%5Cexp%28%5Cphi%28x%29%5ET%5Ctheta%29%7D%7B%5Csum_%7Bx%27+%5Cin+X%7D+%5Cexp%28%5Cphi%28x%27%29%5ET%5Ctheta%29%7D&bg=f0f0f0&fg=555555&s=0&c=20201002)

Given observations ![{x_1,\ldots,x_n}](https://s0.wp.com/latex.php?latex=%7Bx_1%2C%5Cldots%2Cx_n%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), which we assume to be independent given ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002), our goal is to choose ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) maximizing ![{p(x_1,\ldots,x_n \mid \theta)}](https://s0.wp.com/latex.php?latex=%7Bp%28x_1%2C%5Cldots%2Cx_n+%5Cmid+%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), or, equivalently, ![{\log p(x_1,\ldots,x_n \mid \theta)}](https://s0.wp.com/latex.php?latex=%7B%5Clog+p%28x_1%2C%5Cldots%2Cx_n+%5Cmid+%5Ctheta%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002). In equations, we want

![\displaystyle \theta^* = \arg\max\limits_{\theta} \sum_{i=1}^n \left[\phi(x_i)^T\theta - \log\left(\sum_{x \in X} \exp(\phi(x)^T\theta)\right) \right]. \ \ \ \ \ (1)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Ctheta%5E%2A+%3D+%5Carg%5Cmax%5Climits_%7B%5Ctheta%7D+%5Csum_%7Bi%3D1%7D%5En+%5Cleft%5B%5Cphi%28x_i%29%5ET%5Ctheta+-+%5Clog%5Cleft%28%5Csum_%7Bx+%5Cin+X%7D+%5Cexp%28%5Cphi%28x%29%5ET%5Ctheta%29%5Cright%29+%5Cright%5D.+%5C+%5C+%5C+%5C+%5C+%281%29&bg=f0f0f0&fg=000000&s=0&c=20201002)

We typically use gradient methods (such as [gradient descent](http://en.wikipedia.org/wiki/Gradient_descent), [stochastic gradient descent](http://en.wikipedia.org/wiki/Stochastic_gradient_descent), or [L-BFGS](http://en.wikipedia.org/wiki/Limited-memory_BFGS)) to minimize the right-hand side of ([1](https://jsteinhardt.wordpress.com/feed/?paged=3#eqnobj)). If we compute the gradient of ([1](https://jsteinhardt.wordpress.com/feed/?paged=3#eqnobj)) then we get:

![\displaystyle \sum_{i=1}^n \left(\phi(x_i)-\frac{\sum_{x \in X} \exp(\phi(x)^T\theta)\phi(x)}{\sum_{x \in X} \exp(\phi(x)^T\theta)}\right). \ \ \ \ \ (2)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Csum_%7Bi%3D1%7D%5En+%5Cleft%28%5Cphi%28x_i%29-%5Cfrac%7B%5Csum_%7Bx+%5Cin+X%7D+%5Cexp%28%5Cphi%28x%29%5ET%5Ctheta%29%5Cphi%28x%29%7D%7B%5Csum_%7Bx+%5Cin+X%7D+%5Cexp%28%5Cphi%28x%29%5ET%5Ctheta%29%7D%5Cright%29.+%5C+%5C+%5C+%5C+%5C+%282%29&bg=f0f0f0&fg=000000&s=0&c=20201002)

We can re-write ([2](https://jsteinhardt.wordpress.com/feed/?paged=3#eqngrad)) in the following more compact form:

![\displaystyle \sum_{i=1}^n \left(\phi(x_i) - \mathbb{E}[\phi(x) \mid \theta]\right). \ \ \ \ \ (3)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Csum_%7Bi%3D1%7D%5En+%5Cleft%28%5Cphi%28x_i%29+-+%5Cmathbb%7BE%7D%5B%5Cphi%28x%29+%5Cmid+%5Ctheta%5D%5Cright%29.+%5C+%5C+%5C+%5C+%5C+%283%29&bg=f0f0f0&fg=000000&s=0&c=20201002)

In other words, the contribution of each training example ![{x_i}](https://s0.wp.com/latex.php?latex=%7Bx_i%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) to the gradient is the extent to which the features values for ![{x_i}](https://s0.wp.com/latex.php?latex=%7Bx_i%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) exceed their expected values conditioned on ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002).

One important consideration for such gradient-based numerical optimizers is *convexity*. If the objective function we are trying to minimize is convex (or concave), then gradient methods are guaranteed to converge to the global optimum. If the objective function is non-convex, then a gradient-based approach (or any other type of local search) may converge to a *local optimum* that is very far from the global optimum. In order to assess convexity, we compute the *Hessian* (matrix of second derivatives) and check whether it is positive definite. (In this case, we actually care about concavity, so we want the Hessian to be negative definite.) We can compute the Hessian by differentiating ([2](https://jsteinhardt.wordpress.com/feed/?paged=3#eqngrad)), which gives us

![\displaystyle n \times \left[\left(\frac{\sum_{x \in X} \exp(\phi(x)^T\theta)\phi(x)}{\sum_{x \in X} \exp(\phi(x)^T\theta)}\right)\left(\frac{\sum_{x \in X} \exp(\phi(x)^T\theta)\phi(x)}{\sum_{x \in X} \exp(\phi(x)^T\theta)}\right)^T-\frac{\sum_{x \in X} \exp(\phi(x)^T\theta)\phi(x)\phi(x)^T}{\sum_{x \in X} \exp(\phi(x)^T \theta)}\right]. \ \ \ \ \ (4)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+n+%5Ctimes+%5Cleft%5B%5Cleft%28%5Cfrac%7B%5Csum_%7Bx+%5Cin+X%7D+%5Cexp%28%5Cphi%28x%29%5ET%5Ctheta%29%5Cphi%28x%29%7D%7B%5Csum_%7Bx+%5Cin+X%7D+%5Cexp%28%5Cphi%28x%29%5ET%5Ctheta%29%7D%5Cright%29%5Cleft%28%5Cfrac%7B%5Csum_%7Bx+%5Cin+X%7D+%5Cexp%28%5Cphi%28x%29%5ET%5Ctheta%29%5Cphi%28x%29%7D%7B%5Csum_%7Bx+%5Cin+X%7D+%5Cexp%28%5Cphi%28x%29%5ET%5Ctheta%29%7D%5Cright%29%5ET-%5Cfrac%7B%5Csum_%7Bx+%5Cin+X%7D+%5Cexp%28%5Cphi%28x%29%5ET%5Ctheta%29%5Cphi%28x%29%5Cphi%28x%29%5ET%7D%7B%5Csum_%7Bx+%5Cin+X%7D+%5Cexp%28%5Cphi%28x%29%5ET+%5Ctheta%29%7D%5Cright%5D.+%5C+%5C+%5C+%5C+%5C+%284%29&bg=f0f0f0&fg=000000&s=0&c=20201002)

Again, we can re-write this more compactly as

![\displaystyle n\times \left(\mathbb{E}[\phi(x) \mid \theta]\mathbb{E}[\phi(x) \mid \theta]^T - \mathbb{E}[\phi(x)\phi(x)^T \mid \theta]\right). \ \ \ \ \ (5)](https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+n%5Ctimes+%5Cleft%28%5Cmathbb%7BE%7D%5B%5Cphi%28x%29+%5Cmid+%5Ctheta%5D%5Cmathbb%7BE%7D%5B%5Cphi%28x%29+%5Cmid+%5Ctheta%5D%5ET+-+%5Cmathbb%7BE%7D%5B%5Cphi%28x%29%5Cphi%28x%29%5ET+%5Cmid+%5Ctheta%5D%5Cright%29.+%5C+%5C+%5C+%5C+%5C+%285%29&bg=f0f0f0&fg=000000&s=0&c=20201002)

The term inside the parentheses of ([5](https://jsteinhardt.wordpress.com/feed/?paged=3#eqnhess2)) is exactly the negative of the [covariance matrix](http://en.wikipedia.org/wiki/Covariance_matrix) of ![{\phi(x)}](https://s0.wp.com/latex.php?latex=%7B%5Cphi%28x%29%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) given ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002), and is therefore necessarily negative definite, so the objective function we are trying to minimize is indeed concave, which, as noted before, implies that our gradient methods will always reach the global optimum.

 **Regularization and Concavity**

We may in practice wish to encode additional prior knowledge about ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) in our model, especially if the dimensionality of ![\theta](https://s0.wp.com/latex.php?latex=%5Ctheta&bg=f0f0f0&fg=000000&s=0&c=20201002) is large relative to the amount of data we have. Can we do this and still maintain concavity? The answer in many cases is yes: since the [![{L^p}](https://s0.wp.com/latex.php?latex=%7BL%5Ep%7D&bg=f0f0f0&fg=000000&s=0&c=20201002)-norm](http://en.wikipedia.org/wiki/Lp_space#The_p-norm_in_finite_dimensions) is convex for all ![{p \geq 1}](https://s0.wp.com/latex.php?latex=%7Bp+%5Cgeq+1%7D&bg=f0f0f0&fg=000000&s=0&c=20201002), we can add an ![{L^p}](https://s0.wp.com/latex.php?latex=%7BL%5Ep%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) penalty to the objective for any such ![{p}](https://s0.wp.com/latex.php?latex=%7Bp%7D&bg=f0f0f0&fg=000000&s=0&c=20201002) and still have a concave objective function.

 **Conclusion**

Log-linear models provide a universal representation for individual probability distributions, but not for arbitrary families of probability distributions (for instance, due to the inability to capture local normalization constraints or sparsity constraints). However, for the families they do express, parameter optimization can be performed efficiently due to a likelihood function that is log-concave in its parameters. Log-linear models also have tie-ins to many other beautiful areas of statistics, such as exponential families, which will be the subject of the next post.

Log-Linear Models