52
MAPSI — cours 4 : Expectation-Maximization (EM) Christophe Gonzales LIP6 – Universit´ e Paris 6, France

MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

MAPSI — cours 4 :Expectation-Maximization (EM)

Christophe Gonzales

LIP6 – Universite Paris 6, France

Page 2: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Motivations : Systeme de recommandation

ArmelleBernard

Damien Claude

Armelle, Bernard, Claude=⇒ notes films (rA, rB, rC)

Probleme : quel film conseiller aDamien?

Solution : echantillons〈rA, rB, rC , rD〉 =⇒ P(rA, rB, rC , rD)

conseiller Damien en exploitantP(rD|rA, rB, rC)

Cours 3 : determination de P(rA, rB, rC , rD) par maximum devraisemblance ou MAP

MAPSI — cours 4 : Expectation-Maximization (EM) 2/52

Page 3: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Motivations : Systeme de recommandation

Film rA rB rC rD

I robot 4 2 3 3

Forest Gump 1 3 2 4

Intouchables 2 2 3 2

Le parrain 1 3 2 1

Pulp fiction 2 4 3 4

evaluations : 1,2,3,4P(rD|rA, rB, rC) : distribution multivarieeΘ = parametres de P(rD|rA, rB, rC) =⇒ 44 = 256 parametres θi∑

rDP(rD|rA, rB, rC) = 1 =⇒ 3× 43 = 192 θi

MAPSI — cours 4 : Expectation-Maximization (EM) 3/52

Page 4: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Motivations : Systeme de recommandation

Vraisemblance : L(x,Θ) =∏

film θfilmθabcd : parametre pour un film ayant obtenu (rA = a, rB = b, rC = c, rD = d)

Nabcd : nombre de films ayant obtenu (rA = a, rB = b, rC = c, rD = d)

L(x,Θ) =4∏

a=1

4∏b=1

4∏c=1

(1−3∑

d=1

θabcd

)Nabc4 ∏d=13

θNabcdabcd

log L(x,Θ) =

4∑a=1

4∑b=1

4∑c=1

[Nabc4 log

(1−

3∑d=1

θabcd

)+∑d=13

Nabcd log θabcd

]

∂ log L(x,Θ)

θabcd= − Nabc4

1−∑3

d ′=1 θabcd ′+

Nabcd

θabcd= 0 ∀d ∈ {1,2,3}

−Nabc4θabcd + Nabcd

(1−

3∑d ′=1

θabcd ′

)= 0 ∀d ∈ {1,2,3}

MAPSI — cours 4 : Expectation-Maximization (EM) 4/52

Page 5: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Motivations : Systeme de recommandation

−Nabc4θabcd + Nabcd

(1−

3∑d ′=1

θabcd ′

)= 0 ∀d ∈ {1,2,3}

Nabc4

Nabcdθabcd +

3∑d ′=1

θabcd ′ = 1 ∀d ∈ {1,2,3}

1 + Nabc4Nabc1

1 11 1 + Nabc4

Nabc21

1 1 1 + Nabc4Nabc3

θabc1θabc2θabc3

=

111

θabcd =Nabcd∑4

d ′=1 Nabcd ′

MAPSI — cours 4 : Expectation-Maximization (EM) 5/52

Page 6: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Motivations : Systeme de recommandation

Film rA rB rC rD

I robot 4 2 3 3

Forest Gump 1 3 2 4

Intouchables 2 2 3 2

Le parrain 1 3 2 1

Pulp fiction 2 4 3 4

Film rA rB rC rD

I robot 4 3 3

Forest Gump 2 4

Intouchables 2 2 3

Le parrain 1 2

Pulp fiction 2 4 3 4

∑rD

P(rD|rA, rB, rC) = 1 =⇒ 3× 43 = 192 θi

probabilites =⇒ au moins 2000 evaluations

certains films n’ont pas ete vus =⇒ donnees manquantes

Probleme : comment estimer P(rD|rA, rB, rC) ?

MAPSI — cours 4 : Expectation-Maximization (EM) 6/52

Page 7: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Motivations : reconstruction de genotypes

MAPSI — cours 4 : Expectation-Maximization (EM) 7/52

Page 8: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Motivations : reconstruction de genotypes

MAPSI — cours 4 : Expectation-Maximization (EM) 8/52

Page 9: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Motivations : reconstruction de genotypes

Genotype, phenotype

Genotype = paire d’alleles d’un segment d’ADN.Phenotype = caractere observable d’un genotype.

Exemple : groupe sanguin (alleles A, B, O)

genotype phenotype X YAA A 1 1AB AB 2 3AO A 3 1BB B 4 2BO B 5 2OO O 6 4

6 genotypes mais seulement 4 phenotypes !

Probleme : Apprendre en presence de variables latentes

MAPSI — cours 4 : Expectation-Maximization (EM) 9/52

Page 10: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Motivations : tracking avec occlusions

MAPSI — cours 4 : Expectation-Maximization (EM) 10/52

Page 11: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Motivations : resume

Problemes etudies dans ce cours :

1 estimation de parametres en presence de donneesmanquantes

2 estimation de parametres en presence de variableslatentes

Solution : l’algorithme EM

MAPSI — cours 4 : Expectation-Maximization (EM) 11/52

Page 12: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Plan du cours n◦4

1 Principes d’apprentissage avec donnees manquantes

2 Quelques rappels de maths

3 L’algorithme EM

4 Pourquoi fonctionne-t-il ?

5 Mixtures de Gaussiennes et EM

MAPSI — cours 4 : Expectation-Maximization (EM) 12/52

Page 13: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Apprentissage avec donnees manquantes : principes

X Ya ?a ?a ?a ?a ca ca ca db cb cb db d

Algorithme naıf :

Supprimer les enregistrements avec ?

=⇒

X Ya ca ca ca db cb cb db d

Donnees completes

Apprentissage : cf. cours precedents

Probleme :Tableau gauche : P(X = a) = 2/3Tableau droit : P(X = a) = 1/2

=⇒ essayer de tenir compte de tous les enregistrements

MAPSI — cours 4 : Expectation-Maximization (EM) 13/52

Page 14: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Apprentissage avec donnees manquantes : principes

Algorithme k-means :

Remplacer les ? par leur valeur la plus probable

X Ya ?a ?a ?a ?a ca ca ca db cb cb db d

=⇒

X Ya ca ca ca ca ca ca ca db cb cb db d

Donnees completes

Apprentissage : cf. cours precedents

Probleme :Tableau gauche : P(Y = c|X = a) = 3/4(sur les donnees observees)

Tableau droit : P(Y = c|X = a) = 7/8

=⇒ essayer de tenir compte de toutes lesvaleurs possibles de Y

MAPSI — cours 4 : Expectation-Maximization (EM) 14/52

Page 15: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Apprentissage avec donnees manquantes : principes

Algorithme naıf 2 :

Remplacer les ? par toutes les valeurs possibles

X Ya ?a ?a ?a ?a ca ca ca db cb cb db d

=⇒

X Ya ca da ca da ca da ca d

X Ya ca ca ca db cb cb db d

Problemes :Tableau gauche : P(X = a) = 2/3

Tableau droit : P(X = a) = 3/4

Tableau gauche : P(Y = c|X = a) = 3/4

Tableau droit : P(Y = c|X = a) = 7/12

=⇒ essayer de tenir compte desdistributions des valeurs

MAPSI — cours 4 : Expectation-Maximization (EM) 15/52

Page 16: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Apprentissage avec donnees manquantes : principes

Algorithme EM :

Remplacer les ? par toutes les valeurs possiblesponderees par leur probabilite d’apparitionX Y

a ?a ?a ?a ?a ca ca ca db cb cb db d

=⇒

X Y wa c 3/4a d 1/4a c 3/4a d 1/4a c 3/4a d 1/4a c 3/4a d 1/4

X Y wa c 1a c 1a c 1a d 1b c 1b c 1b d 1b d 1

Apprentissage =⇒ comptages

=⇒ sommer les poids

=⇒ P(X = a) = 812 = 2

3

=⇒ P(Y = c|X = a) = 68 = 3

4

=⇒ Tableau gauche = droit

MAPSI — cours 4 : Expectation-Maximization (EM) 16/52

Page 17: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Apprentissage avec donnees manquantes : principes

K-means : remplacer? par la valeur la plus probable

EM : Remplacer? par toutes les valeurs possiblesponderees par leur probabilite d’apparition

=⇒ On connaıt la probabilite des valeurs de Y |X

=⇒ On a un modele probabiliste de ces valeurs

Or, c’est justement le modele qu’on souhaite apprendre !

Idee clef de K-means et EM : algos iteratifs

1 se donner un modele initial (pas trop mauvais)

2 ce modele =⇒ donnees completes

3 apprendre nouveau modele avec ces donnees

4 revenir en 2 avec nouveau modele si 6= ancien modele

MAPSI — cours 4 : Expectation-Maximization (EM) 17/52

Page 18: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Apprentissage avec donnees manquantes : principes

Problemes :

1 Y a-t-il convergence?

1 A convergence, est-ce que l’on a obtenu un bon modele?

But du reste du cours 4 : repondre a ces questions pour EM

MAPSI — cours 4 : Expectation-Maximization (EM) 18/52

Page 19: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

2 Rappels de maths

MAPSI — cours 4 : Expectation-Maximization (EM) 19/52

Page 20: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Rappel : fonctions convexes

x

yy = f (x)

x1 x2λx1 + (1− λ)x2

Definitionf convexe⇐⇒ ∀λ ∈ [0,1],∀x1, x2 :

f (λx1+(1−λ)x2) ≤ λf (x1)+(1−λ)f (x2)

fonction concavef concave⇐⇒ −f convexe

MAPSI — cours 4 : Expectation-Maximization (EM) 20/52

Page 21: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Generalisation : l’inegalite de JensenInegalite de Jensen

f convexe definie sur Dx1, . . . , xn ∈ Dλ1, . . . , λn ≥ 0,

∑ni=1 λi = 1

Alors :

f

(n∑

i=1

λixi

)≤

n∑i=1

λi f (xi)

Inegalite de Jensen

f convexeX : variable aleatoire a n dimensions x1, . . . , xn

λ1, . . . , λn ≥ 0,n∑

i=1

λi = 1 =⇒ probabilite Pλ

f (EPλ(X )) ≤ EPλ(f (X )) ou EPλ = esperance

MAPSI — cours 4 : Expectation-Maximization (EM) 21/52

Page 22: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Demonstration de l’inegalite de Jensen

f

(n∑

i=1

λixi

)≤

n∑i=1

λi f (xi)

par recurrence : si n = 1 : trivial, si n = 2 : convexite

f

(n+1∑i=1

λixi

)= f

(λn+1xn+1 +

n∑i=1

λixi

)

= f

(λn+1xn+1 + (1− λn+1)

n∑i=1

λi

1− λn+1xi

)

≤ λn+1f (xn+1) + (1− λn+1)f

(n∑

i=1

λi

1− λn+1xi

)

≤ λn+1f (xn+1) + (1− λn+1)n∑

i=1

λi

1− λn+1f (xi)

= λn+1f (xn+1) +n∑

i=1

λi f (xi) =n+1∑i=1

λi f (xi)

MAPSI — cours 4 : Expectation-Maximization (EM) 22/52

Page 23: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Consequences de l’inegalite de Jensen

Inegalite de Jensen pour le logarithme

Logarithme = fonction concave :

log

(n∑

i=1

λixi

)≥

n∑i=1

λi log(xi)

x

y

y = log(x)

E(log(X )) = log(E(X )) =⇒ X = E(X ) = constante

MAPSI — cours 4 : Expectation-Maximization (EM) 23/52

Page 24: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

3 L’algorithme EM

MAPSI — cours 4 : Expectation-Maximization (EM) 24/52

Page 25: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Typologies de donnees incompletes

xo : donnees observees, xh : donnees manquantes

x = xo ∪ xh

Film rA rB rC rD

I robot 4 ? 3 3

Forest Gump ? ? 2 4

Intouchables 2 2 3 ?

Le parrain 1 ? 2 ?

Pulp fiction 2 4 3 4

Mij = P(r ji ∈ xh) : position des donnees manquantes

MAPSI — cours 4 : Expectation-Maximization (EM) 25/52

Page 26: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Typologies de donnees incompletes

Typologies

Missing Completely at Random (MCAR) : P(M|x) = P(M)Aucune relation entre le fait qu’une donnee soit manquante ouobserveeMissing at Random (MAR) : P(M|x) = P(M|xo) donneesmanquantes en relation avec les donnees observees mais pasavec les autres donnees manquantesNot Missing At Random (NMAR) : P(M|x) donneesmanquantes en relation avec toutes les donnees

On n’etudiera que MCAR!

MAPSI — cours 4 : Expectation-Maximization (EM) 26/52

Page 27: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Log-vraisemblance et donnees incompletes

Echantillon x = {x1, . . . , xn} de taille n

donnees completes : log L(x,Θ) =n∑

i=1

log P(xi |Θ)

xo : donnees observees, xh : donnees manquantes

log L(xo,Θ) = log-vraisemblance des donnees observees

=n∑

i=1

log P(xoi |Θ) =

n∑i=1

log

∑xh

i ∈xh

P(xoi , x

hi |Θ)

Soit Qi(xh

i ) une loi de proba quelconque alors :

log L(xo,Θ) =n∑

i=1

log

∑xh

i ∈xh

Qi(xhi )

P(xoi , x

hi |Θ)

Qi(xhi )

MAPSI — cours 4 : Expectation-Maximization (EM) 27/52

Page 28: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Log-vraisemblance et donnees incompletes

log L(xo,Θ) =n∑

i=1

log

∑xh

i ∈xh

Qi(xhi )

P(xoi , x

hi |Θ)

Qi(xhi )

inegalite de Jensen =⇒ log

(n∑

i=1

λiyi

)≥

n∑i=1

λi log(yi)

log L(xo,Θ) ≥n∑

i=1

∑xh

i ∈xh

Qi(xhi ) log

(P(xo

i , xhi |Θ)

Qi(xhi )

)

Jensen =⇒ egalite ssiP(xo

i , xhi |Θ)

Qi(xhi )

= constante

choisir Qi(xhi ) ∝ P(xo

i , xhi |Θ) =⇒ Qi(xh

i ) = P(xhi |x

oi ,Θ)

MAPSI — cours 4 : Expectation-Maximization (EM) 28/52

Page 29: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Algorithme EM

Algorithme1 choisir une valeur initiale Θ = Θ0

2 Etape E (expectation) :

Qt+1i (xh

i )← P(xhi |x

oi ,Θ

t ) ∀i ∈ {1, . . . ,n}

log Lt+1(xo,Θ) =n∑

i=1

∑xh

i ∈xh

Qt+1i (xh

i ) log

(P(xo

i , xhi |Θ)

Qt+1i (xh

i )

)

3 Etape M (maximization) :

Θt+1 ← ArgmaxΘ log Lt+1(xo,Θ)

4 Tant qu’on n’a pas converge, revenir en 2

A convergence, Θt+1 = optimum local par max devraisemblance

MAPSI — cours 4 : Expectation-Maximization (EM) 29/52

Page 30: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Algorithme EM : un exemple

2 variables aleatoires A ∈ {a,b} et C ∈ {c,d}

P(A,C|Θ) =

[θac θadθbc θbd

]=⇒ Θ = {θac , θad , θbc , θbd}

but : estimer Θ par EM

A Ca ?b ?a db da c

A toujours observe :=⇒ θac + θad = 3

5 par max de vraisemblance

θbc + θbd = 25 par max de vraisemblance

initialisation possible :Θ0 = {θ0

ac = 0.3, θ0ad = 0.3, θ0

bc = 0.2, θ0bd = 0.2}

Etape E (expectation) : Q1i (xh

i )← P(xhi |xo

i ,Θ0) ∀i ∈ {1,2}

Q11(C) = P(C|A = a,Θ0) = P(A=a,C|Θ0)∑

C P(A=a,C|Θ0)= [ 0.3

0.6 ,0.30.6 ] = [0.5 , 0.5]

Q12(C) = P(C|A = b,Θ0) = P(A=b,C|Θ0)∑

C P(A=b,C|Θ0)= [ 0.2

0.4 ,0.20.4 ] = [0.5 , 0.5]

MAPSI — cours 4 : Expectation-Maximization (EM) 30/52

Page 31: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Algorithme EM : un exempleΘ0 = {θ0

ac = 0.3, θ0ad = 0.3, θ0

bc = 0.2, θ0bd = 0.2}

Q11(C) = [0.5 , 0.5] Q1

2(C) = [0.5 , 0.5] P(xhi , x

oi |Θ0) =

[0.3 0.30.2 0.2

]

log Lt+1(xo,Θ) =n∑

i=1

∑xh

i ∈xh

Qt+1i (xh

i ) log

(P(xo

i , xhi |Θ)

Qt+1i (xh

i )

)

A Ba ?b ?a db da c

=⇒

A B Qt+1i P/Qt+1

i log(P/Qt+1i )

a c 0.5 θac/0.5 log θac − log 0.5a d 0.5 θad/0.5 log θad − log 0.5b c 0.5 θbc/0.5 log θbc − log 0.5b d 0.5 θbd/0.5 log θbd − log 0.5a d 1 θad log θadb d 1 θbd log θbda c 1 θac log θac

=⇒ revient a observer l’echantillon avec poids Qt+1i

MAPSI — cours 4 : Expectation-Maximization (EM) 31/52

Page 32: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Algorithme EM

log Lt+1(xo,Θ) =n∑

i=1

∑xh

i ∈xh

Qt+1i (xh

i ) log

(P(xo

i , xhi |Θ)

Qt+1i (xh

i )

)

=n∑

i=1

∑xh

i ∈xh

Qt+1i (xh

i )[log(P(xo

i , xhi |Θ))− log(Qt+1

i (xhi ))]

=⇒ Θt+1 = ArgmaxΘ log Lt+1(xo,Θ)

= ArgmaxΘ

n∑i=1

∑xh

i ∈xh

Qt+1i (xh

i ) log(P(xoi , x

hi |Θ))

Principe de EM

Etape M =⇒ maximum de vraisemblance avec un echantillondont chaque enregistrement xi a un poids Qt+1

i

MAPSI — cours 4 : Expectation-Maximization (EM) 32/52

Page 33: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Algorithme EM : un exemple

Θ1 = ArgmaxΘ

n∑i=1

∑xh

i ∈xh

Qt+1i (xh

i ) log

(P(xo

i , xhi |Θ)

Qt+1i (xh

i )

)

A B Qt+1i log θ

a c 0.5 log θaca d 0.5 log θadb c 0.5 log θbcb d 0.5 log θbda d 1 log θadb d 1 log θbda c 1 log θac

Θ1 = ArgmaxΘ[0.5 + 1] log θac + [0.5 + 1] log θad + 0.5 log θbc + [0.5 + 1] log θbdSous contrainte : θac + θad + θbc + θbd = 1

Θ1 = {θ1ac = 3

10 , θ1ad = 3

10 , θ1bc = 1

10 , θ1bd = 3

10}

MAPSI — cours 4 : Expectation-Maximization (EM) 33/52

Page 34: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Algorithme EM : un exemple

Θ1 = {θ1ac = 3

10 , θ1ad = 3

10 , θ1bc = 1

10 , θ1bd = 3

10}

A Ca ?b ?a db da c

Etape E (expectation) : Q2i (xh

i )← P(xhi |xo

i ,Θ1) ∀i ∈ {1,2}

Q21(C) = P(C|A = a,Θ1) = P(A=a,C|Θ1)∑

C P(A=a,C|Θ1)= [ 0.3

0.6 ,0.30.6 ] = [0.5 , 0.5]

Q22(C) = P(C|A = b,Θ1) = P(A=b,C|Θ1)∑

C P(A=b,C|Θ1)= [ 0.1

0.4 ,0.30.4 ] = [0.25 , 0.75]

MAPSI — cours 4 : Expectation-Maximization (EM) 34/52

Page 35: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Algorithme EM : un exemple

Θ1 = {θ1ac = 3

10 , θ1ad = 3

10 , θ1bc = 1

10 , θ1bd = 3

10}

Q21(C) = [0.5 , 0.5] Q2

2(C) = [0.25 , 0.75] P(xhi , x

oi |Θ0) =

[0.3 0.30.1 0.3

]

log Lt+1(xo,Θ) =n∑

i=1

∑xh

i ∈xh

Qt+1i (xh

i ) log

(P(xo

i , xhi |Θ)

Qt+1i (xh

i )

)

A Ba ?b ?a db da c

=⇒

A B Qt+1i P/Qt+1

i log(P/Qt+1i )

a c 0.5 θac/0.5 log θac − log 0.5a d 0.5 θad/0.5 log θad − log 0.5b c 0.25 θbc/0.25 log θbc − log 0.25b d 0.75 θbd/0.75 log θbd − log 0.75a d 1 θad log θadb d 1 θbd log θbda c 1 θac log θac

Θ2 = ArgmaxΘ[0.5 + 1] log θac + [0.5 + 1] log θad + 0.25 log θbc + [0.75 + 1] log θbdSous contrainte : θac + θad + θbc + θbd = 1

MAPSI — cours 4 : Expectation-Maximization (EM) 35/52

Page 36: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Algorithme EM : un exemple

Θ2 = {θ2ac = 3

10 , θ2ad = 3

10 , θ2bc = 1

20 , θ2bd = 7

20}

Θ3 = {θ3ac = 3

10 , θ3ad = 3

10 , θ3bc = 1

40 , θ2bd = 15

40}

. . .

θac = θbc = 0,3

θbc + θbd = 0,4 et θbc divise par 2 a chaque etape.

=⇒ a convergence :Θ = {θac = 3

10 , θad = 310 , θbc = 0, θbd = 4

10}

MAPSI — cours 4 : Expectation-Maximization (EM) 36/52

Page 37: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Systeme de recommandation : le retour

Film rA rB rC rD

I robot 4 ? 3 3 ← Qt+11 (rB) =⇒ 4 enregistrements

Forest Gump ? ? 2 4 ← Qt+12 (rA, rB) =⇒ 16 enregistrements

Intouchables 2 2 3 ? ← Qt+13 (rD) =⇒ 4 enregistrements

Le parrain 1 ? 2 ? ← Qt+14 (rB , rD) =⇒ 16 enregistrements

Pulp fiction 2 4 3 4 ← Qt+15 () = 1 =⇒ 1 enregistrement

=⇒ 4 + 16 + 4 + 16 + 1 = 41 enregistrements pour calculer Θt+1

MAPSI — cours 4 : Expectation-Maximization (EM) 37/52

Page 38: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

4 Pourquoi EM fonctionne-t-il ?

MAPSI — cours 4 : Expectation-Maximization (EM) 38/52

Page 39: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Rappel : Algorithme EM

Algorithme1 choisir une valeur initiale Θ = Θ0

2 Etape E (expectation) :

Qt+1i (xh

i )← P(xhi |x

oi ,Θ

t ) ∀i ∈ {1, . . . ,n}

log Lt+1(xo,Θ) =n∑

i=1

∑xh

i ∈xh

Qt+1i (xh

i ) log

(P(xo

i , xhi |Θ)

Qt+1i (xh

i )

)

3 Etape M (maximization) :

Θt+1 ← ArgmaxΘ log Lt+1(xo,Θ)

4 Tant qu’on n’a pas converge, revenir en 2

MAPSI — cours 4 : Expectation-Maximization (EM) 39/52

Page 40: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Convergence de EM : monotonie

Etape E : log Lt+1(xo,Θ) =n∑

i=1

∑xh

i ∈xh

Qt+1i (xh

i ) log

P(xoi , x

hi |Θ)

Qt+1i (xh

i )

Etape M : Θt+1 ← ArgmaxΘ log Lt+1(xo,Θ)

=⇒ log Lt+1(xo,Θt+1) ≥ log Lt+1(xo,Θt )

Rappel : inegalite de Jensen

∀ loi de proba Qi (xhi ) :

log L(xo,Θt ) ≥n∑

i=1

∑xh

i ∈xh

Qi (xhi ) log

(P(xo

i , xhi |Θt )

Qi (xhi )

)

egalite⇐⇒ Qi (xhi ) = P(xh

i |xoi ,Θ

t ) = Qt+1i (xh

i )

=⇒{

log Lt+1(xo,Θt ) = log L(xo,Θt ) ≥ log Lt (xo,Θt )log L(xo,Θt+1) ≥ log Lt+1(xo,Θt+1)

=⇒ L(xo,Θt+1) ≥ Lt+1(xo,Θt+1) ≥ L(xo,Θt ) ≥ Lt (xo,Θt )

MAPSI — cours 4 : Expectation-Maximization (EM) 40/52

Page 41: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Convergence de EM

L(xo,Θt+1) ≥ Lt+1(xo,Θt+1) ≥ L(xo,Θt ) ≥ Lt (xo,Θt )

Propriete de EMEM converge vers un maximum local de la vraisemblance

si ArgmaxΘ Lt+1(xo,Θ) estime par descente de gradient,on peut perdre cette propriete !

MAPSI — cours 4 : Expectation-Maximization (EM) 41/52

Page 42: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

5 Mixtures de Gaussiennes et EM

MAPSI — cours 4 : Expectation-Maximization (EM) 42/52

Page 43: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Mixture de gaussiennes

p(·) = 0,3×N (0,22) + 0,4×N (4,32) + 0,3×N (−3,12)

x

y

N1

N2 N3

p

MAPSI — cours 4 : Expectation-Maximization (EM) 43/52

Page 44: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Application : apprentissage de prix fonciers

postulat : prix de biens similaires dans un quartier ∼ identiques

=⇒ prix dependent{

des caracteristiques du bien (e.g. nombre de pieces)du quartier

=⇒ modelisation par une mixture de gaussiennes (ici 2 gaussiennes)

Modelisation du probleme

Θ = {µ1, µ2, σ1, σ2, π1, π2}p(x |Θ) = π1 N (µ1, σ

21) + π2 N (µ2, σ

22)

Apprentissage non supervise

echantillon x = 〈x1, . . . , xn〉xi = prix =⇒ on ne connaıt pas la Gaussienne a laquelle le bien

appartient

echantillon suppose complet (pas de donnees manquantes)

MAPSI — cours 4 : Expectation-Maximization (EM) 44/52

Page 45: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Application : apprentissage de prix fonciers

echantillon complet =⇒ estimation par max de vraisemblance

L(x,Θ) =n∏

i=1

p(xi |Θ) =n∏

i=1

2∑k=1

πk1√

2πσkexp

{−1

2

(xi − µk

σk

)2}

log L(x,Θ) =n∑

i=1

log

[2∑

k=1

πk1√

2πσkexp

{−1

2

(xi − µk

σk

)2}]

trop complique a maximiser analytiquement !

Solution : EM

1 xi appartient a une classe yk(i) non observee ∼ N (µk(i), σk(i))

2 echantillon x = 〈(xi , yk(i))〉

3 echantillon maintenant avec donnees manquantes =⇒ EM

MAPSI — cours 4 : Expectation-Maximization (EM) 45/52

Page 46: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Application : apprentissage de prix fonciers

Nouvelle modelisation du probleme

p(Xi ,Yk(i)|Θ) = p(Xi |Yk(i),Θ)P(Yk(i)|Θ) =

[N (µ1, σ

21) π1

N (µ2, σ22) π2

]=⇒ pour xi connu :

P(Yk(i)|xi ,Θ) =p(xi ,Yk(i)|Θ)

p(xi |Θ)∝

1√2πσ1

exp{− 1

2

(xi−µ1

σ1

)2}× π1

1√2πσ2

exp{− 1

2

(xi−µ2

σ2

)2}× π2

Initialisation d’EM : choisir une valeur Θ0 = {µ0

1, µ02, σ

01 , σ

02 , π

01 , π

02}

Etape E : Q1i (yk )← P(yk |xi ,Θ

0) pour k = 1,2

=⇒ Q1i (·) tres facile a calculer

Etape M :

ArgmaxΘ

log Lt+1(xo,Θ) = ArgmaxΘ

n∑i=1

2∑k=1

Qt+1i (yk ) log

(p(xi , yk |Θ)

Qt+1i (yk )

)MAPSI — cours 4 : Expectation-Maximization (EM) 46/52

Page 47: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Application : apprentissage de prix fonciersEtape M :

ArgmaxΘ log Lt+1(xo,Θ)

= ArgmaxΘ

n∑i=1

2∑k=1

Qt+1i (yk ) log

(p(xi , yk |Θ)

Qt+1i (yk )

)

= ArgmaxΘ

n∑i=1

Qt+1i (y1) log

π11√

2πσ21

exp

{−1

2

(xi − µ1

σ1

)2}+

Qt+1i (y2) log

π21√

2πσ22

exp

{−1

2

(xi − µ2

σ2

)2}

= ArgmaxΘ

n∑i=1

Qt+1i (y1)

[log(π1)− 1

2log(σ2

1)− 12

(xi − µ1

σ1

)2]

+

Qt+1i (y2)

[log(π2)− 1

2log(σ2

2)− 12

(xi − µ2

σ2

)2]

Argmax facile a calculer !

MAPSI — cours 4 : Expectation-Maximization (EM) 47/52

Page 48: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

classification d’images

MAPSI — cours 4 : Expectation-Maximization (EM) 48/52

Page 49: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

classification d’images

Signatures spectrales en teintes de gris

neige ∼ N (µ1, σ21)

foret ∼ N (µ2, σ22)

desert ∼ N (µ3, σ23)

mer ∼ N (µ4, σ24)

Y = observation en teinte de gris = pixels d’une image

Z = classe paysage ∈ {1,2,3,4} ∼ distribution (π1, π2, π3, π4)

Parametres du probleme

Θ = {(µj , σj)}4j=1 ∪ {πj}4j=1

p(Y ,Z |Θ) = p(Y |Z ,Θ)P(Z |Θ) =4∑

j=1

πj N (µj , σ2j )

MAPSI — cours 4 : Expectation-Maximization (EM) 49/52

Page 50: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

classification d’images

Y : observations, Z : classes de paysage

p(Y ,Z |Θ) =4∑

j=1

πj N (µj , σ2j )

base de donnees incomplete ou Z non observe

=⇒ estimation de Θ par EM (similaire aux prix fonciers)

MAPSI — cours 4 : Expectation-Maximization (EM) 50/52

Page 51: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Le geyser Old Faithful

Geyser du parc national de Yellowstone

MAPSI — cours 4 : Expectation-Maximization (EM) 51/52

Page 52: MAPSI cours 4 : Expectation-Maximization (EM)mapsi.lip6.fr/uploads/Cours/2018_MAPSI_cours4.pdf2 Quelques rappels de maths 3 L’algorithme EM 4 Pourquoi fonctionne-t-il? 5 Mixtures

Le geyser Old Faithful

Donnees : (duree de l’eruption, temps jusqu’a la prochaine eruption)

=⇒ ressemble a une mixture de 2 gaussiennes

[http://en.wikipedia.org/wiki/Expectation-maximization algorithm]

MAPSI — cours 4 : Expectation-Maximization (EM) 52/52