Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in...

45
Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne Koller) 1

Transcript of Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in...

Page 1: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Approximate Inference in Bayes NetsSampling based methods

Mausam

(Based on slides by Jack Breese and Daphne Koller)

1

Page 2: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Bayes Nets is a generative model• We can easily generate samples from the

distribution represented by the Bayes net

– Generate one variable at a time in topological order

2

Page 3: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

3

Page 4: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

4

Page 5: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

5

Page 6: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

6

Page 7: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

7

Page 8: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

8

Page 9: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

9

Page 10: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

10

Page 11: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

11

Page 12: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

12

Page 13: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

13

Page 14: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

14

Page 15: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

15

Page 16: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

16

Page 17: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

17

Page 18: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

18

Page 19: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Rejection Sampling

• Sample from the prior

– reject if do not match the evidence

• Returns consistent posterior estimates

• Hopelessly expensive if P(e) is small

– P(e) drops off exponentially if no. of evidence vars

19

Page 20: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Likelihood Weighting

• Idea:

– fix evidence variables

– sample only non-evidence variables

– weight each sample by the likelihood of evidence

20

Page 21: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

21

Page 22: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

22

Page 23: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

23

Page 24: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

24

Page 25: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

25

Page 26: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

26

Page 27: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

27

Page 28: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

28

Page 29: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

29

Page 30: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

P(B|C)

30

Page 31: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Likelihood Weighting

• Sampling probability: S(z,e) =

– Neither prior nor posterior

• Wt for a sample <z,e>:

• Weighted Sampling probability S(z,e)w(z,e)

=

= P(z,e)

• returns consistent estimates

• performance degrades w/ many evidence vars

– but a few samples have nearly all the total weight

– late occuring evidence vars do not guide sample generation

i

))Parents(Z|P(z ii

i

ii )Parents(E|P(e e) w(z,

i

ii )Parents(E|P(ei

))Parents(Z|P(z ii

31

Page 32: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

32

MCMC with Gibbs Sampling• Fix the values of observed variables

• Set the values of all non-observed variables randomly

• Perform a random walk through the space of complete variable assignments. On each move:

1. Pick a variable X

2. Calculate Pr(X=true | all other variables)

3. Set X to true with that probability

• Repeat many times. Frequency with which any variable X is true is it’s posterior probability.

• Converges to true posterior when frequencies stop changing significantly

– stable distribution, mixing

Page 33: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

33

Markov Blanket Sampling

• How to calculate Pr(X=true | all other variables) ?

• Recall: a variable is independent of all others given it’s Markov Blanket

– parents

– children

– other parents of children

• So problem becomes calculating Pr(X=true | MB(X))

– We solve this sub-problem exactly

– Fortunately, it is easy to solve

( )

( ) ( | ( )) ( | ( ))Y Children X

P X P X Parents X P Y Parents Y

Page 34: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

34

Example

( )

( ) ( | ( )) ( | ( ))Y Children X

P X P X Parents X P Y Parents Y

( )

( , , , )( | , , )

( , , )

( , , )

( ) ( )( | ) ( | , )

( , , )

( | )

( | ) ( ) ( | , )

( | , )

P X A B CP X A B C

P A B C

P A B

P A P X A P C P B

C

P A P CP X A P B X C

P A B C

P X

X

A P B X C

C

A

X

B

C

Page 35: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Example

35

Smoking

Heartdisease

Lungdisease

Shortnessof breath

P(h)

s 0.6

~s 0.1

P(g)

s 0.8

~s 0.1

H G P(b)

h g 0.9

h ~g 0.8

~h g 0.7

~h ~g 0.1

P(s)

0.2

Page 36: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Example

• Evidence: s, b

36

Smoking

Heartdisease

Lungdisease

Shortnessof breath

P(h)

s 0.6

~s 0.1

P(g)

s 0.8

~s 0.1

H G P(b)

h g 0.9

h ~g 0.8

~h g 0.7

~h ~g 0.1

P(s)

0.2

Page 37: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Example

• Evidence: s, b

• Randomly set: h, b

37

Smoking

Heartdisease

Lungdisease

Shortnessof breath

P(h)

s 0.6

~s 0.1

P(g)

s 0.8

~s 0.1

H G P(b)

h g 0.9

h ~g 0.8

~h g 0.7

~h ~g 0.1

P(s)

0.2

Page 38: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Example

• Evidence: s, b

• Randomly set: h, g

• Sample H using P(H|s,g,b)

38

Smoking

Heartdisease

Lungdisease

Shortnessof breath

P(h)

s 0.6

~s 0.1

P(g)

s 0.8

~s 0.1

H G P(b)

h g 0.9

h ~g 0.8

~h g 0.7

~h ~g 0.1

P(s)

0.2

Page 39: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Example

• Evidence: s, b

• Randomly set: ~h, g

• Sample H using P(H|s,g,b)

• Suppose result is ~h

39

Smoking

Heartdisease

Lungdisease

Shortnessof breath

P(h)

s 0.6

~s 0.1

P(g)

s 0.8

~s 0.1

H G P(b)

h g 0.9

h ~g 0.8

~h g 0.7

~h ~g 0.1

P(s)

0.2

Page 40: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Example

• Evidence: s, b

• Randomly set: ~h, g

• Sample H using P(H|s,g,b)

Suppose result is ~h

Sample G using P(G|s,~h,b)

40

Smoking

Heartdisease

Lungdisease

Shortnessof breath

P(h)

s 0.6

~s 0.1

P(g)

s 0.8

~s 0.1

H G P(b)

h g 0.9

h ~g 0.8

~h g 0.7

~h ~g 0.1

P(s)

0.2

Page 41: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Example

• Evidence: s, b

• Randomly set: ~h, g

• Sample H using P(H|s,g,b)

Suppose result is ~h

Sample G using P(G|s,~h,b)

Suppose result is g

41

Smoking

Heartdisease

Lungdisease

Shortnessof breath

P(h)

s 0.6

~s 0.1

P(g)

s 0.8

~s 0.1

H G P(b)

h g 0.9

h ~g 0.8

~h g 0.7

~h ~g 0.1

P(s)

0.2

Page 42: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Example

• Evidence: s, b

• Randomly set: ~h, g

• Sample H using P(H|s,g,b)

Suppose result is ~h

Sample G using P(G|s,~h,b)

Suppose result is g

Sample G using P(G|s,~h,b)42

Smoking

Heartdisease

Lungdisease

Shortnessof breath

P(h)

s 0.6

~s 0.1

P(g)

s 0.8

~s 0.1

H G P(b)

h g 0.9

h ~g 0.8

~h g 0.7

~h ~g 0.1

P(s)

0.2

Page 43: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Example

• Evidence: s, b

• Randomly set: ~h, g

• Sample H using P(H|s,g,b)

Suppose result is ~h

Sample G using P(G|s,~h,b)

Suppose result is g

Sample G using P(G|s,~h,b)

Suppose result is ~g 43

Smoking

Heartdisease

Lungdisease

Shortnessof breath

P(h)

s 0.6

~s 0.1

P(g)

s 0.8

~s 0.1

H G P(b)

h g 0.9

h ~g 0.8

~h g 0.7

~h ~g 0.1

P(s)

0.2

Page 44: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Gibbs MCMC Summary

• Advantages:

– No samples are discarded

– No problem with samples of low weight

– Can be implemented very efficiently• 10K samples @ second

• Disadvantages:

– Can get stuck if relationship between two variables is deterministic

– Many variations have been devised to make MCMC more robust

44

P(X|E) =number of samples with X=x

total number of samples

Page 45: Approximate Inference in Bayes Nets › courses › csep573 › 11wi › ...Approximate Inference in Bayes Nets Sampling based methods Mausam (Based on slides by Jack Breese and Daphne

Other inference methods

• Exact inference

– Junction tree

• Approximate inference

– Belief Propagation

– Variational Methods

45