Debian Codegraph @

easel/esl_mixdchlet.tex

raw
1 \documentclass[11pt]{article}
2 \setcounter{secnumdepth}{0}
3
4 \usepackage{relsize}
5
6 \newcommand{\mono}[1]{{\smaller\texttt{#1}}} % literal (to be typed): code, program names
7
8 \begin{document}
9
10 \section{Fitting a mixture Dirichlet to counts}
11
12 \mono{esl\_mixdchlet\_Fit()} infers a maximum likelihood mixture
13 Dirichlet distribution for a data set of count vectors. It uses
14 conjugate gradient descent from an initial starting point. The result
15 is only a local optimum, so we typically run it multiple times with
16 different starting points. The partial derivatives of the log
17 likelihood function are persnickety, and the purpose of these notes is
18 to enshrine the derivation that corresponds to the implementation.
19
20 We have $N$ count vectors $c_i$, with each vector consisting of $K$
21 counts for individual symbols $c_{ia} \geq 0$. The mixture Dirichlet
22 $\theta$ consists of $Q$ components $\alpha_k$, with each parameter
23 vector containing $K$ parameters $\alpha_{ka} > 0$, and $Q$ mixture
24 coefficients $q_k > 0, \sum_k q_k = 1$.
25
26 The log likelihood of the data is:
27
28 \[
29 L = \log P(\mbox{data} \mid \theta) = \sum_i \log P(c_i \mid \theta) = \sum_i \log \sum_k q_k P(c_i \mid \alpha_k)
30 \]
31
32 \mono{esl\_mixdchlet\_logpdf\_c()} calculates $\log P(c_i \mid
33 \theta)$.
34
35 $P(c_i \mid \alpha_k)$, the probability of one count vector given one
36 Dirichlet component, is:
37
38 \[
39 P(c_i \mid \alpha_k) = \frac{ |c_i|! }
40 { \prod_a c_{ia}! }
41 \frac{ \prod_a \Gamma \left( c_{ia} + \alpha_{ia} \right) }
42 { \Gamma ( |c_i + \alpha_k| ) }
43 \frac{ \Gamma ( |\alpha_k| ) }
44 { \prod_a \Gamma \left( \alpha_{ka} \right) }
45 \]
46
47 \mono{esl\_dirichlet\_logpdf\_c()} calculates $\log P(c_i \mid \alpha_k)$.
48
49 The conjugate gradient descent code works with unconstrained
50 real-valued parameters. The Dirichlet parameters $\alpha_{ka}$ are
51 constrained to $>0$, and mixture coefficients $q_k$ are constrained to
52 $>0$ and $\sum_k q_k = 1$. Define a change of variables in terms of
53 unconstrained parameters $\lambda_k$ for the mixture coefficients and
54 $\beta_{ka}$ for Dirichlet parameters:
55
56 \begin{eqnarray*}
57 q_k & = & \frac{ e^{\lambda_k} } { \sum_m e^{\lambda_m} } \\
58 \alpha_{ka} & = & e^{\beta_{ka}}
59 \end{eqnarray*}
60
61 After variable substitution, partial differentiation w.r.t. the
62 unconstrained parameters, and substituting back the original
63 parameters, we have for the mixture coefficients:
64
65 \[
66 \frac{\partial L}{\partial \lambda_k} = \sum_i P(k \mid \theta, c_i) - q_k
67 \]
68
69 i.e., the difference between the posterior probability of component
70 $k$ $P(k \mid \theta, c_i)$, calculated by \mono{mixdchlet\_postq()},
71 and its prior $q_k$.
72
73 For the Dirichlet parameters:
74
75 \[
76 \frac{\partial L}{\partial \beta_{ka}} = \sum_i
77 \alpha_{ka} P(k \mid \theta, c_i)
78 \left( \Psi \left( c_{ia} + \alpha_{ka} \right)
79 - \Psi \left( | c_i | + | \alpha_k | \right)
80 + \Psi \left( | \alpha_k | \right)
81 - \Psi \left( \alpha_{ka} \right)
82 \right)
83 \]
84
85
86 $\Psi(x)$ is the digamma function $\frac{d}{dx} \log \Gamma(x) =
87 \frac{\Gamma'(x)}{\Gamma(x)}$, for $x > 0$, implemented by
88 \mono{esl\_stats\_Psi()}.
89
90 The Easel conjugate gradient descent optimizer is a minimizer, not a
91 maximizer. The implementation provides the negative log likelihood
92 and the negative gradient to the CG routine.
93
94
95 \end{document}
96