Expectation Maximization Algorithm
Expectation Maximization Algorithm
The Expectation-Maximization
(EM) Algorithm
1.
pentru orice x (fixat), pentru orice valoare a parametrului θ şi pentru orice
distribuţie probabilistă q definită peste variabilele neobservabile z.
a Reţineţi
că x, vectorul de date observabile, este fixat (dat), ı̂n vreme ce z, vectorul de date neobservabile, este
liber (variabil).
4.
Observaţie (1)
Semnificaţia inegalităţii (1) este următoarea:
Funcţia (de fapt, orice funcţie de forma)
def.
X P (x, z | θ)
F (q, θ) = q(z) log
z
q(z)
P (x, z | θ)
Conform inegalităţii lui Jensen (ı̂nlocuind X de mai sus cu ), rezultă:
q(z)
not. P (x, z | θ) def. X P (x, z | θ)
ℓ(θ) = log P (x | θ) ≥ Eq(z) log = q(z) log ,
q(z) z
q(z)
6.
Notaţie
În continuare, pentru a vă aduce mereu aminte că distribuţia q se referă
la datele neobservabile z, vom folosi notaţia q(z) ı̂n loc de q.
În consecinţă, ı̂n cele ce urmează, ı̂n funcţie de context, q(z) va desemna
fie distribuţia q, fie valoarea acestei distribuţii pentru o valoare oarecare
[a variabilei neobservabile] z.
(Este adevărat că această lejeră ambiguitate poate induce ı̂n eroare citi-
torul neexperimentat.)
7.
Arătaţi că
log P (x | θ) = F (q(z), θ) + KL(q(z) || P (z | x, θ)).
Observaţie (2):
Semnificaţia egalităţii care trebuie demonstrată la acest punct este foarte
not.
interesantă: diferenţa dintre funcţia obiectiv ℓ(θ) = log P (x | θ) şi marginea
sa inferioară F (q(z), θ) — a se vedea punctul a — este KL(q(z) || P (z | x, θ)).
Tocmai pe această chestiune se va “construi” punctul final, şi cel mai
important, al problemei noastre.
8.
Observaţie (3)
Ideile de bază ale algoritmului EM sunt două:
1. În loc să calculeze maximul funcţiei de log-verosimilitate log P (x | θ) ı̂n
raport cu θ, algoritmul EM va maximiza marginea sa inferioară, F (q(z), θ),
ı̂n raport cu ambele argumente, q(z) şi θ.
2. Pentru a căuta maximul (de fapt, un maxim local al) marginii in-
ferioare F (q(z), θ), algoritmul EM aplică metoda creşterii pe coordonate
(engl., coordinate ascent): după ce iniţial se fixează θ(0) eventual aleatoriu,
se maximizează iterativ funcţia F (q(z), θ), ı̂n mod alternativ: mai ı̂ntâi ı̂n
raport cu distribuţia q(z) şi apoi ı̂n raport cu parametrul θ.
Observaţie (4)
Conform proprietăţii KL(p || q) ≥ 0 pentru ∀p, q, rezultă KL(q(z) || P (z |
x, θ)) ≥ 0.
Aşadar, din egalitatea care tocmai a fost demonstrată la punctul b obţinem
(din nou!, după rezultatul de la punctul a) că F (q(z), θ) este o margine
not.
inferioară pentru log-verosimilitatea datelor observabile, ℓ(θ) = log P (x | θ).
11.
Observaţie (5)
def.
Notând Gt (θ) = F (P (z | x, θ(t) ), θ), din calculul de mai sus rezultă că
Gt (θ(t) ) = log P (x | θ(t) ) = Q(θ(t) | θ(t) ) + H(P (z | x, θ(t) )). Se poate demon-
stra uşor — procedând similar cu calculul de mai sus — egalitatea
From:
What is the expectation maximiza-
tion algorithm?
Chuong B. Do, Serafim Batzoglou,
Nature Biotechnology,
vol. 26, no. 8, 2008, pp. 897-899
16.
Algoritmul EM:
corectitudine / convergenţă
Observaţii (cont.)
3. Conform aceleiaşi inegalităţi (2), la pasul M de la iteraţia t a algoritmului
EM, este suficient ca ı̂n loc să se ia θ(t+1) = argmaxθ Q(θ | θ(t) ), să se aleagă
θ(t+1) astfel ı̂ncât Q(θ(t+1) | θ(t) ) > Q(θ(t) | θ(t) ). Aceasta constituie versiunea
“generalizată” a algoritmului EM.
21.
Demonstraţia relaţiei (2)
P (x, z | θ) = P (z | x, θ) · P (x | θ) ⇒ log P (x | θ) = log P (x, z | θ) − log P (z | x, θ) ⇒
X
P (z | x, θ(t) ) · log P (x | θ) =
z
| {z }
1
X X
P (z | x, θ(t) ) · log P (x, z | θ) − P (z | x, θ(t) ) · log P (z | x, θ) ⇒
z z
X
log P (x | θ) = Q(θ | θ(t) ) − P (z | x, θ(t) ) · log P (z | x, θ)
z
Ultimul termen din egalitatea aceasta reprezintă o cross-entropie, pe care o vom nota
cu CH(θ | θ(t) ). Aşadar,
Această egalitate este valabilă pentru toate valorile posibile ale parametrului θ. În
particular pentru θ = θ(t) , vom avea:
log P (x | θ) − log P (x | θ(t) ) = Q(θ | θ(t) ) − Q(θ(t) | θ(t) ) + CH(θ | θ(t) ) − CH(θ(t) | θ(t) )
Conform inegalităţii lui Gibbs, avem CH(θ | θ(t) ) ≥ CH(θ(t) | θ(t) ), deci ı̂n final rezultă:
log P(x| θ )
G t+1 (θ (t+1) )
} H [P(z|x; θ (t+1))]
Gt (θ (t) )
Q (θ | θ(t+1) )
} Q (θ|θ (t) )
H[ P(z|x; θ (t) ) ]
Source: wiki
Source: wiki
27.
ch. 9 ch. 9’
pheno− blood
type type Probability counts
nAA AA pA 2 +
probabilities alleles alleles A nA
AO 2p p
p A O
A A A
B
ABO ABO nBB BB pB 2 +
A B B B nB
gene gene BO 2p p
p O O B O
O
AB AB 2p p
A B
nAB
homologous chromosomes
O O pO2 nO
Indicaţii
Solution
Notations:
• parameters: p = {pA , pB , pO }
(in fact, it will be enough to estimate pA and pB , since pA + pB + pO = 1)
• observable data: nobs = {nA , nB , nAB , nO }
• unobservable data: nunobs = {nAA , nAO , nBB , nBO }
(in fact, we will restrict nunobs to {nAA , nBB })
• complete data: ncompl = nobs ∪ nunobs
• n = nA + nB + nAB + nO , nA = nAA + nAO , nB = nBB + nBO .
where
not. (t) (t) (t)
n̂AA = E[nAA |nobs ; p(t) ] = E[nAA |nA , nB , nAB , nO ; pA , pB , pO ]
not. (t) (t) (t)
n̂BB = E[nBB |nobs ; p(t) ] = E[nBB |nA , nB , nAB , nO ; pA , pB , pO ]
33.
E step: As indicated by the expression of Q, here we have to compute n̂AA
and n̂BB the expected number of individuals having the phenotype (aka,
the allele pair) AA, and respectively BB.
Firstly, taking into account that nAA (or, equivalently, the phenotype AA),
when seen as a random variable, follows a binomial distribution of param-
(t)
(pA )2
eters nA and (t) (t) (t)
, its expectation will be:
2
(pA ) + 2 pA pO
not. (t) (t) (t)
n̂AA = E[nAA |nA , nB , nAB , nO ; pA , pB , pO ]
(t)
(pA )2
= (t) (t) (t)
· nA
(pA )2 +2 pA pO
Similarly,
not. (t) (t) (t)
n̂BB = E[nBB |nA , nB , nAB , nO ; pA , pB , pO ]
(t)
(pB )2
= (t) (t) (t)
· nB
(pB )2 +2 pB pO
34.
M step:
Given the constraint pA + pB + pO = 1, we will introduce the Lagrange vari-
able/“multiplier” λ and solve for the optimisation problem
not. (t+1) (t+1) (t+1)
p(t+1) = (pA , pB , pO )
(t) (t) (t)
= argmax [Q(pA , pB , pO |pA , pB , pO ) + λ(1 − (pA + pB + pO ))]
pA , pB , pO
Source: wiki
40.
Biological background (cont’d)
P P
AB (1−p)/2 AB (1−p’)/2
Ab p/2 Ab p’/2
aB p/2 aB p’/2
ab (1−p)/2 ab (1−p’)/2
male/father diploid cell female/mother diploid cell
ch. i ch. i
A/a A/a A/a A/a
B/b B/b B/b B/b
A/a A/a
B/b B/b
meiosis meiosis
(including (including
crossover) crossover)
Solution
By denoting n = n1 + n2 + n3 + n4,
2+ψ 1−ψ 1−ψ ψ
and kowing that n ∼ Multinomial n; , , , ,
4 4 4 4
it follows that the verosimility function will be
n n n n4
def. n! 2+ψ 1 1−ψ 2 1−ψ 3 ψ
L(ψ) = P (D|ψ) = · · · · ,
n1 ! n2 ! n3 ! n4 ! 4 4 4 4
while
def.
ℓ(ψ) = ln L(ψ) = ln c + n1 ln(2 + ψ) + (n2 + n3 ) ln(1 − ψ) + n4 ln(ψ),
1 ψ 1 − ψ 1 − ψ ψ
b. Fie acum variabila aleatoare X ′ ∼ Multinomial n; , , , , . Valorile luate
2 4 4 4 4
de variabila X ′ , corespunzător acestor cinci probabilităţi, sunt (ı̂n ordine) v1 , v1 , v2 , v3 şi
v4 .
Observaţi că, ı̂n raport cu distribuţia multinomială de la punctul a, am ,,descompus“
2+ψ 1 ψ
probabilitatea ı̂n două probabilităţi, şi , ca şi cum ele ar corespunde unor
4 2 4
evenimente disjuncte.
Vom considera n11 , n12 , n2 , n3 şi respectiv n4 numărul de ,,realizări“ ale acestor valori,
ı̂nsă de data aceasta n11 şi n12 vor fi neobservabile. În schimb, vom furniza suma
n1 = n11 + n12 ca dată ,,observabilă“, alături de celelalte date observabile, n2 , n3 şi n4 .
Să se estimeze parametrul ψ folosind algoritmul EM. Cum este această estimare faţă
de valoarea obţinută la punctul a?
Indicaţie: Veţi elabora formulele corespunzătoare pasului E şi pasului M. Apoi veţi face
o implementare şi veţi rula algoritmul EM (pornind, de exemplu, cu valoarea iniţială
0.5 pentru ψ) până când valorile acestui parametru până la cea de-a şasea zecimală nu
se mai modifică.
46.
Solution: E-step
The verosimility function is now
n11 n12 n n n4
n! 1 ψ 1−ψ 2 1−ψ 3 ψ
P (D|ψ) = · · · · ·
n11 ! n12 ! n2 ! n3 ! n4 ! 2 4 4 4 4
n11 n2 +n3 n12 +n4
n! 1 1−ψ ψ
= · · · ,
n11 ! n12 ! n2 ! n3 ! n4 ! 2 4 4
Q(ψ|ψ (t+1) ) = En12 |n1 ,n2 ,n3 ,n4 ,ψ(t) [ln P (D|ψ)]
= ln d + (n2 + n3 ) ln(1 − ψ) + (n̂12 + n4 ) ln(ψ),
where
1
not. (t) 2 ψ (t)
n̂12 = E[n12 |n1 , n2 , n3 , n4 , ψ ] = = · n1 .
1
2 + ψ4 2 + ψ (t)
47.
M-step
∂ 1
E[ln P (D|ψ)] = −(n2 + n3 ) + (n̂12 + n4 )
∂ψ 1−ψ
∂2 −1 1
⇒ E[ln P (D|ψ)] = (n 1 + n 3 ) − (n̂ 12 + n 4 ) ≤0
∂ψ 2 n1 + n3 ψ2
∂
E[ln P (D|ψ)] = 0 ⇔
∂ψ
(n̂12 + n4 )(1 − ψ) = ψ(n2 + n3 ) ⇔
ψ(n̂12 + n2 + n3 + n4 ) = n̂12 + n4 ⇔
n̂12 + n4
ψ (t+1) =
n − n̂11
where
not. 2
n̂11 = E[n11 |n1 , n2 , n3 , n4 , ψ (t) ] = n1 − n̂12 = · n1 .
2 + ψ (t)
A Matlab implementation of this EM algorithm produces ψ = 0.62682139.
48.
Suppose I have two unfair coins. The first lands on heads with probability
p, and the second lands on heads with probability q.
Imagine n tosses, where for each toss I choose to use the first coin with
probability π and choose to use the second with probability 1 − π. The
outcome of each toss i is xi ∈ {0, 1}.
not.
Suppose I tell you the outcomes of the n tosses, x = {x1 , x2 , . . . , xn }, but I
don’t tell you which coins I used on which toss.
Given only the outcomes, x, your job is to compute estimates for θ which
is the set of all parameters, θ = {p, q, π} using the EM algorithm.
To compute these estimates, we will create a latent variable Z, where
zi ∈ {0, 1} indicates the coin used for the nth toss. For example z2 = 1
indicates the first coin was used on the second toss.
We define the “incomplete” data log-likelihood as log P (x|θ) and the “com-
plete” data log-likelihood as log P (x, z|θ).
50.
e. M-Step: Describe the process you would use to obtain the update
equations for p(t+1) , q (t+1) şi π (t+1) .
51.
Solution
a.
X
E[zi | xi , θ] = zi P (zi | xi , θ) = 0 · P (zi = 0 | xi , θ) + 1 · P (zi = 1 | xi , θ)
z∈{0,1}
⇒ E[zi | xi , θ] = P (zi = 1 | xi , θ)
b.
P (zi = 1 | xi , θ)
P (xi | zi = 1, θ)P (zi = 1 | θ)
=
P (xi | zi = 1, θ)P (zi = 1 | θ) + P (xi | zi = 0, θ)P (zi = 0 | θ)
pxi · (1 − p)1−xi · π
= xi
p · (1 − p)1−xi · π + q xi · (1 − q)1−xi · (1 − π)
52.
c.
Note (in Romanian): Din punct de vedere metodologic, pentru a calcula P (x, z|θ)
ne putem inspira de la punctul precedent: observăm că la numitorul fracţiei care ne
dă valoarea lui P (zi |xi , θ) avem P (xi , zi = 1|θ) şi P (xi , zi = 0|θ). Pornind de la aceste două
expresii, ne vom propune să le exprimăm ı̂n mod unitar, adică sub forma unei singure
expresii.
n
Y n
Y
i.i.d.
log P (x, z | θ) = log P (xi , zi | θ) = log P (xi | zi , θ) · P (zi | θ)
i=1 i=1
Yn
xi 1−xi
zi xi 1−xi
1−zi
= log p (1 − p) π q (1 − q) (1 − π)
i=1
n
X
xi 1−xi
zi xi 1−xi
1−zi
= log p (1 − p) π q (1 − q) (1 − π)
i=1
Xn
xi 1−xi
xi 1−xi
= zi log p (1 − p) π + (1 − zi ) log q (1 − q) (1 − π)
i=1
53.
d.
not.
Q(θ | θ(t) ) = EP (z|x,θ(t) ) [log P (x, z | θ)]
n
X xi 1−xi
= EP (z|x,θ(t) ) [ zi log p (1 − p) π +
i=1
n
X
xi 1−xi
EP (z|x,θ(t) ) [ [ (1 − zi ) log q (1 − q) (1 − π) ]
n i=1
X
= E[zi | xi , θ(t) ] · log pxi (1 − p)1−xi π +
i=1
(t)
xi 1−xi
+ 1 − E[zi | xi , θ ] · q (1 − q) (1 − π)
n
X
= E[zi | xi , θ(t) ] · (log π + xi log p + (1 − xi ) log(1 − p)) +
i=1
(t)
+ 1 − E[zi | xi , θ ] · (log(1 − π) + xi log q + (1 − xi ) log(1 − q))
54.
e.
(t) not. (t) (p(t) )xi · (1 − p(t) )1−xi · π (t)
µi = E[zi | xi , θ ] = (t) x
(p ) i · (1 − p(t) )1−xi · π (t) + (q (t) )xi · (1 − q (t) )1−xi · (1 − π (t) )
n h
X (t)
⇒ Q(θ | θ(t) ) = µi (log π + xi log p + (1 − xi ) log(1 − p)) +
i=1
n
X i
(t)
[ + 1 − µi · (log(1 − π) + xi log q + (1 − xi ) log(1 − q))
i=1
n n n
∂Q(θ | θ(t) ) X (t) xi 1 − xi 1 X (t) 1 X (t)
=0⇔ µi − =0⇔ µ xi = µ (1 − xi )
∂p i=1
p 1−p p i=1 i 1 − p i=1 i
n n n n n
!
X (t)
X (t)
X (t)
X (t)
X (t)
⇔ (1−p) µi xi = p µi (1−xi ) ⇔ µi xi = p µi (1−xi ) + µi xi
i=1 i=1 i=1 i=1 i=1
n n Pn (t)
i=1 µi xi
X (t)
X (t)
⇔ µi xi =p µi ⇒ p(t+1) = Pn (t)
∈ [0, 1]
i=1 i=1 i=1 µi
55.
n Pn (t)
∂Q(θ | θ(t) ) X (t) xi 1 − xi (t+1) i=1 (1 − µi )xi
=0⇔ (1−µi ) − =0⇒q = Pn (t)
∈ [0, 1]
∂q i=1
q 1−q (1 − µ i )
i=1
n
! n n
(t) (t) (t)
∂Q(θ | θ ) X µi 1−
1 X (t) µi 1 X (t)
=0⇔ =0⇔ − µi = (1 − µi )
∂π i=1
π 1−π
π i=1 1 − π i=1
n n n n n
!
X (t)
X (t)
X (t)
X (t)
X (t)
⇔ (1 − π) µi = π (1 − µi ) ⇔ µi = π (1 − µi ) + µi
i=1 i=1 i=1 i=1 i=1
n n n n
X (t)
X X (t) 1 X (t)
⇔ µi =π 1⇔ µi = nπ ⇒ π (t+1) = µ ∈ [0, 1]
i=1 i=1 i=1
n i=1 i
∂2 ∂2 ∂2
Note: It can be easily shown that the second derivatives ( 2 , 2 and 2 ) are all
∂p ∂q ∂π
negative on the respective domains of definition. Therefore, the above solutions (p(t+1) ,
q (t+1) and π (t+1) ) maximize the Q functional.
56.
Estimarea parametrilor
unei mixturi de distribuţii [de tip] Bernoulli
A. când toate variabilele sunt observabile: MLE;
B. când unele variabile sunt neobservabile: algoritmul EM
A. La acest punct vom considera că s-a obţinut următorul rezultat pentru
experimentul nostru:
i Z i Xi
1 B 5H (5T )
2 A 9H (1T )
3 A 8H (2T )
4 B 4H (6T )
5 A 7H (3T )
Semnificaţia variabilelor aleatoare Zi şi Xi pentru i = 1, . . . , 5 din tabelul de
mai sus este imediată.
59.
Răspuns:
Analizând datele din tabelul din enunţ, rezultă imediat
24 9
θ̂A = = 0.8 şi θ̂B = = 0.45.
24 + 6 9 + 11
De observat că termenii 6 şi respectiv 11 de la numitorii acestor fracţii
reprezintă numărul de feţe ‘tail’/ban care au fost obţinute la aruncarea
monedei A şi respectiv B: 6T = 1T + 2T + 3T , 11T = 5T + 6T .
60.
61.
Observaţie
Dacă ı̂n locul variabilelor binare Zi ∈ {A, B} pentru i = 1, . . . , 5 introducem
ı̂n mod natural variabilele-indicator Zi,A ∈ {0, 1} şi Zi,B ∈ {0, 1} tot pentru
i = 1, . . . , 5, definite prin Zi,A = 1 iff Zi = A, şi Zi,A = 0 iff Zi,B = 0, atunci
procesările necesare pentru calculul probabilităţilor/parametrilor θ̂A şi θ̂B
pot fi prezentate ı̂n mod sintetizat ca ı̂n tabelul de mai jos.a
i Zi,A Zi,B Xi
1 0 1 5H
2 1 0 9H ⇒
3 1 0 8H
4 0 1 4H
5 1 0 7H
Xi · Zi,A Xi · Zi,B
0H (0T ) 5H (5T )
9H (1T ) 0H (0T )
8H (2T ) 0H (0T )
⇒ 0H (0T ) 4H (6T ) ⇒
7H (3T ) 0H (0T )
P5 P5
i=1 Xi · Zi,A = 24H Xi · Zi,B = 9H
P5 Pi=1
5
i=1 (10 − Xi ) · Zi,A = 6T i=1 (10 − Xi ) · Zi,B = 11T
24
θ̂A =
= 0.8
24 + 6
⇒
9
θ̂B =
= 0.45
9 + 11
63.
not.
ii. Calculaţi L1 (θA , θB ) = P (X, Z | θA , θB ), funcţia de verosimilitate a datelor
not. not.
X = < X1 , . . . , X5 > şi Z = < Z1 , . . . , Z5 >, ı̂n raport cu parametrii θA şi re-
spectiv θB ai distribuţiilor Bernoulli care modelează aruncarea celor două
monede.
not. not.
iii. Calculaţi θ̂A = arg maxθA log L1 (θA , θB ) şi θ̂B = arg maxθB log L1 (θA , θB )
folosind derivatele parţiale de ordinul ı̂ntâi.
Observaţii:
1. Baza logaritmului, fixată dar lăsată mai sus nespecificată, se va considera
supraunitară (de exemplu 2, e sau 10).
2. Lucrând corect, veţi obţine acelaşi rezultat ca la punctul i.
66.
Răspuns:
Funcţia de log-verosimilitate a datelor complete se exprimă astfel:
log L1 (θA , θB ) = −5 log 2 + 24 log θA + 6 log(1 − θA ) + 9 log θB + 11 log(1 − θB )
Prin urmare, maximul acestei funcţii ı̂n raport cu parametrul θA se cal-
culează astfel:
∂ log L1 (θA , θB ) 24 6 4 1
=0 ⇔ − =0⇔ = ⇔ 4 − 4 θA = θA ⇔ θ̂A = 0.8
∂θA θA 1 − θA θA 1 − θA
∂ log L1 (θA , θB )
Similar, se face calculul şi pentru şi se obţine θ̂B = 0.45.a
∂θB
Cele două valori obţinute, θ̂A şi θ̂B , reprezintă estimarea de verosimilitate
maximă (MLE) a probabilităţilor de apariţie a feţei ‘head’ (‘stema’) pentru
moneda A şi respectiv moneda B.
aSe verifică uşor faptul că ı̂ntr-adevăr rădăcinile derivatelor parţiale de ordinul ı̂ntâi
pentru funcţia de log-verosimilitate reprezintă puncte de maxim. Pentru aceasta se
studiază semnele acestor derivate.
67.
Observaţii
i Z i Xi
1 ? 5H (5T )
2 ? 9H (1T )
3 ? 8H (2T )
4 ? 4H (6T )
5 ? 7H (3T )
69.
Notă
Algoritmul EM ne permite să facem ı̂n mod iterativ estimarea parametrilor
θA şi θB ı̂n funcţie de valorile variabilelor observabile, Xi , şi de valorile
(0) (0)
inţiale atribuite parametrilor (ı̂n cazul nostru, θA = 0.6 şi θB = 0.5).
Vom face o sinteză a calculelor de la prima iteraţie a algoritmului EM —
detaliate la punctele iv, v şi vi de mai jos — sub forma următoare, care
seamănă ı̂ntr-o anumită măsură cu tabelele de la punctul A:
Notă (cont.)
Xi · E[Zi,A ] Xi · E[Zi,B ]
2.2H (2.2T ) 2.8H (2.8T )
7.2H (0.8T ) 1.8H (0.2T )
M
5.9H (1.5T ) 2.1H (0.5T )
⇒ 1.4H (2.1T ) 2.6H (3.9T ) ⇒
4.5H (1.9T ) 2.5H (1.1T )
P5 P5
i=1 X i · E[Z i,A ] = 21.3H i=1 Xi · E[Zi,B ] = 11.7H
P5 P5
i=1 (10 − X i ) · E[Z i,A ] = 8.7T i=1 (10 − Xi ) · E[Zi,B ] = 8.3T
(1) 21.3
θ̂A =
≈ 0.71
21.3 + 8.7
⇒
(1) 11.7
θ̂B
= ≈ 0.58
11.7 + 8.3
72.
Notă (cont.)
Vom arăta că:
• ı̂ntr-adevăr, este posibilă calcularea mediilor variabilelor neobservabile
Zi,A şi Zi,B , condiţionate de variabilele observabile Xi şi ı̂n funcţie de
valorile asignate iniţial (0.6 şi 0.5 ı̂n enunţ, dar ı̂n general ele se pot
asigna ı̂n mod aleatoriu) pentru parametrii θA şi θB ;
• faţă de tabloul de sinteză de la punctul precedent, când toate vari-
abilele erau observabile şi se calculau produsele Xi · Zi,A şi Xi · Zi,B , aici
se ı̂nlocuiesc variabilele Zi,A şi Zi,B cu mediile E[Z
P i,A ] şi E[Zi,B ] ı̂n pro-
dusele respective.
P De fapt, ı̂n loc să se calculeze i Xi ·Zi,A se calculează
media E[ i Xi · Zi,A ], şi similar pentru B.
Notaţie: Pentru simplitate, ı̂n cele de mai sus (inclusiv ı̂n tabelele prece-
dente), prin E[Zi,A ] am notat E[Zi,A | Xi , θ(0) ], iar prin E[Zi,B ] am notat
not. (0) (0)
E[Zi,B | Xi , θ(0) ], unde θ(0) = (θA , θB ).
73.
Răspuns (iv)
Întrucât variabilele Zi,A au valori boolene (0 sau 1), rezultă că
S-a ţinut cont că P (Zi,A = 1 | θ(0) ) = P (Zi,B = 1 | θ(0) ) = 1/2 (a se vedea
enunţul).
74.
Observaţie: Se poate ţine cont că, de ı̂ndată ce s-a calculat E[Zi,A | Xi , θ(0) ],
se poate obţine imediat şi E[Zi,B | Xi , θ(0) ] = 1 − E[Zi,A | Xi , θ(0) ], fiindcă
Zi,A + Zi,B = 1.
75.
Răspuns:
def.
L2 (θA , θB ) = EP (Z|X,θ(0) ) [log P (X, Z | θ)]
5
Y
indep. cdt.
= EP (Z|X,θ(0) ) [log P (Xi , Zi,A , Zi,B | θA , θB )]
i=1
Y5
reg. de mult.
= EP (Z|X,θ(0) ) [log P (Xi | Zi,A , Zi,B ; θA , θB ) · P (Zi,A, Zi,B | θA , θB )]
i=1
În continuare, omiţând din nou distribuţia probabilistă ı̂n raport cu care
se calculează media aceasta ı̂ntrucât ea poate fi subı̂nţeleasă, vom scrie:
77.
L2 (θA , θB )
5
Y Z Z 1
= E[log ·(θAi,A )Xi · [(1 − θA )Zi,A ]10−Xi · (θBi,B )Xi · [(1 − θB )Zi,B ]10−Xi · ]
i=1
2
5
X
= E[ [Xi · Zi,A · log θA + (10 − Xi ) · Zi,A · log(1 − θA ) +
i=1
5
X
E[ [Xi · Zi,B · log θB + (10 − Xi ) · Zi,B · log(1 − θB ) − log 2] ]
i=1
5
lin. med.
X
= [Xi · E[Zi,A ] · log θA + (10 − Xi ) · E[Zi,A ] · log(1 − θA ) +
i=1
5
X
[Xi · E[Zi,B ] · log θB + (10 − Xi ) · E[Zi,B ] · log(1 − θB ) − log 2]
5 i=1
X X ·E[Zi,A ] X ·E[Zi,B ] 1
= log[θA i · (1 − θA )(10−Xi )·E[Zi,A] · θB i · (1 − θB )(10−Xi )·E[Zi,B ] · ]
i=1
2
1
= log(θA2.2 · (1 − θA )2.2 · θB
2.8
· (1 − θB )2.8 · . . . · θA4.5 · (1 − θA )1.9 · θB
2.5
· (1 − θB )1.1 · ).
2
78.
Răspuns:
Răspuns:
Formulele care se folosesc ı̂n cadrul algoritmului EM pentru rezolvarea
problemei date — i.e. estimarea parametrilor θA şi θB atunci când vari-
abilele Zi sunt neobservabile —, se elaborează/deduc astfel:
81.
Pasul E:
E[Zi,A | X, θ] = P (Zi,A = 1 | X, θ) = P (Zi,A = 1 | Xi , θ)
1/2
z }| {
T. B. P (Xi | Zi,A = 1; θ) · P (Zi,A = 1 | θ)
=
P (Xi | Zi,A = 1; θ) · P (Zi,A = 1 | θ) + P (Xi | Zi,B = 1; θ) · P (Zi,B = 1 | θ)
| {z }
1/2
P (Xi | Zi,A = 1; θ)
=
P (Xi | Zi,A = 1; θ) + P (Xi | Zi,B = 1; θ)
θAXi (1 − θA )10−Xi
=
θAXi (1 − θA )10−Xi + θBXi
(1 − θB )10−Xi
Notând cu
− xi valoarea variabilei Xi ,
(t) (t)
− θA şi respectiv θB estimările parametrilor θA şi θB la iteraţia t a algo-
ritmului EM,
(t+1) (t+1) (t) (t)
− pi,A şi respectiv pi,B , mediile E[Zi,A | Xi , θA ] şi E[Zi,B | Xi , θB ],
vom avea:
(t) (t)
(t+1) (θA )xi (10 − θA )10−xi
pi,A = (t) (t) (t) (t)
(θA )xi (10 − θA )10−xi + (θB )xi (10 − θB )10−xi
(t) (t)
(t+1) (θB )xi (10 − θB )10−xi
pi,B = (t) (t) (t) (t)
(θA )xi (10 − θA )10−xi + (θB )xi (10 − θB )10−xi
83.
Pasul M:
Ca şi mai ı̂nainte, ı̂n formulele de mai jos vom folosi notaţiile simplificate
not. not.
E[Zi,A ] = E[Zi,A | Xi , θ(t) ] şi E[Zi,B ] = E[Zi,B | Xi , θ(t) ].
Cu aceste notaţii, procedând similar cu calculul de la partea B, punctul v,
vom avea:
5
Y x E[Zi,A ] x E[Zi,B ]
L2 (θA , θB ) = log θAi (1 − θA )(10−xi )E[Zi,A] θBi (1 − θB )(10−xi )E[Zi,B ]
i=1
84.
Prin urmare,
5 5
∂ 1 X 1 X
L2 (θA , θB ) = 0 ⇒ xi E[Zi,A ] = (10 − xi )E[Zi,A ]
∂θA θA i=1 1 − θA i=1
5
X 5
X
⇒ (1 − θA ) xi E[Zi,A ] = θA (10 − xi )E[Zi,A ]
i=1 i=1
5
X 5
X
⇒ xi E[Zi,A ] = 10 θA E[Zi,A ]
i=1 i=1
P5 P5
xi E[Z i,A ] i=1 xi E[Zi,B ]
⇒ θA = i=1
P şi, similar, θB = P
10 5i=1 E[Zi,A ] 10 5i=1 E[Zi,B ]
Aşadar, la pasul M al algoritmului EM vom avea:
P5 (t+1) P5 (t+1)
(t+1) i=1 xi pi,A (t+1) i=1 xi pi,B
θA = P5 (t+1) şi θB = P5 (t+1)
10 i=1 pi,A 10 i=1 pi,B
85.
Observaţie
Zi ∼ Categorical(π)
Xi ∼ Categorical(θZi )
89.
For this model, where we observe X but not Z, we want to learn the parame-
ters of the K categorical components Θ = {π, θ1 , . . . , θK }, where each θk ∈ RM is
the parameter for the categorical distribution associated with the k-th mix-
ture component. (It implies that each Xi can take on one of M possible
values). We will use the EM algorithm to accomplish this.
d. What is the update step for Θ? That is, what Θ maximizes Q(Θ|Θ′ )?
Hint: Make sure your solution enforces the constraint that parameters to
categorical distributions must sum to 1. Lagrange multipliers are a great way
to solve constrained optimization problems.
91.
Answer:
a.
n
Y n
Y
P (X, Z; Θ) = P (Xi , Zi ; Θ) = P (Xi |Zi ; Θ)P (Zi ; Θ)
i=1 i=1
1{Z
K
n Y M i =k}
Y Y 1{X =v }
= πk θkj i j
i=1 k=1 j=1
b.
P (Xi |Zi = k; Θ)P (Zi = k; Θ)
Bayes F.
P (Zi = k|Xi ; Θ) =
P (Xi ; Θ)
QK QM 1{Xi =vj } 1{Zi =k}
k=1 πk j=1 θkj
P (Xi |Zi = k; Θ)P (Zi = k; Θ)
= PK = PK QM 1{Xi =vj }
l=1 P (Zi = l; Θ)P (Xi |Zi = l; Θ) l=1 πl j=1 θlj
92.
c.
def.
Q(Θ|Θ′ ) = EZ|X;Θ′ [log P (X, Z; Θ)]
1{Z =k}
n K M i
a. Y Y Y 1{Xi =vj }
= EZ|X;Θ′ log πk θkj
i=1 k=1 j=1
X K
n X M
X
= EZ|X;Θ′ 1{Zi =k} log πk + 1{Xi =vj } log θkj
i=1 k=1 j=1
X K
n X M
X
= EZ|X;Θ′ [1{Zi =k} ] log πk + 1{Xi =vj } log θkj
i=1 k=1
| {z } j=1
P (Zi =k|Xi ;Θ)
Using
QM 1
not. ′ b.
′
πk′
j=1 (θkj )
{Xi =vj }
γik = EZ|X;Θ′ [1{Zi =k} ] = P (Zi = k|Xi ; Θ ) = PK ,
′ )1{Xi =vj }
′
QM
π
l=1 l (θ
j=1 lj
leads to
X K
n X M
X
Q(Θ|Θ′ ) = γik log πk + 1{Xi =vj } log θkj
i=1 k=1 j=1
93.
d. To find the updates rules for the parameters, we solve the following constrained
optimization problem:
maxπ,θ1:K Q(Θ|Θ′ )
PK
subject to k=1 πk = 1
PM
j=1 θkj = 1, ∀k = 1, . . . , K
We introduce a Lagrange multiplier for each constraint associated to this problem and
form the Lagrangian functional :
!
K
X K
X M
X
L = Q(Θ|Θ′ ) + λπ 1 − πk + λθk 1 − θkj
k=1 k=1 j=1
Now we will differentiate the Lagrangian functional with respect to each parameter we
want to optimize, set the derivative to zero, and solve for the optimal value.
94.
We’ll start with optimizing for π, the parameter to the categorical distribution for the
latent variables Z.
n n
∂L X 1 ∗ 1 X
=0⇔ γik · − λπ = 0 ⇔ πk = γik
∂πk i=1
πk λ π i=1
We can find the value of the Lagrange multiplier λπ by enforcing the constraint:
K K n K n
X X 1 X 1 XX
πk∗ =1⇔ γik = 1 ⇔ γik = 1 ⇔
λπ i=1 λπ i=1
k=1 k=1 k=1
X n
K X n X
X K
λπ = γik ⇔ λπ = γik ⇔ λπ = n
k=1 i=1 i=1 k=1
| {z }
1
Substituting this value for λπ back into the expression of πk∗ gives the answer:
n
1X
πk∗ = γik
n i=1
95.
The process for optimizing the observation parameters θkj is similar. First, we differ-
entiate the Lagrangian L with respect to θkj , set to zero, and [finally] solve.
n
∂L X 1
=0⇔ γik 1{Xi =vj } · − λθk = 0
∂θkj i=1
θ kj
n
∗ 1 X
⇒ θkj = γik 1{Xi =vj }
λθk i=1
Again, we can find the value of the Lagrange multiplier λθk by enforcing the summation
constraint:
M M n M n
X
∗
X 1 X 1 XX
θkj =1⇔ γik 1{Xi =vj } = 1 ⇔ γik 1{Xi =vj } = 1
j=1
λ
j=1 θk i=1
λθk j=1 i=1
M X
X n
⇔ λθk = γik 1{Xi =vj }
j=1 i=1
∗
Substituting this value for λθk back into the expression of θkj gives the answer:
Pn Pn
∗ γ 1
i=1 ik {Xi =vj } i=1 γik 1{Xi =vj }
θkj = PM Pn = Pn PM
l=1 i=1 γ ik 1 {Xi =vl } i=1 l=1 γik 1{Xi =vl }
96.
where
πm denotes the prior [probability] for the latent topic variable t = m,
not. PV
µk = (µk (1), . . . , µk (i), . . . , µk (V )), with µk (i) ≥ 0 for i = 1, . . . , V and i=1 µm (i) = 1 for
each k = 1, . . . , K, and
not.
µm (i) = P (w(i) = 1|t = m).
98.
Answer:
not. P (wj |tj = m; θ) P (tj = m|θ)
Bayes T.
Fj (tj = m) = P (tj = m|wj ; θ) =
P (wj |θ)
QV
πm P (wj |µm) πm l=1 µm (l)wj (l)
= PK = PK QV wj (l)
m′ =1 πm′ P (wj |µm′ ) m′ =1 πm′ l=1 µm′ (l)
99.
Hint: Suming over the latent topic variable, we can write l(w; θ) as
N N P
X X X
t P (wj , t; θ)
l(w; θ) = log P (wj , t; θ) = log Fj (t)
j=1 t j=1
Fj (t)
Answer:
N X
X K
θ = argmax Fj (tj = m) log P (wj , tj = m|θ)
θ
j=1 m=1
N X
X K
= argmax Fj (tj = m) log P (wj |tj = m; θ) P (tj = m|θ)
θ j=1 m=1
K
N X V
!
X Y
= argmax Fj (tj = m) log πm µm (l)wj (l)
θ j=1 m=1 l=1
X K
N X V
X
= argmax [Fj (tj = m) log πm + Fj (tj = m) log µm (l)wj (l) ]
θ j=1 m=1 l=1
X K
N X V
X
= argmax [Fj (tj = m) log πm + Fj (tj = m) wj (l) log µm (l)] (3)
θ
j=1 m=1 l=1
To optimize µm (l): 101.
After eliminating from (3) the terms which are constant with respect to µm we get:
N
X V
X
Fj (tj = m) wj (l) log µm (l)
j=1 l=1
Note: Intuitively the last expression can be interpreted as the portion [of
word[ occurrence]s] that belongs to cluster m among the total of N words.
105.
To summarize:
E step: QV
πmµm (l)wj (l)
l=1
Fj (tj = m) = PK QV for j = 1, . . . , N and m = 1, . . . , K
w (l)
m′ =1 πm′ l=1 µm′ (l)
j
M step: PN
j=1 Fj (tj = m) wj (l)
µm (l) = PN for m = 1, . . . , K and l = 1, . . . , V
j=1 Fj (tj = m)
PN
j=1 Fj (tj = m)
πm = for m = 1, . . . , K
N
106.
0.4
The Poisson distribution is a distribu- λ=1
tion over positive count values; for a λ=4
0.3
λ = 10
count x with parameter λ, the Poisson
1 λx
has the form Poisson(x|λ) = λ · .
p(x)
0.2
e x!
It can be proven that the maximum
0.1
likelihood estimation for λ given a se-
quence of counts x1 , . . . , xn was simply
0.0
1 Pn
xi – the mean of the counts. 0 5 10 15 20
n i=1
x
where
not. not.
x̄ = (x1 , . . . , xn ), with xi = (xi,1 , . . . , xi,M ) for i = 1, . . . , n,
not. not. not.
z̄ = (z1 , . . . , zK ), π̄ = (π1 , . . . , πK ); λ̄ = (λ1 , . . . , λK ), and
1{zi =k} is one if zi = k and zero otherwise.
110.
Solution
The likelihood function:
K
n Y
" M x
#1{zi =k}
Y Y 1 λk i,m
L(λ̄, π̄) = πk λk x
i=1 k=1 m=1
e i,m !
E-step:
(t) not.
pik = P (zi = k|xi , λ̄(t) , π̄ (t) )
M-step:
PK
Since k=1 πk = 1, we have to introduce the Lagrange multiplier λ:
" K
#
∂ X
Q(λ̄, π̄|λ̄(t) , π̄ (t) ) + λ(1 − πk ) = 0 ⇔
∂πk
k=1
n (t) n
X pik (t+1) 1 X (t)
− λ = 0 ⇔ πk = p
i=1
πk λ i=1 ik
(t+1)
It is easy to see that πk is indeed a maximum point for Q w.r.t. the pa-
rameter πk .
PK (t+1)
Imposing the constraint k=1 πk = 1 leads to:
K n n K
1 X X (t) 1 X X (t) n
pik = 1 ⇔ pik = 1 ⇔ = 1 ⇔ λ = n.
λ λ i=1 λ
k=1 i=1 k=1
| {z }
1
(t+1) 1 Pn (t)
Therefore, πk = i=1 pik , which is alyways a non-negative quantity.
n
113.
n M
! n M
! n
X 1 X 1 X X X
pik −M + xi,m =0⇔ pik xi,m =M pik ⇔
i=1
λk m=1 λk i=1 m=1 i=1
Pn P
M
i=1 pik m=1 xi,m
(t+1)
λk = Pn
M i=1 pik
(t+1)
It can be easily shown that for each k ∈ {1, . . . , K}, the value λk
is positive, and it maximizes Q w.r.t. the parameter λk .
114.
not. not.
with r = (r1 , . . . , rK ), β = (β1 , . . . , βK ), θ = (r, β), and θk = (rk , βk ) for k = 1, . . . , K,
PK
and πk > 0 for k = 1, . . . , K and k=1 πk = 1.
E step
π
z }|k {
(t+1) not. Bayes F. Gamma(xi |zi = k, θ) · P (zi = k|θ)
γik = P (zi = k|xi , θ(t) ) = PK
k′ =1 Gamma(xi |zi = k ′ , θ) · P (zi = k ′ |θ)
| {z }
πk ′
Gamma(xi |θk ) · πk
= PK
k′ =1 Gamma(xi |θk′ ) · πk′
(t+1)
Note that γik > 0 for k = 1, . . . , K because xi > 0 for i = 1, . . . , n.
118.
M step: πk
PK
Because k=1 πk = 1, we will use a Lagrange multiplier λ, and solve as usually:
" K
!# n n
∂ X X1 1 X
Q(θ|θ(t) ) + λ 1 − πk =0⇔ γik −λ=0⇔ γik = λ ⇔
∂πk i=1
π k πk i=1
k=1
n
(t+1) 1X
πk = γik
λ i=1
PK
By substituting this expression into the constraint k=1 πk = 1, we will get:
K n n K
1 XX 1 XX 1
γik = 1 ⇔ γik = 1 ⇔ n = 1 ⇔ λ = n
λ λ i=1 λ
k=1 i=1 k=1
| {z }
1
Therefore,
n
(t+1) 1X
πk = γik k (t+1)
n i=1
(t+1)
Note that πk > 0 for k = 1, . . . , K.
119.
M step: βk
n " n #
∂ X rk xi 1 X
Q(θ|θ(t) ) = 0 ⇔ γik − + 2 = 0 ⇔ 2 γik (xi − rk βk ) = 0
∂βk i=1
βk βk βk i=1
n
X n
X n
X n
X n
X
⇔ γik (xi − rk βk ) = 0 ⇔ γik rk βk = γik xi ⇔ rk βk γik = γik xi
i=1 i=1 i=1 i=1 i=1
Therefore,
Pn (t+1) (t+1)
(t+1) γ xi
βk = Pnik
i=1
for k = 1, . . . , K.
rk i=1 γik
(t+1)
It can be easily shown that βk is always positive, and it maxi-
mizes Q(θ|θ(t) ) w.r.t. βk .
120.
M step: rk
(t+1)
By substituting [the expression of] βk into Q(θ|θ(t) ), we will get:
n K
" #
(t+1) (t)
XX xi
Q(r, β |θ ) = γik ln πk − rk ln β (t+1) − ln Γ(rk ) + (rk − 1) ln xi − (t+1)
i=1 k=1 βk
Then, solving for the partial derivative of Q(r, β (t+1) |θ(t) ) w.r.t. rk ,
amounts to:
∂
Q(r, β (t+1) |θ(t) ) = 0 ⇔
∂rk
n
" #
∂ X (t+1) (t+1) xi
γik ln πk − rk ln βk − ln Γ(rk ) + (rk − 1) ln xi − (t+1)
=0⇔
∂rk i=1 βk
n
" #
′
X (t+1) (t+1) ∂ (t+1) Γ (rk ) ∂ 1
γik − ln βk − rk ln βk − + ln xi − xi =0
i=1
∂rk Γ(rk ) ∂rk β (t+1)
k
121.
Since
Pn (t+1) Pn (t+1)
!
∂ (t+1) ∂ γ
i=1 ik xi ∂ γ
i=1 ik xi 1
ln βk = ln Pn (t+1)
= − ln rk + ln Pn (t+1)
=−
∂rk ∂rk rk i=1 γik ∂rk rk
i=1 γik
and
Pn (t+1) Pn (t+1)
∂ 1 ∂ rk i=1 γik i=1 γik
= P = Pn ,
∂rk β (t+1) ∂rk n γ (t+1) xi γ
(t+1)
xi
k i=1 ik i=1 ik
it follows that
∂
Q(r, β (t+1) |θ(t) ) = 0 ⇔
∂rk
n
" Pn (t+1) Pn (t+1)
#
′
i′ =1 γi′ k xi′ Γ (rk ) i′ =1 γi′ k
X (t+1)
γik ln rk − ln Pn (t+1)
+1− + ln xi − xi Pn (t+1)
=0
Γ(rk )
i=1 i′ =1 γi′ k i′ =1 γi′ k xi′
122.
Therefore,
n
Γ′ (rk ) X (t+1)
ln rk − γ =
Γ(rk ) i=1 ik
n Pn (t+1) n n n Pn (t+1)
X (t+1) i′ =1 γi′ k xi′ X (t+1)
X (t+1)
X (t+1) i′ =1 γi′ k
γik ln Pn (t+1)
− γik − γik ln xi + γik xi · Pn (t+1)
⇔
i=1 i′ =1 γi′ k i=1 i=1 i=1 i′ =1 γi′ k xi′
n n Pn (t+1) n
Γ′ (rk ) X (t+1)
X (t+1) i′ =1 γi′ k xi′ X (t+1)
ln rk − γik = γik ln Pn (t+1)
− γik ln xi
Γ(rk ) i=1 i=1 i′ =1 γi′ k i=1
So,
Pn (t+1) Pn (t+1)
Γ′ (rk ) γ
i=1 ik xi i=1 γik ln xi
ln rik − = ln Pn (t+1)
− Pn (t+1)
Γ(rk ) γ γ
i=1 ik i=1 ik
Γ′ (rk )not
Note: The function ψ(r) = ln rik − is the so-called di-gamma function.
Γ(rk )
123.
Note
a.
Given a data point x, and a value for the mixture parameter λ,
compute the probability that x was generated from density f1 .
b.
Now, suppose you are given a data set {x1 , . . . , xn } drawn i.i.d. from the
mixture density, and a set of coin flips {z1 , z2 , . . . , zn }, such that zi = 1 means
that xi is a sample from f1 , and zi = 0 means that xi was generated from
density f2 .
For a fixed parameter λ, compute the complete log-likelihood of the data,
i.e., ln P (x1 , z1 , x2 , z2 , . . . , xn , zn |λ).
c.
Now, suppose you are given only a sample {x1 , . . . , xn } drawn i.i.d. from
the mixture density, without the knowledge about which component the
samples were drawn from (i.e., the zi are unknown).
Using your derivations from part a and b, derive the E- and M-steps for
an EM algorithm to compute the maximum likelihood estimate (MLE) of
the mixture parameter λ.
127.
Solution
P (X = x|Z = 1) · P (Z = 1) λf1 (x)
a. P (Z = 1|X = x) = = .
P (X = x) fλ (x)
Qn Qn
b. P (x1 , z1 , x2 , z2 , . . . , xn , zn |λ) = i=1 P (xi , zi |λ) = i=1 (P (xi |zi , λ) · P (zi |λ)).
(
λf1 (xi ) if zi = 1
P (xi |zi , λ) · P (zi |λ) =
(1 − λ)f2 (xi ) if zi = 0
= λzi f1 (xi )zi (1 − λ)1−zi f2 (xi )1−zi
Therefore,
n
X
ln P (x1 , z1 , x2 , z2 , . . . , xn , zn |λ) = ln P (xi , zi |λ)
i=1
Xn
= ln λzi f1 (xi )zi (1 − λ)1−zi f2 (xi )1−zi
i=1
Xn
= zi ((ln λ + ln f1 (xi )) + (1 − zi )(ln(1 − λ) + ln f2 (xi )))
i=1
128.
c.
not. (t) [Link]. λ(t) f1 (xi )
E-step: q(zi ) = P (zi = 1|xi , λ ) =
fλ(t) (xi )
M-step:
n
Y
(t+1)
λ = argmax Eq [ln P (x1 , z1 , x2 , z2 , . . . , xn , zn |λ)]
λ i=1
Xn n
X
= argmax(ln λ · q(zi ) + ln(1 − λ) · (1 − q(zi )))
λ i=1 i=1
| {z } | {z }
c n−c
∂ c n−c
(c ln λ + (n − c) ln(1 − λ)) = 0 ⇔ =
∂λ λ 1−λ
Pn
c q(zi )
⇔ c(1 − λ) = λ(n − c) ⇔ c = nλ ⇔ λ = = i=1
n n
n
(t+1) λ(t) X f1 (xi )
⇒ λ =
n i=1 fλ(t) (xi )
∂2 c 1
Note: 2
(c ln λ + (n − c) ln(1 − λ)) = − − (n − c) 2
≤ 0 ⇒ λ(t+1) corresponds to a
∂λ λ (1 − λ)
maximum.
129.
Note
Explanation:
def.
F (x) = P (Z1 + Z2 < x)
Z x Z x−z2
= fλ1 (z1 ) dz1 · fλ2 (z2 ) dz2
0 0
Z x Z x−z1 Z x Z x−z1
= fλ2 (z2 ) dz2 · fλ1 (z1 ) dz1 = fλ1 (z1 ) · fλ2 (z2 ) dz2 dz1 .
0 0 0 0
133.
1.0
1.5
λ = 0.5
λ=1
0.8
λ = 1.5
1.0
0.6
P(X ≤ x)
p(x)
0.4
0.5
λ = 0.5
0.2
λ=1
λ = 1.5
0.0
0.0
0 1 2 3 4 5 0 1 2 3 4 5
x x
134.
Answer
The c.d.f. of X:
Z x Z x−z1 Z x Z x−z1
def.
F (x) = P (Z1 + Z2 < x) = fλ1 (z1 ) · fλ2 (z2 ) dz2 dz1 = λ1 e−λ1 z1 · λ2 e−λ2 z2 dz2 dz1
0 0 0 0
Z x Z x−z1 Z x
−λ2 z2 x−z1
= (−λ1 )e−λ1 z1 (−λ2 )e −λ2 z2
dz2 dz1 = (−λ1 )e −λ1 z1
e 0
dz1
0 0 0
Z !
x
= (−λ1 )e−λ1 z1 e−λ2 (x−z1 ) − |e−λ 2 ·0
{z } dz1
0 1
Z x Z x
= (−λ1 )e−λ1 z1 e−λ2 (x−z1 ) dz1 − (−λ1 )e−λ1 z1 dz1
0 0
Z x Z x
−λ1 −λ2 x (λ2 −λ1 )z1
= e (λ2 − λ1 )e dz1 − (−λ1 )e−λ1 z1 dz1
λ2 − λ1 0 0
λ1
x x
= − e−λ2 x e(λ2 −λ1 )z1 − e−λ1 z1 0
λ2 − λ1 0
λ1 λ1 λ1
−λ2 x (λ2 −λ1 )x
= − e e − 1 − e−λ1 x − 1 = − e−λ1 x + e−λ2 x − e−λ1 x + 1
λ2 − λ1 λ2 − λ1 λ2 − λ1
1 −λ1 x −λ2 x −λ1 x −λ1 x
λ2 e−λ1 x − λ1 e−λ2 x
= 1− λ1 e − λ1 e + λ2 e − λ1 e = 1−
λ2 − λ1 λ2 − λ1
135.
The p.d.f. of X:
∂F (x) 1 λ1 λ2
p(x) = =− −λ1 λ2 e−λ1 x + λ1 λ2 e−λ2 x = e−λ1 x − e−λ2 x
∂x λ2 − λ1 λ2 − λ1
136.
b. Derive the E-step and M-step of the EM algorithm, and give explicit
expressions for the parameter updates in the EM process for computing the
MLE of λ1 and λ2 .
λ = (λ1 , λ2 )
λ(t) = valoarea parametrului λ la iteraţia t
X = variabila observabilă, cu instanţele x1 , x2 , . . . , xn
Z = (Z1 , Z2 ) variabilele ascunse/neobservabile
având valorile z1j , z2j , . . . , znj cu j ∈ {1, 2},
aşa ı̂ncât xi = zi1 + zi2 .
137.
i=1
" n #
X
= EP (Z|X,λ(t) ) (log λ1 − λ1 zi1 + log λ2 − λ2 zi2 )
i=1
" n
#
X
= EP (Z|X,λ(t) ) n log λ1 + n log λ2 − (λ1 zi1 + λ2 zi2 )
i=1
n
X n
X
= n log λ1 + n log λ2 − λ1 Ep(zi1 |xi ,λ(t) ) [zi1 ] − λ2 Ep(zi2 |xi ,λ(t) ) [zi2 ]
i=1 i=1
138.
Solution: E step; computation of expectations
Z xi
def.
Ep(zi1 |xi ,λ(t) ) [zi1 ] = zi1 · p(zi1 | xi , λ(t) ) dzi1
0
(t) (t)
(t) (t) e(λ2 −λ1 )zi1
= (λ2 − λ1 ) · (t) (t)
e(λ2 −λ1 )xi −1
139.
Z Z (t) (t)
xi xi (λ2 −λ1 )zi1
def. (t) (t) (t) e
⇒ Ep(zi1 |xi ,λ(t) ) [zi1 ] = zi1 · p(zi1 | xi , λ ) dzi1 = zi1 · (λ2 − λ1 ) · (t) (t)
dzi1
0 0 e(λ2 −λ1 )xi −1
Z xi
1 (t) (t) (t) (t)
= (t) (t)
zi1 · (λ2 − λ1 ) · e(λ2 −λ1 )zi1
dzi1
e(λ2 −λ1 )xi −1 0
Vom rezolva ultima integrală de mai sus utilizând formula de integrare prin părţi.
Z xi Z xi
(t) (t) (t) (t)
(λ2 −λ1 )zi1 ∂ (λ2(t) −λ1(t) )zi1
zi1 · (λ2 − λ1 ) · e dzi1 = zi1 · e dzi1
0 0 ∂z i1
xi Z xi
(t) (t) (t) (t)
(λ2 −λ1 )zi1
= zi1 · e − e(λ2 −λ1 )zi1 dzi1
0 0
(t) (t)
xi (λ2 −λ1 )xi
(t) (t)
(λ2 −λ1 )xi
1 (t) (t)
(λ2 −λ1 )zi1
(t) (t) e −1
= xi · e(λ2 −λ1 )xi −
= xi · e −0 − (t) (t)
·e (t) (t)
λ2 − λ1 0 λ2 − λ1
Prin urmare, !
(t) (t)
(λ2 −λ1 )xi
1 (t) (t) e −1
Ep(zi1 |xi ,λ(t) ) [zi1 ] = (t) (t)
· xi · e(λ2 −λ1 )xi
− (t) (t)
e(λ2 −λ1 )xi −1 λ2 − λ1
(t) (t)
xi · e(λ2 −λ1 )xi
1
= (t) (t)
− (t) (t)
e (λ2 −λ1 )xi −1 λ2 − λ1
140.
xi = zi1 + zi2
⇒ Ep(zi2 |xi ,λ(t) ) [zi2 ] = Ep(zi2 |xi ,λ(t) ) [xi − zi1 ] = xi − Ep(zi2 |xi,λ(t) ) [zi1 ]
= xi − Ep(z|xi,λ(t) ) [zi1 ] = xi − Ep(zi1 |xi,λ(t) ) [zi1 ]
(t) (t)
(λ2 −λ1 )xi
xi · e 1
= xi − (t) (t)
+ (t) (t)
e(λ2 −λ1 )xi −1 λ2 − λ1
1 xi
= (t) (t)
− (t) (t)
λ2 − λ1 e(λ2 −λ1 )xi −1
141.
Solution: M step
n
∂ n X
Q(λ | λ(t) ) = 0 ⇔ = Ep(zi1 |xi ,λ(t) ) [zi1 ]
∂λ1 λ1 i=1
(t+1) n
⇒ λ1 = Pn >0
E
i=1 p(zi1 |xi ,λ ) i1(t) [z ]
n
∂ n X
Q(λ | λ(t) ) = 0 ⇔ = Ep(zi2 |xi ,λ(t) ) [zi2 ]
∂λ2 λ2 i=1
(t+1) n
⇒ λ2 = Pn >0
i=1 E p(z i2 |x i ,λ(t) ) [zi2 ]
Observaţie:
Se verifică imediat că aceste soluţii ı̂ntr-adevăr maximizează Q(λ | λ(t) ).
142.
E-step:
En1 |xi ,λ(t) [ℓ(λ)] is the expected number of unobservable instances zj having value 1, out
of the total of n − m unobservable instances.
The definition of the density function for the Poisson distribution implies
1 λ1 1 1 λ0 1
P (x = 1|λ) = λ · = λ · λ and P (x = 0|λ) = λ · = λ.
e 1! e e 0! e
Therefore E[n1 |xi , λ(t) ] is exactly the expectation of the binomial distribution
λ(t)
Bin n − m; . So,
1 + λ(t)
(t) λ(t)
E[n1 |xi , λ ] = (n − m) .
1 + λ(t)
146.
M-step:
Now we can write
" m
# m
(t)
λ X X
Q(λ|λ(t) ) = −nλ + (n − m) + xi ln λ − ln xi !.
1 + λ(t) i=1 i=1
Pm
From the problem’s statement we know that n > m and i=1 xi ≥ 0.
At the initialization step of the EM algorithm the parameter λ is asigned a
positive value (λ(0) ), and we will soon see that λ(t) > 0 at each iteration t > 0.
Therefore, the second derivative of Q is always negative, meaning that Q is
concave and therefore it has a maximum.
In order to find this maximum we equate the first derivative to 0, which gives
us the update equation:
" m
#
(t)
1 λ X
λ(t+1) = (n − m) + xi
n 1 + λ(t) i=1
One can easily see now (ny induction) that λ(t+1) > 0.