+ All Categories
Home > Documents > Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov...

Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov...

Date post: 10-Oct-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
43
CS 343H: Honors Artificial Intelligence Prof. Peter Stone — The University of Texas at Austin [These slides based on those of Dan Klein and Pieter Abbeel for CS188 Intro to AI at UC Berkeley. All CS188 materials are available at http://ai.berkeley.edu.] Hidden Markov Models
Transcript
Page 1: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

CS343H:HonorsArtificialIntelligence

Prof.PeterStone—TheUniversityofTexasatAustin[TheseslidesbasedonthoseofDanKleinandPieterAbbeelforCS188IntrotoAIatUCBerkeley.AllCS188materialsareavailableathttp://ai.berkeley.edu.]

HiddenMarkovModels

Page 2: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

ReasoningoverTimeorSpace

▪ Often,wewanttoreasonaboutasequenceofobservations

▪ Speechrecognition▪ Robotlocalization▪ Userattention▪ Medicalmonitoring

▪ Needtointroducetime(orspace)intoourmodels

Page 3: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

MarkovModels

▪ ValueofXatagiventimeiscalledthestate

▪ Parameters:calledtransitionprobabilitiesordynamics,specifyhowthestateevolvesovertime(also,initialstateprobabilities)

▪ Stationarityassumption:transitionprobabilitiesthesameatalltimes▪ SameasMDPtransitionmodel,butnochoiceofaction

X2X1 X3 X4

Page 4: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

JointDistributionofaMarkovModel

▪ Jointdistribution:

▪ Moregenerally:

X2X1 X3 X4

Page 5: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

ImpliedConditionalIndependencies

▪ Weassumed:and

▪ Dowealsohave ?▪ Yes!D-Separation▪ Or,Proof:

X2X1 X3 X4

Page 6: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

MarkovModelsRecap

▪ Explicitassumptionforallt:▪ Consequence,jointdistributioncanbewrittenas:

▪ Impliedconditionalindependencies:▪ Pastvariablesindependentoffuturevariablesgiventhepresenti.e.,iforthen:

▪ Additionalexplicitassumption:isthesameforallt

Page 7: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

ConditionalIndependence

▪ Basicconditionalindependence:▪ Pastandfutureindependentgiventhepresent▪ Eachtimesteponlydependsontheprevious▪ Thisisthe(firstorder)Markovproperty(rememberMDPs?)

▪ Notethatthechainisjusta(growable)BN▪ WecanalwaysusegenericBNreasoningonitifwetruncatethechainatafixedlength

Page 8: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

ExampleMarkovChain:Weather

▪ States:X={rain,sun}

rain sun

0.9

0.7

0.3

0.1

TwonewwaysofrepresentingthesameCPT

sun

rain

sun

rain

0.1

0.9

0.7

0.3

Xt-1 Xt P(Xt|Xt-1)

sun sun 0.9

sun rain 0.1

rain sun 0.3

rain rain 0.7

▪ Initialdistribution:1.0sun

▪ CPTP(Xt|Xt-1):

Page 9: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

ExampleMarkovChain:Weather

▪ Initialdistribution:1.0sun

▪ Whatistheprobabilitydistributionafteronestep?

rain sun

0.9

0.7

0.3

0.1

Page 10: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Mini-ForwardAlgorithm

▪ Question:What’sP(X)onsomedayt?

Forward simulation

X2X1 X3 X4

Recursion

Page 11: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

ExampleRunofMini-ForwardAlgorithm

▪ Frominitialobservationofsun

▪ Frominitialobservationofrain

▪ FromyetanotherinitialdistributionP(X1):

P(X1) P(X2) P(X3) P(X∞)P(X4)

P(X1) P(X2) P(X3) P(X∞)P(X4)

P(X1) P(X∞)…

Page 12: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

▪ Stationarydistribution:▪ Thedistributionweendupwithiscalledthestationarydistribution ofthechain

▪ Itsatisfies

StationaryDistributions

▪ Formostchains:▪ Influenceoftheinitialdistributiongetslessandlessovertime.

▪ Thedistributionweendupinisindependentoftheinitialdistribution

Page 13: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:StationaryDistributions

▪ Question:What’sP(X)attimet=infinity?

X2X1 X3 X4

Xt-1 Xt P(Xt|Xt-1)

sun sun 0.9

sun rain 0.1

rain sun 0.3

rain rain 0.7

Also:

Page 14: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

ApplicationofStationaryDistribution:WebLinkAnalysis

▪ PageRankoverawebgraph▪ Eachwebpageisastate▪ Initialdistribution:uniformoverpages▪ Transitions:

▪ Withprob.c,uniformjumptoarandompage(dottedlines,notallshown)▪ Withprob.1-c,followarandomoutlink(solidlines)

▪ Stationarydistribution▪ Willspendmoretimeonhighlyreachablepages▪ E.g.manywaystogettotheAcrobatReaderdownloadpage▪ Somewhatrobusttolinkspam(Why?)▪ Google1.0returnedthesetofpagescontainingallyourkeywordsin

decreasingrank,nowallsearchenginesuselinkanalysisalongwithmanyotherfactors(rankactuallygettinglessimportantovertime)

Page 15: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

ApplicationofStationaryDistributions:GibbsSampling*

▪ Eachjointinstantiationoverallhiddenandqueryvariablesisastate:{X1,…,Xn}=HUQ

▪ Transitions:▪ Withprobability1/nresamplevariableXjaccordingto

P(Xj|x1,x2,…,xj-1,xj+1,…,xn,e1,…,em)

▪ Stationarydistribution:▪ ConditionaldistributionP(X1,X2,…,Xn|e1,…,em)▪ MeansthatwhenrunningGibbssamplinglongenoughwe

getasamplefromthedesireddistribution▪ Requiressomeprooftoshowthisistrue!

Page 16: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Pacman–Sonar(P4)

Page 17: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Pacman–Sonar(nobeliefs)

Page 18: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

HiddenMarkovModels

Page 19: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

HiddenMarkovModels

▪ Markovchainsnotsousefulformostagents▪ Needobservationstoupdateyourbeliefs

▪ HiddenMarkovmodels(HMMs)▪ UnderlyingMarkovchainoverstatesX▪ Youobserveoutputs(effects)ateachtimestep

X5X2

E1

X1 X3 X4

E2 E3 E4 E5

Page 20: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:WeatherHMM

Rt Rt+1 P(Rt+1|Rt)

+r +r 0.7

+r -r 0.3

-r +r 0.3

-r -r 0.7

Umbrellat-1

Rt Ut P(Ut|Rt)

+r +u 0.9

+r -u 0.1

-r +u 0.2

-r -u 0.8

Umbrellat Umbrellat+1

Raint-1 Raint Raint+1

▪ AnHMMisdefinedby:▪ Initialdistribution:▪ Transitions:▪ Emissions:

Page 21: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:GhostbustersHMM

▪ P(X1)=uniform

▪ P(X|X’)=usuallymoveclockwise,butsometimesmoveinarandomdirectionorstayinplace

▪ P(Rij|X)=samesensormodelasbefore:redmeansclose,greenmeansfaraway.

1/9 1/9

1/9 1/9

1/9

1/9

1/9 1/9 1/9

P(X1)

P(X|X’=<1,2>)

1/6 1/6

0 1/6

1/2

0

0 0 0

X5

X2

Ri,j

X1 X3 X4

Ri,j Ri,j Ri,j

Page 22: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Ghostbusters–CircularDynamics(HMM)

Page 23: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

JointDistributionofanHMM

▪ Jointdistribution:

▪ Moregenerally:

X5X2

E1

X1 X3

E2 E3 E5

Page 24: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

ImpliedConditionalIndependencies

▪ Manyimpliedconditionalindependencies,e.g.,

▪ Toprovethem▪ Approach1:followsimilar(algebraic)approachtowhatwedidforMarkovmodels▪ Approach2:D-Separation

X2

E1

X1 X3

E2 E3

Page 25: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

RealHMMExamples

▪ SpeechrecognitionHMMs:▪ Observationsareacousticsignals(continuousvalued)▪ Statesarespecificpositionsinspecificwords(so,tensofthousands)

▪ MachinetranslationHMMs:▪ Observationsarewords(tensofthousands)▪ Statesaretranslationoptions

▪ Robottracking:▪ Observationsarerangereadings(continuous)▪ Statesarepositionsonamap(continuous)

Page 26: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Filtering/Monitoring

▪ Filtering,ormonitoring,isthetaskoftrackingthedistributionBt(X)=Pt(Xt|e1,…,et)(thebeliefstate)overtime

▪ WestartwithB1(X)inaninitialsetting,usuallyuniform

▪ Astimepasses,orwegetobservations,weupdateB(X)

▪ TheKalmanfilterwasinventedinthe60’sandfirstimplementedasamethodoftrajectoryestimationfortheApolloprogram

Page 27: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:RobotLocalization

t=0Sensormodel:canreadinwhichdirectionsthereisawall,nevermorethan1mistake

Motionmodel:maynotexecuteactionwithsmallprob.

10Prob

ExamplefromMichaelPfeiffer

Page 28: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:RobotLocalization

t=1Lightergrey:waspossibletogetthereading,butlesslikelyb/crequired

1mistake

10Prob

Page 29: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:RobotLocalization

t=2

10Prob

Page 30: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:RobotLocalization

t=3

10Prob

Page 31: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:RobotLocalization

t=4

10Prob

Page 32: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:RobotLocalization

t=5

10Prob

Page 33: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Inference:BaseCases

E1

X1

X2X1

Page 34: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

PassageofTime

▪ AssumewehavecurrentbeliefP(X|evidencetodate)

▪ Then,afteronetimesteppasses:

▪ Basicidea:beliefsget“pushed”throughthetransitions▪ Withthe“B”notation,wehavetobecarefulaboutwhattimesteptthebeliefisabout,andwhatevidenceit

includes

X2X1

▪ Orcompactly:

Page 35: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:PassageofTime

▪ Astimepasses,uncertainty“accumulates”

T=1 T=2 T=5

(Transitionmodel:ghostsusuallygoclockwise)

Page 36: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Observation▪ AssumewehavecurrentbeliefP(X|previousevidence):

▪ Then,afterevidencecomesin:

▪ Or,compactly:

E1

X1

▪ Basicidea:beliefs“reweighted”bylikelihoodofevidence

▪ Unlikepassageoftime,wehavetorenormalize

Page 37: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:Observation

▪ Aswegetobservations,beliefsgetreweighted,uncertainty“decreases”

Beforeobservation Afterobservation

Page 38: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

PuttingitAllTogether:TheForwardAlgorithm▪ Wearegivenevidenceateachtimeandwanttoknow

▪ WecanderivethefollowingupdatesWecannormalizeaswegoifwewanttohaveP(x|e)ateachtimestep,orjustonceattheend…

Page 39: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

OnlineBeliefUpdates

▪ Everytimestep,westartwithcurrentP(X|evidence)▪ Weupdatefortime:

▪ Weupdateforevidence:

▪ Theforwardalgorithmdoesbothatonce(anddoesn’tnormalize)

X2X1

X2

E2

Page 40: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Example:WeatherHMM

Rt Rt+1 P(Rt+1|Rt)

+r +r 0.7

+r -r 0.3

-r +r 0.3

-r -r 0.7

Rt Ut P(Ut|Rt)

+r +u 0.9

+r -u 0.1

-r +u 0.2

-r -u 0.8

Umbrella1 Umbrella2

Rain0 Rain1 Rain2

B(+r)=0.5B(-r)=0.5

B’(+r)=0.5B’(-r)=0.5

B(+r)=0.818B(-r)=0.182

B’(+r)=0.627B’(-r)=0.373

B(+r)=0.883B(-r)=0.117

Page 41: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

Pacman–Sonar(P4)

Page 42: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

VideoofDemoPacman–Sonar(withbeliefs)

Page 43: Hidden Markov Models - University of Texas at Austinpstone/Courses/343Hfall... · Hidden Markov Models Markov chains not so useful for most agents Need observations to update your

NextTime:ParticleFilteringandApplicationsofHMMs


Recommended