Post · 13 min read· pp. 194–202

Introduction to Exponential Family

Introduction

Exponential family is a set of probability distributions whose probability density function (or probability mass function, for the case of a discrete distribution) can be expressed in the form

p(x∣η)=h(x)exp⁡{T(x)⊤η−A(η)}p(x|\eta) = h(x) \exp \big\{ T(x)^{\top} \eta - A(\eta) \big\}

where η\eta is the parameter for the probability density function, which is independent of xx, and A(η)A(\eta) is also independent of xx. η\eta is also called the natural parameter of the distribution, T(x)T(x) is also called the sufficient statistics, A(η)A(\eta) is also called the log normalizer (we will see why), h(x)h(x) is also called the base measurement, and the above expression is also called the natural form of the distribution.

Many common distributions, such as normal distribution, categorical distribution, gamma distribution, Dirichlet distribution, etc, belong to the exponential family.

In this blog post, I will use normal distribution as an example to show how to derive h(x)h(x), T(x)T(x), η\eta and A(η)A(\eta). I will also talk about some of the properties of the exponential family that we will use for variational inference.

Log Normalizer

Source of Name

Because p(x∣η)p(x|\eta) is a probability density, the integral of probability density is 1.

∫xp(x∣η)dx=∫xh(x)exp⁡{T(x)⊤η−A(η)}dx=∫xh(x)exp⁡{T(x)⊤η}dxexp⁡{A(η)}=1\begin{aligned} \int\limits_{x} p(x|\eta) dx &= \int\limits_{x} h(x) \exp \big\{ T(x)^{\top} \eta - A(\eta) \big\} dx \\ &= \frac{ \int\limits_{x} h(x) \exp \big\{ T(x)^{\top} \eta \big\} dx}{\exp\{ A(\eta) \}} =1 \end{aligned}

We then have

A(η)=log⁡[∫xh(x)exp⁡{T(x)⊤η}dx]A(\eta) = \log \bigg[ \int\limits_{x} h(x) \exp \big\{ T(x)^{\top} \eta \big\} dx \bigg]

Therefore A(η)A(\eta) is a log normalizer for h(x)exp⁡{T(x)⊤η}h(x) \exp\{ T(x)^{\top} \eta\}.

Derivative of Log Normalizer

The derivative of the log normalizer has an important property, which will be used in many other applications, such as variational inference.

ddηA(η)=Ex∼p(x∣η)[T(x)]\frac{d}{d \eta} A(\eta) = \mathbb{E}_{x \sim p(x|\eta)} [T(x)]

Let’s see how to derive this. Because

∫xp(x∣η)dx=∫xh(x)exp⁡{T(x)⊤η−A(η)}dx=1\int\limits_{x} p(x|\eta) dx = \int\limits_{x} h(x) \exp \big\{ T(x)^{\top} \eta - A(\eta) \big\} dx = 1

We take the derivative with respect to η\eta,

ddη∫xp(x∣η)dx=ddη∫xh(x)exp⁡{T(x)⊤η−A(η)}dx=0\frac{d}{d \eta} \int\limits_{x} p(x|\eta) dx = \frac{d}{d \eta} \int\limits_{x} h(x) \exp \big\{ T(x)^{\top} \eta - A(\eta) \big\} dx = 0

We then use a special case of Leibniz Integral Rule.

ddη∫xp(x∣η)dx=ddη∫xh(x)exp⁡{T(x)⊤η−A(η)}dx=∫x∂∂η[h(x)exp⁡{T(x)⊤η−A(η)}]dx=∫xh(x)exp⁡{T(x)⊤η−A(η)}⏟p(x∣η)[T(x)−ddηA(η)]dx=∫xp(x∣η)T(x)−∫xp(x∣η)ddηA(η)dx=∫xp(x∣η)T(x)⏟Ex∼p(x∣η)[T(x)]−ddηA(η)∫xp(x∣η)dx⏟1=Ex∼p(x∣η)[T(x)]−ddηA(η)=0\begin{aligned} \frac{d}{d \eta} \int\limits_{x} p(x|\eta) dx &= \frac{d}{d \eta} \int\limits_{x} h(x) \exp \big\{ T(x)^{\top} \eta - A(\eta) \big\} dx \\ &= \int\limits_{x} \frac{ \partial }{\partial \eta} \bigg[ h(x) \exp \big\{ T(x)^{\top} \eta - A(\eta) \big\} \bigg] dx\\ &= \int\limits_{x} \underbrace{ h(x) \exp \big\{ T(x)^{\top} \eta - A(\eta) \big\} }_{p(x|\eta)} [T(x) - \frac{d}{d \eta} A(\eta)] dx \\ &= \int\limits_{x} p(x|\eta) T(x) - \int\limits_{x} p(x|\eta) \frac{d}{d \eta} A(\eta) dx \\ &= \underbrace{ \int\limits_{x} p(x|\eta) T(x) }_{\mathbb{E}_{x \sim p(x|\eta)} [T(x)]} - \frac{d}{d \eta} A(\eta) \underbrace{ \int\limits_{x} p(x|\eta) dx }_{1} \\ &= \mathbb{E}_{x \sim p(x|\eta)} [T(x)] - \frac{d}{d \eta} A(\eta) \\ &= 0 \end{aligned}

Therefore,

ddηA(η)=Ex∼p(x∣η)[T(x)]\frac{d}{d \eta} A(\eta) = \mathbb{E}_{x \sim p(x|\eta)} [T(x)]

Conjugate Priors

All members of the exponential family have conjugate priors. If you don’t remember what conjugate prior is, please check my blog post on conjugate priors. Here I will give the proof of this theorem.

Given likelihood p(x∣β)p(x|\beta) (β\beta is its natural parameter) from any member of the exponential family, we have to find a prior p(β)p(\beta) that belongs to the same family of the posterior p(x∣β)p(x | \beta).

Because p(x∣β)p(x|\beta) is from the exponential family, we could write p(x∣β)p(x|\beta) in its natural form.

p(x∣β)=h(x)exp⁡{T(x)⊤β−A(β)}p(x|\beta) = h(x) \exp \big\{ T(x)^{\top} \beta - A(\beta) \big\}

Here we do not limit the size of β\beta. It could be β={β1,β2,⋯ ,βN}\beta = \{ \beta_1, \beta_2, \cdots, \beta_N \} and β\beta is a column vector.

We then assume that we could find a conjugate prior p(β)p(\beta) for the likelihood from the exponential family. We assume p(β)p(\beta) has the following natural form.

p(β)=h′(β)exp⁡{T′(β)⊤α−A′(α)}p(\beta) = h^{\prime}(\beta) \exp \big\{ T^{\prime}(\beta)^{\top} \alpha - A^{\prime}(\alpha) \big\}

where

T′(β)=[β−A(β)]T^{\prime}(\beta) = \begin{bmatrix} \beta \\ -A(\beta) \end{bmatrix}

Note that because β∈RN\beta \in \mathbb{R}^{N} and A(β)A(\beta) is a scalar, T′(β)∈RN+1T^{\prime}(\beta) \in \mathbb{R}^{N+1}. α\alpha is the natural parameter for p(β)p(\beta) and α∈RN+1\alpha \in \mathbb{R}^{N+1}. We denote α\alpha into two parts

α=[α1α2]\alpha = \begin{bmatrix} \alpha_1 \\ \alpha_2 \end{bmatrix}

where α1∈RN\alpha_1 \in \mathbb{R}^{N} and α2∈R1\alpha_2 \in \mathbb{R}^{1}.

According to Bayes’ theorem,

p(β∣x)=p(x∣β)p(β)p(x)∝p(x∣β)p(β)p(\beta | x) = \frac{p(x|\beta) p(\beta)}{p(x)} \propto p(x | \beta) p(\beta)

We use ∝\propto here because p(x)p(x) is a constant value to p(β∣x)p(\beta | x) thus will not change the family of p(x∣β)p(β)p(x | \beta) p(\beta).

p(β∣x)∝p(x∣β)p(β)∝h(x)exp⁡{T(x)⊤β−A(β)}h′(β)exp⁡{T′(β)⊤α−A′(α)}∝h′(β)exp⁡{T(x)⊤β−A(β)+T′(β)⊤α}∝h′(β)exp⁡{T(x)⊤β−A(β)+[β⊤α1−A(β)α2]}∝h′(β)exp⁡{T(x)⊤β−A(β)+[α1⊤β−A(β)α2]}∝h′(β)exp⁡{[T(x)⊤+α1⊤]β−A(β)(1+α2)}∝h′(β)exp⁡{[T(x)+α1]⊤β−(1+α2)A(β)}\begin{aligned} p(\beta | x) &\propto p(x | \beta) p(\beta) \\ &\propto h(x) \exp \big\{ T(x)^{\top} \beta - A(\beta) \big\} h^{\prime}(\beta) \exp \big\{ T^{\prime}(\beta)^{\top} \alpha - A^{\prime}(\alpha)\big\} \\ &\propto h^{\prime}(\beta) \exp \big\{ T(x)^{\top} \beta - A(\beta) + T^{\prime}(\beta)^{\top} \alpha \big\} \\ &\propto h^{\prime}(\beta) \exp \Big\{ T(x)^{\top} \beta - A(\beta) + \big[ \beta^{\top}\alpha_1 - A(\beta)\alpha_2 \big] \Big\} \\ &\propto h^{\prime}(\beta) \exp \Big\{ T(x)^{\top} \beta - A(\beta) + \big[ \alpha_1^{\top}\beta - A(\beta)\alpha_2 \big]\Big\} \\ &\propto h^{\prime}(\beta) \exp \Big\{ \big[ T(x)^{\top} + \alpha_1^{\top} \big] \beta - A(\beta) (1 + \alpha_2) \Big\} \\ &\propto h^{\prime}(\beta) \exp \Big\{ \big[ T(x) + \alpha_1 \big]^{\top} \beta - (1 + \alpha_2) A(\beta) \Big\} \\ \end{aligned}

We define

α^1=T(x)+α1α^2=(1+α2)α^=[α^1α^2]\hat{\alpha}_1 = T(x) + \alpha_1 \\ \hat{\alpha}_2 = (1 + \alpha_2) \\ \hat{\alpha} = \begin{bmatrix} \hat{\alpha}_1 \\ \hat{\alpha}_2 \end{bmatrix}

Then we have

p(β∣x)∝p(x∣β)p(β)∝h′(β)exp⁡{α^1⊤β−α^2A(β)}∝h′(β)exp⁡{[α^1α^2]⊤T′(β)}∝h′(β)exp⁡{T′(β)⊤[α^1α^2]}∝h′(β)exp⁡{T′(β)⊤α^}\begin{aligned} p(\beta | x) &\propto p(x | \beta) p(\beta) \\ &\propto h^{\prime}(\beta) \exp \Big\{ \hat{\alpha}_1^{\top} \beta - \hat{\alpha}_2 A(\beta) \Big\} \\ &\propto h^{\prime}(\beta) \exp \Big\{ \begin{bmatrix} \hat{\alpha}_1 \\ \hat{\alpha}_2 \end{bmatrix}^{\top} T^{\prime}(\beta) \Big\} \\ &\propto h^{\prime}(\beta) \exp \Big\{ T^{\prime}(\beta)^{\top} \begin{bmatrix} \hat{\alpha}_1 \\ \hat{\alpha}_2 \end{bmatrix} \Big\} \\ &\propto h^{\prime}(\beta) \exp \Big\{ T^{\prime}(\beta)^{\top} \hat{\alpha} \Big\} \\ \end{aligned}

We could see that p(β∣x)p(\beta | x) also belongs to the exponential family. Therefore we could always find a conjugate prior for the likelihood from the exponential family.

Natural Form of Distribution

Normal Distribution

For normal distribution, we have probability density:

p(x∣θ)=p(x∣μ,σ2)=12πσ2e−(x−μ)22σ2p(x|\theta) = p(x | \mu, \sigma^2) = \frac{1}{\sqrt{2\pi\sigma^2}} e^ { -\frac{(x - \mu)^2}{2\sigma^2} }

Here θ\theta is called the parameter of the distribution, compared to the natural parameter η\eta of the distribution. We will convert this form to the natural form of normal distribution.

p(x∣μ,σ2)=12πσ2exp⁡{−(x−μ)22σ2}=exp⁡{−(x−μ)22σ2+−12log⁡(2πσ2)}=exp⁡{−12σ2x2+μσ2x−μ22σ2−12log⁡(2πσ2)}=exp⁡{−12σ2x2+μσ2x}exp⁡{−μ22σ2−12log⁡(2πσ2)}=exp⁡{[xx2]⊤[μσ2−12σ2]}exp⁡{−μ22σ2−12log⁡(2πσ2)}=exp⁡{−12log⁡(2π)}exp⁡{[xx2]⊤[μσ2−12σ2]}exp⁡{−μ22σ2−12log⁡σ2}=12πexp⁡{[xx2]⊤[μσ2−12σ2]−{μ22σ2+12log⁡σ2}}\begin{aligned} p(x | \mu, \sigma^2) &= \frac{1}{\sqrt{2\pi\sigma^2}} \exp \bigg\{ -\frac{(x - \mu)^2}{2\sigma^2} \bigg\} \\ &= \exp \bigg\{ -\frac{(x - \mu)^2}{2\sigma^2} + \frac{-1}{2} \log(2 \pi \sigma^2) \bigg\} \\ &= \exp \bigg\{ -\frac{1}{2\sigma^2} x^2 + \frac{\mu}{\sigma^2} x - \frac{\mu^2}{2\sigma^2} - \frac{1}{2} \log(2 \pi \sigma^2) \bigg\} \\ &= \exp \bigg\{ -\frac{1}{2\sigma^2} x^2 + \frac{\mu}{\sigma^2} x \bigg\} \exp \bigg\{- \frac{\mu^2}{2\sigma^2} - \frac{1}{2} \log(2 \pi \sigma^2) \bigg\} \\ &= \exp \Bigg\{ \begin{bmatrix} x\\ x^2 \end{bmatrix}^{\top} \begin{bmatrix} \frac{\mu}{\sigma^2}\\ -\frac{1}{2\sigma^2} \end{bmatrix} \Bigg\} \exp \bigg\{- \frac{\mu^2}{2\sigma^2} - \frac{1}{2} \log(2 \pi \sigma^2) \bigg\} \\ &= \exp \Bigg\{ -\frac{1}{2} \log (2\pi) \Bigg\} \exp \Bigg\{ \begin{bmatrix} x\\ x^2 \end{bmatrix}^{\top} \begin{bmatrix} \frac{\mu}{\sigma^2}\\ -\frac{1}{2\sigma^2} \end{bmatrix} \Bigg\} \exp \bigg\{- \frac{\mu^2}{2\sigma^2} - \frac{1}{2} \log \sigma^2 \bigg\} \\ &= \frac{1}{\sqrt{2\pi}} \exp \Bigg\{ \begin{bmatrix} x\\ x^2 \end{bmatrix}^{\top} \begin{bmatrix} \frac{\mu}{\sigma^2}\\ -\frac{1}{2\sigma^2} \end{bmatrix} - \bigg\{\frac{\mu^2}{2\sigma^2} + \frac{1}{2} \log \sigma^2 \bigg\} \Bigg\} \\ \end{aligned}

So far, we could see that the base measurement, the sufficient statistics and the natural parameter for normal distribution are

h(x)=12πT(x)=[xx2]η=[η1η2]=[μσ2−12σ2]h(x) = \frac{1}{\sqrt{2\pi}}\\ T(x) = \begin{bmatrix} x\\ x^2 \end{bmatrix}\\ \eta = \begin{bmatrix} \eta_1\\ \eta_2 \end{bmatrix} = \begin{bmatrix} \frac{\mu}{\sigma^2}\\ -\frac{1}{2\sigma^2} \end{bmatrix}

It is not hard to see that

θ=[μσ2]=[−η12η2−12η2]\theta = \begin{bmatrix} \mu\\ \sigma^2 \end{bmatrix} = \begin{bmatrix} -\frac{\eta_1}{2\eta_2}\\ -\frac{1}{2\eta_2} \end{bmatrix}

Thus,

μ22σ2+12log⁡σ2=[(−η12η2)2−212η2]+12log⁡[−12η2]=−η124η2−12log⁡(−2η2)\begin{aligned} & \frac{\mu^2}{2\sigma^2} + \frac{1}{2} \log \sigma^2 \\ &= \bigg[ \frac{\big( -\frac{\eta_1}{2\eta_2} \big)^2}{-2\frac{1}{2\eta_2}} \bigg] + \frac{1}{2} \log \bigg[ - \frac{1}{2\eta_2} \bigg]\\ &= - \frac{\eta_1 ^2}{4\eta_2} - \frac{1}{2} \log(-2\eta_2) \\ \end{aligned}

This term is actually the log normalizer of the distribution.

A(η)=−η124η2−12log⁡(−2η2)A(\eta) = - \frac{\eta_1 ^2}{4\eta_2} - \frac{1}{2} \log(-2\eta_2)

Therefore, the natural form of normal distribution is

p(x∣η)=12π⏟h(x)exp⁡{[xx2]⏟T(x)⊤[η1η2]⏟η−[−η124η2−12log⁡(−2η2)]⏟A(η)}\begin{aligned} p(x | \eta) &= \underbrace{ \frac{1}{\sqrt{2\pi}} }_{h(x)} \exp \Bigg\{ {\underbrace{ \begin{bmatrix} x\\ x^2 \end{bmatrix} }_{T(x)}} ^{\top} \underbrace{ \begin{bmatrix} \eta_1\\ \eta_2 \end{bmatrix} }_{\eta} - \underbrace{ \big[ -\frac{\eta_1 ^2}{4\eta_2} - \frac{1}{2} \log(-2\eta_2) \big] }_{A(\eta)} \Bigg\}\\ \end{aligned}

We compared this to the natural form of normal distribution on Wikipedia. They are exactly the same.

Maximum Likelihood Estimation

Original Form

We have a collection of samples X={x1,x2,⋯ ,xN}X = \{ x_1, x_2, \cdots, x_N \}. Each sample xix_i is indepdently and identically drawn from a normal distribution N(μ,σ2)\mathcal{N}(\mu, \sigma^2).

p(X∣θ)=p(X∣μ,σ2)=∏i=1Np(xi∣μ,σ2)p(X | \theta) = p(X | \mu, \sigma^2) = \prod_{i=1}^{N} p(x_i | \mu, \sigma^2)

To maximize $p(X | \theta) $, it is equivalent to maximize $\log p(X | \theta) $, we have

\DeclareMathOperator∗arg max⁡argmaxθ^=arg max⁡θlog⁡p(X∣θ)=arg max⁡μ,σ2log⁡p(X∣μ,σ2)=arg max⁡μ,σ2{∑i=1Nlog⁡p(xi∣μ,σ2)}=arg max⁡μ,σ2{∑i=1Nlog⁡[12πσ2exp⁡{−(xi−μ)22σ2}]}=arg max⁡μ,σ2{Nlog⁡(12πσ2)+∑i=1N[−(xi−μ)22σ2]}=arg max⁡μ,σ2{−N2log⁡(2πσ2)−12σ2∑i=1N[(xi−μ)2]}\begin{aligned} \DeclareMathOperator*{\argmax}{argmax} \hat{\theta} &= \argmax_{\theta} \log p(X | \theta) \\ &= \argmax_{\mu, \sigma^2} \log p(X | \mu, \sigma^2) \\ &= \argmax_{\mu, \sigma^2} \Big\{ \sum_{i=1}^{N} \log p(x_i | \mu, \sigma^2) \Big\}\\ &= \argmax_{\mu, \sigma^2} \Bigg\{ \sum_{i=1}^{N} \log \bigg[ \frac{1}{\sqrt{2\pi\sigma^2}} \exp \big\{ -\frac{(x_i-\mu)^2}{2\sigma^2} \big\} \bigg] \Bigg\}\\ &= \argmax_{\mu, \sigma^2} \Bigg\{ N\log \Big( \frac{1}{\sqrt{2\pi\sigma^2}} \Big) + \sum_{i=1}^{N} \bigg[ -\frac{(x_i-\mu)^2}{2\sigma^2} \bigg] \Bigg\}\\ &= \argmax_{\mu, \sigma^2} \Bigg\{ -\frac{N}{2} \log \Big( 2\pi\sigma^2 \Big) - \frac{1}{2\sigma^2} \sum_{i=1}^{N} \bigg[ (x_i-\mu)^2 \bigg] \Bigg\}\\ \end{aligned}

We first take the derivative with respect to μ\mu.

∂∂μlog⁡p(X∣μ,σ2)=12σ2∑i=1N2(xi−μ)=1σ2[(∑i=1Nxi)−Nμ]=0\begin{aligned} \frac{\partial}{\partial \mu} \log p(X | \mu, \sigma^2) &= \frac{1}{2\sigma^2} \sum_{i=1}^{N} 2(x_i - \mu) \\ &= \frac{1}{\sigma^2} \bigg[ \Big( \sum_{i=1}^{N} x_i \Big) - N \mu \bigg] \\ &= 0 \end{aligned}

We then take the derivative with respect to σ2\sigma^2.

∂∂σ2log⁡p(X∣μ,σ2)=−N21σ2−12−1σ4∑i=1N[(xi−μ)2]=12σ2[−N+1σ2∑i=1N[(xi−μ)2]]=12σ2[−N+1σ2[∑i=1Nxi2−2μ∑i=1Nxi+Nμ2]]=12σ2[−N+1σ2[∑i=1Nxi2−Nμ2]]=0\begin{aligned} \frac{\partial}{\partial \sigma^2} \log p(X | \mu, \sigma^2) &= -\frac{N}{2} \frac{1}{\sigma^2} - \frac{1}{2} \frac{-1}{\sigma^4} \sum_{i=1}^{N} \Big[ (x_i-\mu)^2 \Big] \\ &= \frac{1}{2\sigma^2} \bigg[ -N + \frac{1}{\sigma^2} \sum_{i=1}^{N} \Big[ (x_i-\mu)^2 \Big] \bigg] \\ &= \frac{1}{2\sigma^2} \bigg[ -N + \frac{1}{\sigma^2} \Big[ \sum_{i=1}^{N} x_i^2 - 2\mu \sum_{i=1}^{N} x_i + N \mu^2 \Big] \bigg] \\ &= \frac{1}{2\sigma^2} \bigg[ -N + \frac{1}{\sigma^2} \Big[ \sum_{i=1}^{N} x_i^2 - N\mu^2 \Big] \bigg] \\ &= 0 \end{aligned}

We finally solve the above two equations. We got

μ^=∑i=1NxiNσ^2=∑i=1Nxi2N−μ^2=∑i=1Nxi2N−(∑i=1NxiN)2\begin{aligned} \hat{\mu} &= \frac{\sum_{i=1}^{N} x_i}{N} \\ \hat{\sigma}^2 &= \frac{\sum_{i=1}^{N} x_i^2}{N} - \hat{\mu}^2 \\ &= \frac{\sum_{i=1}^{N} x_i^2}{N} - \big(\frac{\sum_{i=1}^{N} x_i}{N}\big)^2 \end{aligned}

Therefore,

θ^=[μ^σ^2]=[∑i=1NxiN∑i=1Nxi2N−[∑i=1NxiN]2]\hat{\theta} = \begin{bmatrix} \hat{\mu}\\ \hat{\sigma}^2 \end{bmatrix} = \begin{bmatrix} \frac{\sum_{i=1}^{N} x_i}{N} \\ \frac{ \sum_{i=1}^{N}x_i^2 }{N} - \big[ \frac{\sum_{i=1}^{N}x_i}{N} \big]^2 \end{bmatrix}

We could see that it is complicated to derive these. Moreover, if the distribution where the sample is drawn from are changed, we need to derive again from scratch using the probability density of the new distribution.

Natural Form

We now use the natural form of normal distribution to do maximum likelihood estimation for the same task.

p(X∣η)=∏i=1Np(xi∣η)p(X | \eta) = \prod_{i=1}^{N} p(x_i | \eta)

To maximize p(X∣η)p(X | \eta), it is equivalent to maximize log⁡p(X∣η)\log p(X | \eta), we have

\DeclareMathOperator∗arg max⁡argmaxη^=arg max⁡ηlog⁡p(X∣η)=arg max⁡η{∑i=1Nlog⁡p(xi∣η)}=arg max⁡η{∑i=1Nlog⁡[h(xi)exp⁡{T(xi)⊤η−A(η)}]}=arg max⁡η{∑i=1N[log⁡h(xi)+T(xi)⊤η−A(η)]}=arg max⁡η{∑i=1Nlog⁡h(xi)+∑i=1NT(xi)⊤η−NA(η)}\begin{aligned} \DeclareMathOperator*{\argmax}{argmax} \hat{\eta} &= \argmax_{\eta} \log p(X | \eta) \\ &= \argmax_{\eta} \Big\{ \sum_{i=1}^{N} \log p(x_i | \eta) \Big\}\\ &= \argmax_{\eta} \bigg\{ \sum_{i=1}^{N} \log \Big[ h(x_i) \exp \big\{ T(x_i)^{\top} \eta - A(\eta) \big\} \Big] \bigg\}\\ &= \argmax_{\eta} \bigg\{ \sum_{i=1}^{N} \Big[ \log h(x_i) + T(x_i)^{\top} \eta - A(\eta) \Big] \bigg\}\\ &= \argmax_{\eta} \bigg\{ \sum_{i=1}^{N} \log h(x_i) + \sum_{i=1}^{N} T(x_i)^{\top} \eta - N A(\eta) \bigg\}\\ \end{aligned}

We take the derivative with respect to η\eta.

∂∂ηlog⁡p(X∣η)=∑i=1NT(xi)−NddηA(η)=0\begin{aligned} \frac{\partial}{\partial \eta} \log p(X | \eta) &= \sum_{i=1}^{N} T(x_i) - N \frac{d}{d\eta} A(\eta)\\ &= 0 \end{aligned}

Therefore,

ddηA(η)∣η^=A′(η^)=∑i=1NT(xi)N=Ex∈X[T(x)]\frac{d}{d\eta} A(\eta) \Bigr|_{\hat{\eta}} = A^{\prime}(\hat{\eta})= \frac{\sum_{i=1}^{N} T(x_i)}{N} = \mathbb{E}_{x \in X} [T(x)]

This is a general equation to do maximum likelihood estimation for all the distributions from the exponential family.

Specifically for normal distribution,

T(xi)=[xixi2]η=[η1η2]=[μσ2−12σ2]A(η)=−η124η2−12log⁡(−2η2)T(x_i) = \begin{bmatrix} x_i\\ x_i^2 \end{bmatrix}\\ \eta = \begin{bmatrix} \eta_1\\ \eta_2 \end{bmatrix} = \begin{bmatrix} \frac{\mu}{\sigma^2}\\ -\frac{1}{2\sigma^2} \end{bmatrix}\\ A(\eta) = - \frac{\eta_1 ^2}{4\eta_2} - \frac{1}{2} \log(-2\eta_2)

ddηA(η)∣η^=A′(η^)=[∂η1A(η)∂η2A(η)]η^=[−η12η2−η124−1η22−12−2−2η2]η^=[−η12η2η124η22−12η2]η^=[−η^12η^2η^124η^22−12η^2]=∑i=1NT(xi)N=[∑i=1NxiN∑i=1Nxi2N]\begin{aligned} \frac{d}{d\eta} A(\eta) \Bigr|_{\hat{\eta}} &= A^{\prime}(\hat{\eta}) \\ &= \begin{bmatrix} \frac{\partial}{\eta_1} A(\eta)\\ \frac{\partial}{\eta_2} A(\eta) \end{bmatrix}_{\hat{\eta}}\\ &= \begin{bmatrix} -\frac{\eta_1}{2\eta_2} \\ -\frac{\eta_1^2}{4} \frac{-1}{\eta_2^2} - \frac{1}{2} \frac{-2}{-2\eta_2} \end{bmatrix} _{\hat{\eta}} \\ &= \begin{bmatrix} -\frac{\eta_1}{2\eta_2} \\ \frac{\eta_1^2}{4\eta_2^2} - \frac{1}{2\eta_2} \end{bmatrix}_{\hat{\eta}}\\ &= \begin{bmatrix} -\frac{\hat{\eta}_1}{2\hat{\eta}_2} \\ \frac{\hat{\eta}_1^2}{4\hat{\eta}_2^2} - \frac{1}{2\hat{\eta}_2} \end{bmatrix} \\ &= \frac{\sum_{i=1}^{N} T(x_i)}{N}\\ &= \begin{bmatrix} \frac{\sum_{i=1}^{N} x_i}{N}\\ \frac{\sum_{i=1}^{N} x_i^2}{N} \end{bmatrix}\\ \end{aligned}

We solve the above equations

η^=[η^1η^2]=[−∑i=1NxiN[∑i=1NxiN]2−∑i=1Nxi2N12[∑i=1NxiN]2−∑i=1Nxi2N]\hat{\eta} = \begin{bmatrix} \hat{\eta}_1\\ \hat{\eta}_2 \end{bmatrix} = \begin{bmatrix} -\frac{\frac{\sum_{i=1}^{N}x_i}{N}}{\big[ \frac{\sum_{i=1}^{N}x_i}{N} \big]^2 - \frac{ \sum_{i=1}^{N}x_i^2 }{N} }\\ \frac{\frac{1}{2}}{\big[ \frac{\sum_{i=1}^{N}x_i}{N} \big]^2 - \frac{ \sum_{i=1}^{N}x_i^2 }{N} } \end{bmatrix}

Let’s finally check if the maximum likelihood estimate solutions from the original form and the natural form are equivalent. Note that this step is not required in practice since it is redundant.

η^=[η^1η^2]=[−∑i=1NxiN[∑i=1NxiN]2−∑i=1Nxi2N12[∑i=1NxiN]2−∑i=1Nxi2N]=[μ^σ^2−12σ^2]\hat{\eta} = \begin{bmatrix} \hat{\eta}_1\\ \hat{\eta}_2 \end{bmatrix} = \begin{bmatrix} -\frac{\frac{\sum_{i=1}^{N}x_i}{N}}{\big[ \frac{\sum_{i=1}^{N}x_i}{N} \big]^2 - \frac{ \sum_{i=1}^{N}x_i^2 }{N} }\\ \frac{\frac{1}{2}}{\big[ \frac{\sum_{i=1}^{N}x_i}{N} \big]^2 - \frac{ \sum_{i=1}^{N}x_i^2 }{N} } \end{bmatrix} = \begin{bmatrix} \frac{\hat{\mu}}{\hat{\sigma}^2}\\ -\frac{1}{2\hat{\sigma}^2} \end{bmatrix}\\

θ^=[μ^σ^2]=[∑i=1NxiN∑i=1Nxi2N−[∑i=1NxiN]2]\hat{\theta} = \begin{bmatrix} \hat{\mu}\\ \hat{\sigma}^2 \end{bmatrix} = \begin{bmatrix} \frac{\sum_{i=1}^{N} x_i}{N} \\ \frac{ \sum_{i=1}^{N}x_i^2 }{N} - \big[ \frac{\sum_{i=1}^{N}x_i}{N} \big]^2 \end{bmatrix}

It is exactly the same as what we got from the original form. But it is much simpler because we already know T(x)T(x), η\eta, and A(η)A(\eta). For other distributions from the exponential family, their corresponding T(x)T(x), η\eta, and A(η)A(\eta) could be found on Wikipedia.

Final Remarks

The natural forms of all the exponential family members could be found on Wikipedia. Life becomes easier.

References