6 Uncertainty6
6 Uncertainty6
Alan Mackworth
• Final exam
– Thursday, April 18th, 8:30 – 11am in PHRM 1101
– Same general format as midterm (~60% short questions)
• List of short questions will be on Connect
– Practice final to be provided
– More emphasis on material after midterm
– How to study?
• Practice exercises, assignments, short questions,
lecture notes, text, problems in text, …
• Use TA and my office hours (extra office hours TBA if needed)
• Review sessions: last class plus more TBA if needed
• Submit topics you want reviewed on Connect
2
Announcements (2)
• Teaching Evaluations are online
– You should have received a message about them
– Secure, confidential, mobile access
• Your feedback is important!
– Allows us to assess and improve the course material
– I use it to assess and improve my teaching methods
– The department as a whole uses it to shape the curriculum
– Teaching evaluation results are important for instructors
• Appointment, reappointment, tenure, promotion and merit, salary
– UBC takes them very seriously (now)
– Evaluations close at 11:59PM on April 9, 2013.
• Before exam, but instructors can’t see results until after we submit grades
– Please do it!
• Take a few minutes and visit https://eval.olt.ubc.ca/science
3
Lecture Overview
4
Learning Goals For Previous Class
• Build a Bayesian Network for a given domain
• Understand basics of Markov Chains and Hidden Markov
Models
• Classify the types of inference:
– Diagnostic, Predictive, Mixed, Intercausal
5
Inference in Bayesian Networks
Given:
– A Bayesian Network BN, and
– Observations of a subset of its variables E: E=e
– A subset of its variables Y that is queried
Compute: The conditional probability P(Y|E=e)
How: Run the Variable Elimination (VE) algorithm
Given:
– A Bayesian Network BN, and
– Observations of a subset of its variables E: E=e
– A subset of its variables Y that is queried
Compute: The conditional probability P(Y|E=e)
How: Run the Variable Elimination (VE) algorithm
7
Lecture Overview
8
Factors
• A factor is a function from a tuple of random variables to
the real numbers R
• We write a factor on variables X1,… ,Xj as f(X1,… ,Xj)
X Y Z val
• P(Z|X,Y) is a factor f (X,Y,Z)
t t t 0.1
– Factors do not have to sum to one
t t f 0.9
– P(Z|X,Y) is a set of probability
t f t 0.2
distributions: one for each
t f f 0.8
combination of values of X and Y
f t t 0.4
f(X, Y)Z=f f t f 0.6
• P(Z=f|X,Y) is a factor f(X,Y) f f t 0.3
f f f 0.7
9
Operation 1: assigning a variable
• We can make new factors out of an existing factor
Y val
f(X=t,Y=f,Z=f): 0.8
t 0.9
Number f 0.8
Factor of Y
11
Operation 2: Summing out a variable
• Our second operation on factors:
we can marginalize out (or sum out) a variable
– Exactly as before. Only difference: factors don’t have to sum to 1
– Marginalizing out a variable X from a factor f(X1,… ,Xn) yields a new
factor defined on {X1,… ,Xn } \ {X}
⎛ ⎞
⎜ ∑
⎜ X f ⎟⎟(X 2 ,…, X j ) = ∑ f ( X 1 = x, X 2 ,…, X j )
⎝ 1 ⎠ x∈dom( X 1 )
B A C val (∑Bf3)(A,C)
t t t 0.03
A C val
t t f 0.07
t t 0.57
f t t 0.54
f t f 0.36 t f 0.43
f t 0.6 f f f
f f 0.4
13
Operation 3: multiplying factors
( f1 × f 2 )( A, B, C) = f1 ( A, B) f 2 ( B, C)
14
Lecture Overview
15
General Inference in Bayesian Networks
Given
– A Bayesian Network BN, and
– Observations of a subset of its variables E: E=e
– A subset of its variables Y that is queried
P(Y = y, E = e) P(Y = y, E = e)
P(Y = y | E = e) = =
P ( E = e) ∑ P(Y = y' , E = e)
y '∈dom (Y )
• Are we done?
– No. This would still represent the whole JPD (as a single factor)
– We need to exploit the compactness of Bayesian networks 17
Variable Elimination: Intro (2)
18
Computing sums of products
• Inference in Bayesian networks thus reduces to computing
the sums of products
– Example: it takes 9 multiplications to evaluate the expression
ab + ac + ad + aeh + afh + agh.
– How can this expression be evaluated more efficiently?
• Factor out the a and then the h giving a(b + c + d + h(e + f + g))
• This takes only 2 multiplications (same number of additions as above)
n
• Similarly, how can we compute ∑∏ f
Zk i =1
i efficiently?
∑ f (Z
Zk
1 k ) f 2 (Y ) f 3 ( Z k , Y ) f 4 ( X , Y )
⎛ ⎞
= f 2 (Y ) f 4 ( X , Y )⎜⎜ ∑ f1 ( Z k ) f 3 (Z k , Y ) ⎟⎟
⎝ Z k ⎠ 19
Summing out a variable efficiently
⎛ ⎞
∑ f1 × ... × f k = f1 × ... × f i × ⎜⎜ ∑ f i +1 × ... × f k ⎟⎟
Zk ⎝ Z k ⎠
New factor! Let’s call it f’
∑f
Zk
1 × ... × f k = f1 × ... × f i × f '
20
The variable elimination algorithm
See the algorithm VE_BN in the P&M text, Section 6.4.1, Figure 6.8, p. 254.
21
Lecture Overview
22
Variable elimination example: compute P(G|H=h1)
Step 1: construct a factor for each cond. probability
P(G,H) = ∑A,B,C,D,E,F,I P(A,B,C,D,E,F,G,H,I) =
= ∑A,B,C,D,E,F,I P(A)P(B|A)P(C)P(D|B,C)P(E|C)P(F|D)P(G|F,E)P(H|G)P(I|G)
= ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f7(H,G) f8(I,G)
23
Variable elimination example: compute P(G|H=h1)
Step 2: assign observed variables their observed value
P(G,H) = ∑A,B,C,D,E,F,I P(A,B,C,D,E,F,G,H,I) =
= ∑A,B,C,D,E,F,I P(A)P(B|A)P(C)P(D|B,C)P(E|C)P(F|D)P(G|F,E)P(H|G)P(I|G)
= ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f7(H,G) f8(I,G)
Observe H=h1:
P(G,H=h1)=∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C)
f5(F, D) f6(G,F,E) f9(G) f8(I,G)
24
Variable elimination example: compute P(G|H=h1)
Step 3: decompose sum
P(G,H=h1) = ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f9(G) f8(I,G)
Elimination ordering: A, C, E, I, B, D, F 25
Variable elimination example: compute P(G|H=h1)
Step 3: decompose sum
P(G,H=h1) = ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f9(G) f8(I,G)
Elimination ordering: A, C, E, I, B, D, F 26
Variable elimination example: compute P(G|H=h1)
Step 4: sum out non- query variables (one at a time)
P(G,H=h1) = ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f9(G) f8(I,G)
Elimination ordering: A, C, E, I, B, D, F 27
Variable elimination example: compute P(G|H=h1)
Step 4: sum out non- query variables (one at a time)
P(G,H=h1) = ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f9(G) f8(I,G)
Elimination ordering: A, C, E, I, B, D, F 28
Variable elimination example: compute P(G|H=h1)
Step 4: sum out non- query variables (one at a time)
P(G,H=h1) = ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f9(G) f8(I,G)
Elimination ordering: A, C, E, I, B, D, F 29
Variable elimination example: compute P(G|H=h1)
Step 4: sum out non- query variables (one at a time)
P(G,H=h1) = ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f9(G) f8(I,G)
Elimination ordering: A, C, E, I, B, D, F 30
Variable elimination example: compute P(G|H=h1)
Step 4: sum out non- query variables (one at a time)
P(G,H=h1) = ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f9(G) f8(I,G)
Elimination ordering: A, C, E, I, B, D, F 31
Variable elimination example: compute P(G|H=h1)
Step 4: sum out non- query variables (one at a time)
P(G,H=h1) = ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f9(G) f8(I,G)
Elimination ordering: A, C, E, I, B, D, F 32
Variable elimination example: compute P(G|H=h1)
Step 4: sum out non- query variables (one at a time)
P(G,H=h1) = ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f9(G) f8(I,G)
Elimination ordering: A, C, E, I, B, D, F 33
Variable elimination example: compute P(G|H=h1)
Step 5: multiply the remaining factors
P(G,H=h1) = ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f9(G) f8(I,G)
= f17(G)
Elimination ordering: A, C, E, I, B, D, F 34
Variable elimination example: compute P(G|H=h1)
Step 6: normalize
P(G,H=h1) = ∑A,B,C,D,E,F,I f0(A) f1(B,A) f2(C) f3(D,B,C) f4(E,C) f5(F, D) f6(G,F,E) f9(G) f8(I,G)
• Practice Exercises
– Reminder: they are helpful for staying on top of the material,
and for studying for the exam
– Exercise 10 is on conditional independence.
– Exercise 11 is on variable elimination
• Assignment 4 is due on Wednesday, April 3rd
– You should now be able to solve all questions: 1, 2, 3, 4 and 5
36