Markov Models and Hidden Markov Models Robert Platt Northeastern - - PowerPoint PPT Presentation

markov models and hidden markov models
SMART_READER_LITE
LIVE PREVIEW

Markov Models and Hidden Markov Models Robert Platt Northeastern - - PowerPoint PPT Presentation

Markov Models and Hidden Markov Models Robert Platt Northeastern University Some images and slides are used from: 1. CS188 UC Berkeley 2. RN, AIMA Markov Models We have already seen that an MDP provides a useful framework for modeling


slide-1
SLIDE 1

Markov Models and Hidden Markov Models

Robert Platt Northeastern University Some images and slides are used from:

  • 1. CS188 UC Berkeley
  • 2. RN, AIMA
slide-2
SLIDE 2

Markov Models

We have already seen that an MDP provides a useful framework for modeling stochastic control problems. Markov Models: model any kind of temporally dynamic system.

slide-3
SLIDE 3
  • Conditional probability
  • Product rule
  • Chain rule
  • X, Y independent if and only if:
  • X and Y are conditionally independent given Z if and only if:

Probability recap

slide-4
SLIDE 4

Probability again: Independence

Two random variables, x and y, are independent when: The outcomes of two different coin flips are usually independent of each other

slide-5
SLIDE 5

Probability again: Independence

If: Then: Why?

slide-6
SLIDE 6

Probability again: Independence

Two random variables, x and y, are independent when: The outcomes of two different coin flips are usually independent of each other

slide-7
SLIDE 7

Example: Independence

winter snow 0.1 !snow 0.3 !winter 0.1 0.5

slide-8
SLIDE 8

Example: Independence

winter snow 0.1 !snow 0.3 !winter 0.1 0.5

Are snow and winter independent variables?

slide-9
SLIDE 9

Example: Independence

winter snow 0.1 !snow 0.3 !winter 0.1 0.5

Are snow and winter independent variables? P(snow) = 0.2 P(winter) = 0.4

slide-10
SLIDE 10

Example: Independence

winter snow 0.1 !snow 0.3 !winter 0.1 0.5

Are snow and winter independent variables? P(snow) = 0.2 P(winter) = 0.4 What would the distribution look like if snow, winter were independent?

slide-11
SLIDE 11

Conditional independence

Independence: Conditional independence: Equivalent statements of conditional independence:

slide-12
SLIDE 12

Conditional independence: example

cavity toothache catch

P(toothache, catch | cavity) = P(toothache | cavity) P(catch | cavity) Toothache and catch are conditionally independent given cavity – this is the “common cause” scenario covered in Bayes Nets...

slide-13
SLIDE 13

Examples of conditional independence

What are the conditional independence relationships in the following? – traffic, raining, late for work – snow, cloudy, crash – fire, smoke, alarm

slide-14
SLIDE 14

Markov Processes

transitions State at time=1 State at time=2

Markov model can be used to model any sequential time process – the weather – traffic – stock market – news cycle ...

slide-15
SLIDE 15

Markov Processes

transitions State at time=1 State at time=2 Since this is a Markov process, we assume transitions are Markov: Markov assumption: Process model:

slide-16
SLIDE 16

Markov Processes

How do we calculate:

slide-17
SLIDE 17

Markov Processes

How do we calculate:

slide-18
SLIDE 18

Markov Processes

How do we calculate:

slide-19
SLIDE 19

Markov Processes

How do we calculate:

Can we simplify this expression?

slide-20
SLIDE 20

Markov Processes

How do we calculate:

slide-21
SLIDE 21

Markov Processes

How do we calculate:

slide-22
SLIDE 22

Markov Processes

How do we calculate:

In general:

slide-23
SLIDE 23

Markov Processes

How do we calculate:

In general:

Process model

slide-24
SLIDE 24

Markov Processes: example

X_{t-1} X_t sun sun sun cloudy

Two states: cloudy, sunny

X_t 0.8 0.2 cloudy sun cloudy cloudy 0.3 0.7

sun cloudy 0.7 0.8 0.2 0.3

slide-25
SLIDE 25

Simulating dynamics forward

Joint distribution: But, suppose we want to predict the state at time T, given a prior distribution at time 1?

...

slide-26
SLIDE 26

Simulating dynamics forward

Suppose is it sunny on mon... Prob sunny tues Prob sunny weds Prob sunny thurs Prob sunny fri

slide-27
SLIDE 27

Simulating dynamics forward

Suppose is it cloudy on mon... Prob sunny tues Prob sunny weds Prob sunny thurs Prob sunny fri

slide-28
SLIDE 28

Simulating dynamics forward

Suppose is it cloudy on mon... Prob sunny tues Prob sunny weds Prob sunny thurs Prob sunny fri

Converge to same distribution regardless of starting point – called the “stationary distribution”

slide-29
SLIDE 29

An aside: the stationary distribution

How might you calculate the stationary distribution? Let: Then: Stationary distribution is the value for p such that:

slide-30
SLIDE 30

An aside: the stationary distribution

How might you calculate the stationary distribution? Let: Then: Stationary distribution is the value for p such that:

How calculate p that satisfies this eqn?

slide-31
SLIDE 31

Hidden Markov Models (HMMs)

Hidden Markov Models: – extension of the Markov model – state is assumed to be “hidden”

slide-32
SLIDE 32

Hidden Markov Models (HMMs)

State, , is assumed to be unobserved However, you get to make one observation, , on each timestep. Called an “emission” Examples: – speech to text; tracking in computer vision' robot localization

slide-33
SLIDE 33

Hidden Markov Models (HMMs)

Sensor Markov Assumption: the current observation depends only on current state:

slide-34
SLIDE 34

HMM example

sun cloudy 0.7 0.8 0.2 0.3 glasses No glasses 0.7 0.3 0.4 0.6 You live underground... Every day, you're boss comes in either wearing sunglasses or not Can you infer whether it's sunny out based on whether you see the glasses

  • ver a sequence of days?

– e.g. what's the prob it's sunny out today if you've seen your boss wear glasses three days in a row? (state is unobserved) (only observations are observed)

slide-35
SLIDE 35

HMM Filtering Given a prior distribution, , and a series

  • f observations, , calculate the

posterior distribution: Two steps:

Process update Observation update The Kalman filter is perhaps the most famous instance of this idea

slide-36
SLIDE 36

HMM Filtering Given a prior distribution, , and a series

  • f observations, , calculate the

posterior distribution: Two steps:

Process update Observation update

slide-37
SLIDE 37

HMM Filtering Given a prior distribution, , and a series

  • f observations, , calculate the

posterior distribution: Two steps:

Process update Observation update

“Beliefs”

slide-38
SLIDE 38

Process update

This is just forward simulation of the Markov Model

slide-39
SLIDE 39

Process update: example

T = 1 T = 2 T = 5

Completely certain about ghost position at T=1 A little less certain on the next time step... By now, we've almost completely lost track

  • f the ghost...

If we only do the process update, then we typically lose information over time – when might this not be true?

slide-40
SLIDE 40

Observation update

Where is a normalization factor

slide-41
SLIDE 41

Observation update

Before observation After observation Observations enable the system to gain information – a single observation may not determine system state exactly – but, the more observations, the better

slide-42
SLIDE 42

Robot localization example

1 Prob

slide-43
SLIDE 43

Robot localization example

1 Prob

slide-44
SLIDE 44

Robot localization example

1 Prob

slide-45
SLIDE 45

Robot localization example

1 Prob

slide-46
SLIDE 46

Robot localization example

1 Prob

slide-47
SLIDE 47

Robot localization example

1 Prob

slide-48
SLIDE 48

Weather HMM example

sun cloudy 0.7 0.8 0.2 0.3 glasses No glasses 0.7 0.3 0.4 0.6

slide-49
SLIDE 49

Weather HMM example

X_{t-1} X_t sun sun sun cloudy X_t 0.8 0.2 cloudy sun cloudy cloudy 0.3 0.7 X_t sun cloudy P(g_t|X_t) 0.7 0.4

glasses glasses No glasses

w_t sun cloudy P(w_t) 0.5 0.5

slide-50
SLIDE 50

Weather HMM example

X_{t-1} X_t sun sun sun cloudy X_t 0.8 0.2 cloudy sun cloudy cloudy 0.3 0.7 X_t sun cloudy P(g_t|X_t) 0.7 0.4

glasses glasses No glasses

w_t sun cloudy P(w_t) 0.5 0.5 w_t sun cloudy P(w_t) ? ?

slide-51
SLIDE 51

Weather HMM example

X_{t-1} X_t sun sun sun cloudy X_t 0.8 0.2 cloudy sun cloudy cloudy 0.3 0.7 w_t sun cloudy P(w_t) 0.5 0.5 w_t sun cloudy P(w_t) 0.55 0.45

glasses glasses No glasses

X_t sun cloudy P(g_t|X_t) 0.7 0.4

slide-52
SLIDE 52

Weather HMM example

X_{t-1} X_t sun sun sun cloudy X_t 0.8 0.2 cloudy sun cloudy cloudy 0.3 0.7 w_t sun cloudy P(w_t) 0.5 0.5 w_t sun cloudy P(w_t) 0.55 0.45 w_t sun cloudy P(w_t) ? ?

glasses glasses No glasses

X_t sun cloudy P(g_t|X_t) 0.7 0.4

slide-53
SLIDE 53

Weather HMM example

X_{t-1} X_t sun sun sun cloudy X_t 0.8 0.2 cloudy sun cloudy cloudy 0.3 0.7 w_t sun cloudy P(w_t) 0.5 0.5 w_t sun cloudy P(w_t) 0.55 0.45 w_t sun cloudy P(w_t) 0.68 0.31

glasses glasses No glasses

X_t sun cloudy P(g_t|X_t) 0.7 0.4

slide-54
SLIDE 54

Weather HMM example

X_{t-1} X_t sun sun sun cloudy X_t 0.8 0.2 cloudy sun cloudy cloudy 0.3 0.7 w_t sun cloudy P(w_t) 0.68 0.31

glasses glasses No glasses

X_t sun cloudy P(g_t|X_t) 0.7 0.4 w_t sun cloudy P(w_t) ? ?

slide-55
SLIDE 55

Weather HMM example

X_{t-1} X_t sun sun sun cloudy X_t 0.8 0.2 cloudy sun cloudy cloudy 0.3 0.7 w_t sun cloudy P(w_t) 0.68 0.31

glasses glasses No glasses

X_t sun cloudy P(g_t|X_t) 0.7 0.4 w_t sun cloudy P(w_t) 0.64 0.36

slide-56
SLIDE 56

Weather HMM example

X_{t-1} X_t sun sun sun cloudy X_t 0.8 0.2 cloudy sun cloudy cloudy 0.3 0.7 w_t sun cloudy P(w_t) 0.68 0.31

glasses glasses No glasses

X_t sun cloudy P(g_t|X_t) 0.7 0.4 w_t sun cloudy P(w_t) 0.64 0.36 w_t sun cloudy P(w_t) ? ?

slide-57
SLIDE 57

Weather HMM example

X_{t-1} X_t sun sun sun cloudy X_t 0.8 0.2 cloudy sun cloudy cloudy 0.3 0.7 w_t sun cloudy P(w_t) 0.68 0.31

glasses glasses No glasses

X_t sun cloudy P(g_t|X_t) 0.7 0.4 w_t sun cloudy P(w_t) 0.64 0.36 w_t sun cloudy P(w_t) 0.76 0.24

slide-58
SLIDE 58

Particle Filtering

Slide: Berkeley CS188 course notes (downloaded Summer 2015)

slide-59
SLIDE 59

Representation: Particles

  • Our representation of P(X) is now a list of N

particles (samples)

  • Generally, N << |X|
  • Storing map from X to counts would defeat the

point

  • P(x) approximated by number of particles with

value x

  • So, many x may have P(x) = 0!
  • More particles, more accuracy
  • For now, all particles have a weight of 1

Particles : (3,3) (2,3) (3,3) (3,2) (3,3) (3,2) (1,2) (3,3) (3,3) (2,3)

Slide: Berkeley CS188 course notes (downloaded Summer 2015)

slide-60
SLIDE 60

Particle Filtering: Elapse Time

  • Each particle is moved by sampling

its next position from the transition model

  • This is like prior sampling – samples’

frequencies refmect the transition probabilities

  • Here, most samples move clockwise, but

some move in another direction or stay in place

  • This captures the passage of time
  • If enough samples, close to exact values

before and after (consistent)

Particles: (3,3) (2,3) (3,3) (3,2) (3,3) (3,2) (1,2) (3,3) (3,3) (2,3) Particles: (3,2) (2,3) (3,2) (3,1) (3,3) (3,2) (1,3) (2,3) (3,2) (2,2)

Slide: Berkeley CS188 course notes (downloaded Summer 2015)

slide-61
SLIDE 61
  • Slightly trickier:
  • Don’t sample observation, fjx it
  • Similar to likelihood weighting,

downweight samples based on the evidence

  • As before, the probabilities don’t sum to
  • ne, since all have been downweighted

(in fact they now sum to (N times) an approximation of P(e))

Particle Filtering: Observe

Particles: (3,2) w=.9 (2,3) w=.2 (3,2) w=.9 (3,1) w=.4 (3,3) w=.4 (3,2) w=.9 (1,3) w=.1 (2,3) w=.2 (3,2) w=.9 (2,2) w=.4 Particles: (3,2) (2,3) (3,2) (3,1) (3,3) (3,2) (1,3) (2,3) (3,2) (2,2)

Slide: Berkeley CS188 course notes (downloaded Summer 2015)

slide-62
SLIDE 62

Particle Filtering: Resample

  • Rather than tracking weighted

samples, we resample

  • N times, we choose from our

weighted sample distribution (i.e. draw with replacement)

  • This is equivalent to renormalizing

the distribution

  • Now the update is complete for

this time step, continue with the next one

Particles: (3,2) w=.9 (2,3) w=.2 (3,2) w=.9 (3,1) w=.4 (3,3) w=.4 (3,2) w=.9 (1,3) w=.1 (2,3) w=.2 (3,2) w=.9 (2,2) w=.4 (New) Particles: (3,2) (2,2) (3,2) (2,3) (3,3) (3,2) (1,3) (2,3) (3,2) (3,2)

Slide: Berkeley CS188 course notes (downloaded Summer 2015)

slide-63
SLIDE 63

Recap: Particle Filtering

  • Particles: track samples of states rather than an explicit

distribution

Particles: (3,3) (2,3) (3,3) (3,2) (3,3) (3,2) (1,2) (3,3) (3,3) (2,3)

Elapse Weight Resample

Particles: (3,2) (2,3) (3,2) (3,1) (3,3) (3,2) (1,3) (2,3) (3,2) (2,2) Particles: (3,2) w=.9 (2,3) w=.2 (3,2) w=.9 (3,1) w=.4 (3,3) w=.4 (3,2) w=.9 (1,3) w=.1 (2,3) w=.2 (3,2) w=.9 (2,2) w=.4 (New) Particles: (3,2) (2,2) (3,2) (2,3) (3,3) (3,2) (1,3) (2,3) (3,2) (3,2)

Slide: Berkeley CS188 course notes (downloaded Summer 2015)

slide-64
SLIDE 64

Robot Localization

  • In robot localization:
  • We know the map, but not the robot’s position
  • Observations may be vectors of range fjnder

readings

  • State space and readings are typically

continuous (works basically like a very fjne grid) and so we cannot store B(X)

  • Particle fjltering is a main technique

Slide: Berkeley CS188 course notes (downloaded Summer 2015)

slide-65
SLIDE 65

Particle Filter Localization (Sonar)

slide-66
SLIDE 66

Particle Filter Localization (Laser)

slide-67
SLIDE 67

Dynamic Bayes Nets

slide-68
SLIDE 68

Dynamic Bayes Nets (DBNs)

  • We want to track multiple variables over time,

using multiple sources of evidence

  • Idea: Repeat a fjxed Bayes net structure at

each time

  • Variables from time t can condition on those

from t-1

  • Dynamic Bayes nets are a generalization of

HMMs

G1

a

E1

a E1 b

G1

b

G2

a

E2

a

E2

b

G2

b

t =1 t =2

G3

a

E3

a

E3

b

G3

b

t =3

slide-69
SLIDE 69

DBN Particle Filters

  • A particle is a complete sample for a time step
  • Initialize: Generate prior samples for the t=1 Bayes net
  • Example particle: G1

a = (3,3) G1 b = (5,3)

  • Elapse time: Sample a successor for each particle
  • Example successor: G2

a = (2,3) G2 b = (6,3)

  • Observe: Weight each entire sample by the likelihood of

the evidence conditioned on the sample

  • Likelihood: P(E1

a |G1 a ) * P(E1 b |G1 b )

  • Resample: Select prior samples (tuples of values) in

proportion to their likelihood