Markov Chains and MCMC CompSci 590.04 Instructor: - - PowerPoint PPT Presentation

markov chains and mcmc
SMART_READER_LITE
LIVE PREVIEW

Markov Chains and MCMC CompSci 590.04 Instructor: - - PowerPoint PPT Presentation

Markov Chains and MCMC CompSci 590.04 Instructor: AshwinMachanavajjhala Lecture 4 : 590.04 Fall 15 1 Announcement First assignment has been posted


slide-1
SLIDE 1

Markov ¡Chains ¡and ¡MCMC ¡

CompSci ¡590.04 ¡ Instructor: ¡AshwinMachanavajjhala ¡

1 ¡ Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡

slide-2
SLIDE 2

Announcement ¡

  • First ¡assignment ¡has ¡been ¡posted ¡

– Please ¡work ¡on ¡it ¡in ¡groups ¡of ¡2 ¡or ¡3 ¡ – Involves ¡accessing ¡TwiHer ¡for ¡informaIon ¡ – Only ¡allowed ¡a ¡restricted ¡number ¡of ¡API ¡calls ¡to ¡TwiHer ¡a ¡day ¡ – So ¡do ¡not ¡delay ¡the ¡assignment ¡Ill ¡the ¡last ¡minute. ¡ ¡

  • Due ¡date: ¡Friday ¡Sep ¡11, ¡11:59 ¡pm ¡

¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 2 ¡

slide-3
SLIDE 3

Recap: ¡Monte ¡Carlo ¡Method ¡

  • If ¡U ¡is ¡a ¡universe ¡of ¡items, ¡and ¡G ¡is ¡a ¡subset ¡saIsfying ¡some ¡

property, ¡we ¡want ¡to ¡esImate ¡|G| ¡

– Either ¡intractable ¡or ¡inefficient ¡to ¡count ¡exactly ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 3 ¡

For ¡i ¡= ¡1 ¡to ¡N

  • Choose ¡u ¡ε ¡U, ¡uniformly ¡at ¡random
  • Check ¡whether ¡u ¡ε ¡G ¡? ¡
  • Let ¡Xi ¡= ¡1 ¡if ¡u ¡ε ¡G, ¡Xi ¡= ¡0 ¡otherwise

Return Variance: ¡

slide-4
SLIDE 4

Recap: ¡Monte ¡Carlo ¡Method ¡

When ¡is ¡this ¡method ¡an ¡FPRAS? ¡ ¡

  • |U| ¡is ¡known ¡and ¡easy ¡to ¡uniformly ¡sample ¡from ¡U. ¡
  • Easy ¡to ¡check ¡whether ¡sample ¡is ¡in ¡G ¡
  • |U|/|G| ¡is ¡small ¡… ¡(polynomial ¡in ¡the ¡size ¡of ¡the ¡input) ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 4 ¡

slide-5
SLIDE 5

Recap: ¡Importance ¡Sampling ¡

  • In ¡certain ¡case ¡|G| ¡<< ¡|U|, ¡hence ¡the ¡number ¡of ¡samples ¡is ¡not ¡
  • small. ¡ ¡
  • Suppose ¡q(x) ¡is ¡the ¡density ¡of ¡interest, ¡sample ¡from ¡a ¡different ¡

approximate ¡density ¡p(x) ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 5 ¡

¡

slide-6
SLIDE 6

Today’s ¡Class ¡

¡

  • Markov ¡Chains ¡
  • Markov ¡Chain ¡Monte ¡Carlo ¡sampling ¡

– ¡a.k.a. ¡Metropolis-­‑HasIngs ¡Method. ¡ ¡ – Standard ¡technique ¡for ¡probabilisIc ¡inference ¡in ¡machine ¡learning, ¡when ¡ the ¡probability ¡distribuIon ¡is ¡hard ¡to ¡compute ¡exactly ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 6 ¡

slide-7
SLIDE 7

Markov ¡Chains ¡

  • Consider ¡a ¡Ime ¡varying ¡random ¡process ¡which ¡takes ¡the ¡ ¡

value ¡Xt ¡at ¡Ime ¡t ¡

– Values ¡of ¡Xt ¡are ¡drawn ¡from ¡a ¡finite ¡(more ¡generally ¡countable) ¡set ¡

  • f ¡states ¡Ω. ¡ ¡
  • {X0 ¡… ¡Xt… ¡Xn} ¡is ¡a ¡Markov ¡Chain ¡if ¡the ¡value ¡of ¡ ¡

Xt ¡only ¡depends ¡on ¡Xt-­‑1 ¡

¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 7 ¡

slide-8
SLIDE 8

TransiIon ¡ProbabiliIes ¡

  • Pr[Xt+1 ¡= ¡sj ¡| ¡Xt ¡= ¡si], ¡denoted ¡by ¡P(i,j), ¡is ¡called ¡the ¡transiIon ¡

probability ¡

– Can ¡be ¡represented ¡as ¡a ¡|Ω| ¡x ¡|Ω| ¡matrix ¡P. ¡ – P(i,j) ¡ ¡is ¡the ¡probability ¡that ¡the ¡chain ¡moves ¡from ¡state ¡i ¡to ¡state ¡j ¡

  • Let ¡πi(t) ¡= ¡Pr[Xt ¡= ¡si] ¡denote ¡the ¡probability ¡of ¡reaching ¡state ¡i ¡at ¡

Ime ¡t ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 8 ¡

¡ ¡

slide-9
SLIDE 9

TransiIon ¡ProbabiliIes ¡

  • Pr[Xt+1 ¡= ¡sj ¡| ¡Xt ¡= ¡si], ¡denoted ¡by ¡P(i,j), ¡is ¡called ¡the ¡transiIon ¡

probability ¡

– Can ¡be ¡represented ¡as ¡a ¡|Ω| ¡x ¡|Ω| ¡matrix ¡P. ¡ – P(i,j) ¡ ¡is ¡the ¡probability ¡that ¡the ¡chain ¡moves ¡from ¡state ¡i ¡to ¡state ¡j ¡

  • If ¡ ¡π(t) ¡denotes ¡the ¡1x|Ω| ¡vector ¡of ¡probabiliIes ¡of ¡reaching ¡all ¡

the ¡states ¡at ¡Ime ¡t, ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 9 ¡

¡ ¡

slide-10
SLIDE 10

Example ¡

  • Suppose ¡Ω ¡= ¡{Rainy, ¡Sunny, ¡Cloudy} ¡
  • Tomorrow’s ¡weather ¡only ¡depends ¡on ¡today’s ¡weather. ¡

– Markov ¡process ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 10 ¡

Pr[Xt+1 ¡= ¡Sunny ¡| ¡Xt ¡= ¡Rainy] ¡= ¡0.25 ¡ Pr[Xt+1 ¡= ¡Sunny ¡| ¡Xt ¡= ¡Sunny] ¡= ¡0 ¡

No ¡2 ¡consecu=ve ¡days ¡of ¡sun ¡(SeaBle?) ¡

slide-11
SLIDE 11

Example ¡

  • Suppose ¡Ω ¡= ¡{Rainy, ¡Sunny, ¡Cloudy} ¡
  • Tomorrow’s ¡weather ¡only ¡depends ¡on ¡today’s ¡weather. ¡

– Markov ¡process ¡

  • Suppose ¡today ¡is ¡Sunny. ¡ ¡
  • What ¡is ¡the ¡weather ¡2 ¡days ¡from ¡now? ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 11 ¡

slide-12
SLIDE 12

Example ¡

  • Suppose ¡Ω ¡= ¡{Rainy, ¡Sunny, ¡Cloudy} ¡
  • Tomorrow’s ¡weather ¡only ¡depends ¡on ¡today’s ¡weather. ¡

– Markov ¡process ¡

  • Suppose ¡today ¡is ¡Sunny. ¡ ¡
  • What ¡is ¡the ¡weather ¡7 ¡days ¡from ¡now? ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 12 ¡

slide-13
SLIDE 13

Example ¡

  • Suppose ¡Ω ¡= ¡{Rainy, ¡Sunny, ¡Cloudy} ¡
  • Tomorrow’s ¡weather ¡only ¡depends ¡on ¡today’s ¡weather. ¡

– Markov ¡process ¡

  • Suppose ¡today ¡is ¡Rainy. ¡ ¡
  • What ¡is ¡the ¡weather ¡2 ¡days ¡from ¡now? ¡ ¡
  • Weather ¡7 ¡days ¡from ¡now? ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 13 ¡

slide-14
SLIDE 14

Example ¡

  • Arer ¡sufficient ¡amount ¡of ¡Ime ¡the ¡expected ¡weather ¡distribuIon ¡is ¡

independent ¡of ¡the ¡starIng ¡value. ¡

  • Moreover, ¡ ¡
  • This ¡is ¡called ¡the ¡sta=onary ¡distribu=on. ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 14 ¡

slide-15
SLIDE 15

StaIonary ¡DistribuIon ¡

  • ¡π ¡is ¡called ¡a ¡sta>onary ¡distribu>on ¡of ¡the ¡Markov ¡Chain ¡if ¡
  • That ¡is, ¡once ¡the ¡staIonary ¡distribuIon ¡is ¡reached, ¡every ¡

subsequent ¡Xi ¡is ¡a ¡sample ¡from ¡the ¡distribuIon ¡π ¡ How ¡to ¡use ¡Markov ¡Chains: ¡ ¡

  • Suppose ¡ ¡you ¡want ¡to ¡sample ¡from ¡a ¡set ¡|Ω|, ¡according ¡to ¡distribuIon ¡π ¡
  • Construct ¡a ¡Markov ¡Chain ¡(P) ¡such ¡that ¡π ¡is ¡the ¡staIonary ¡distribuIon ¡
  • Once ¡sta>onary ¡distribu>on ¡is ¡achieved, ¡we ¡get ¡samples ¡from ¡the ¡correct ¡
  • distribuIon. ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 15 ¡

slide-16
SLIDE 16

CondiIons ¡for ¡a ¡StaIonary ¡DistribuIon ¡

A ¡Markov ¡chain ¡is ¡ergodic ¡if ¡it ¡is: ¡ ¡ ¡

  • Irreducible: ¡ ¡A ¡state ¡j ¡can ¡be ¡reached ¡from ¡any ¡state ¡i ¡in ¡some ¡

finite ¡number ¡of ¡steps. ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 16 ¡

slide-17
SLIDE 17

CondiIons ¡for ¡a ¡StaIonary ¡DistribuIon ¡

A ¡Markov ¡chain ¡is ¡ergodic ¡if ¡it ¡is: ¡ ¡ ¡

  • Irreducible: ¡ ¡A ¡state ¡j ¡can ¡be ¡reached ¡from ¡any ¡state ¡i ¡in ¡some ¡

finite ¡number ¡of ¡steps. ¡ ¡

  • Aperiodic: ¡A ¡chain ¡is ¡not ¡forced ¡into ¡cycles ¡of ¡fixed ¡length ¡

between ¡certain ¡states ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 17 ¡

slide-18
SLIDE 18

CondiIons ¡for ¡a ¡StaIonary ¡DistribuIon ¡

A ¡Markov ¡chain ¡is ¡ergodic ¡if ¡it ¡is: ¡

  • Irreducible: ¡ ¡A ¡state ¡j ¡can ¡be ¡reached ¡from ¡any ¡state ¡i ¡in ¡some ¡

finite ¡number ¡of ¡steps. ¡ ¡

  • Aperiodic: ¡A ¡chain ¡is ¡not ¡forced ¡into ¡cycles ¡of ¡fixed ¡length ¡

between ¡certain ¡states ¡ Theorem: ¡For ¡every ¡ergodic ¡Markov ¡chain, ¡there ¡is ¡a ¡unique ¡vector ¡ π ¡such ¡that ¡for ¡all ¡iniIal ¡probability ¡vectors ¡π(0), ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 18 ¡

slide-19
SLIDE 19

Sufficient ¡CondiIon: ¡Detailed ¡Balance ¡

  • In ¡a ¡staIonary ¡walk, ¡for ¡any ¡pair ¡of ¡states ¡j, ¡k, ¡the ¡Markov ¡Chain ¡is ¡

as ¡likely ¡to ¡move ¡from ¡j ¡to ¡k ¡as ¡from ¡k ¡to ¡j. ¡

  • Also ¡called ¡reversibility ¡condi=on. ¡ ¡

¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 19 ¡

slide-20
SLIDE 20

Example: ¡Random ¡Walks ¡

  • Consider ¡a ¡graph ¡G ¡= ¡(V,E), ¡with ¡weights ¡on ¡edges ¡(w(e)) ¡

¡ Random ¡Walk: ¡ ¡

  • Start ¡at ¡some ¡node ¡u ¡in ¡the ¡graph ¡G(V,E) ¡
  • Move ¡from ¡node ¡u ¡to ¡node ¡v ¡with ¡probability ¡proporIonal ¡to ¡

w(u,v). ¡ ¡ Random ¡walk ¡is ¡a ¡Markov ¡chain ¡ ¡

  • State ¡space ¡ ¡= ¡V ¡
  • P(u,v) ¡= ¡ ¡w(u,v) ¡/ ¡Σ ¡w(u,v’) ¡ ¡ ¡ ¡ ¡if ¡(u,v) ¡ε ¡E ¡

¡ ¡ ¡ ¡= ¡ ¡0 ¡ ¡ ¡ ¡if ¡(u,v) ¡is ¡not ¡in ¡E ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 20 ¡

slide-21
SLIDE 21

Example: ¡Random ¡Walk ¡

Random ¡walk ¡is ¡ergodic ¡if: ¡ ¡

  • Irreducible: ¡ ¡A ¡state ¡j ¡can ¡be ¡reached ¡from ¡any ¡state ¡i ¡in ¡some ¡

finite ¡number ¡of ¡steps. ¡ ¡ If ¡G ¡is ¡connected. ¡ ¡ ¡

  • Aperiodic: ¡A ¡chain ¡is ¡not ¡forced ¡into ¡cycles ¡of ¡fixed ¡length ¡

between ¡certain ¡states ¡ ¡ If ¡G ¡is ¡not ¡biparIte ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 21 ¡

slide-22
SLIDE 22

Example: ¡Random ¡Walk ¡

Uniform ¡random ¡walk: ¡

  • Suppose ¡all ¡weights ¡on ¡the ¡graph ¡are ¡1 ¡
  • P(u,v) ¡= ¡1/deg(u) ¡ ¡ ¡ ¡ ¡ ¡ ¡(or ¡0) ¡

Theorem: ¡If ¡G ¡is ¡connected ¡and ¡not ¡biparIte, ¡then ¡the ¡staIonary ¡ distribuIon ¡of ¡the ¡random ¡walk ¡is ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 22 ¡

slide-23
SLIDE 23

Example: ¡Random ¡Walk ¡

Symmetric ¡random ¡walk: ¡

  • Suppose ¡P(u,v) ¡= ¡P(v,u) ¡

Theorem: ¡If ¡G ¡is ¡connected ¡and ¡not ¡biparIte, ¡then ¡the ¡staIonary ¡ distribuIon ¡of ¡the ¡random ¡walk ¡is ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 23 ¡

slide-24
SLIDE 24

StaIonary ¡DistribuIon ¡

  • ¡π ¡is ¡called ¡a ¡sta>onary ¡distribu>on ¡of ¡the ¡Markov ¡Chain ¡if ¡
  • That ¡is, ¡once ¡the ¡staIonary ¡distribuIon ¡is ¡reached, ¡every ¡

subsequent ¡Xi ¡is ¡a ¡sample ¡from ¡the ¡distribuIon ¡π ¡ How ¡to ¡use ¡Markov ¡Chains: ¡ ¡

  • Suppose ¡ ¡you ¡want ¡to ¡sample ¡from ¡a ¡set ¡|Ω|, ¡according ¡to ¡distribuIon ¡π ¡
  • Construct ¡a ¡Markov ¡Chain ¡(P) ¡such ¡that ¡π ¡is ¡the ¡staIonary ¡distribuIon ¡
  • Once ¡sta>onary ¡distribu>on ¡is ¡achieved, ¡we ¡get ¡samples ¡from ¡the ¡correct ¡
  • distribuIon. ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 24 ¡

slide-25
SLIDE 25

Metropolis-­‑HasIngs ¡Algorithm ¡(MCMC) ¡

  • Suppose ¡we ¡want ¡to ¡sample ¡from ¡a ¡complex ¡distribuIon ¡ ¡

f(x) ¡= ¡p(x) ¡/ ¡K, ¡where ¡K ¡is ¡unknown ¡or ¡hard ¡to ¡compute ¡

  • Example: ¡Bayesian ¡Inference ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 25 ¡

slide-26
SLIDE 26

Metropolis-­‑HasIngs ¡Algorithm ¡

  • Start ¡with ¡any ¡iniIal ¡value ¡x0, ¡such ¡that ¡p(x0) ¡> ¡0 ¡
  • Using ¡current ¡value ¡xt-­‑1, ¡sample ¡a ¡new ¡point ¡according ¡some ¡

proposal ¡distribu=on ¡q(xt ¡| ¡xt-­‑1) ¡

  • Compute ¡
  • With ¡probability ¡α ¡accept ¡the ¡move ¡to ¡xt, ¡ ¡
  • therwise ¡reject ¡xt ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 26 ¡

slide-27
SLIDE 27

Why ¡does ¡Metropolis-­‑HasIngs ¡work? ¡ ¡

  • Metropolis-­‑HasIngs ¡describes ¡a ¡Markov ¡chain ¡with ¡transiIon ¡

probabiliIes: ¡ ¡

  • We ¡want ¡to ¡show ¡that ¡f(x) ¡= ¡p(x)/K ¡is ¡the ¡staIonary ¡distribuIon ¡
  • Recall ¡sufficient ¡condiIon ¡for ¡staIonary ¡distribuIon: ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 27 ¡

slide-28
SLIDE 28

Why ¡does ¡Metropolis-­‑HasIngs ¡work? ¡ ¡

  • Metropolis-­‑HasIngs ¡describes ¡a ¡Markov ¡chain ¡with ¡transiIon ¡

probabiliIes: ¡ ¡

  • Sufficient ¡to ¡show: ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 28 ¡

slide-29
SLIDE 29

Proof: ¡Case ¡1 ¡

  • Suppose ¡
  • Then, ¡

¡P(x,y) ¡= ¡q(y ¡| ¡x) ¡

  • Therefore ¡ ¡ ¡

P(x,y)p(x) ¡= ¡ ¡q(y ¡| ¡x) ¡p(x) ¡= ¡p(y) ¡q(x ¡| ¡y) ¡= ¡P(y,x) ¡p(y) ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 29 ¡

slide-30
SLIDE 30

Proof: ¡Case ¡2 ¡

¡ ¡ ¡ ¡ ¡

  • Proof ¡of ¡Case ¡3 ¡is ¡idenIcal. ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 30 ¡

slide-31
SLIDE 31

When ¡is ¡staIonary ¡distribuIon ¡reached? ¡

  • Next ¡class ¡… ¡ ¡

Lecture ¡4 ¡: ¡590.04 ¡Fall ¡15 ¡ 31 ¡