CS 294-5: Statistical Natural Language Processing

Download Report

Transcript CS 294-5: Statistical Natural Language Processing

Advanced Artificial Intelligence
Lecture 4B: Bayes Networks
Bayes Network
 We just encountered our first Bayes
network:
Cancer
P(cancer) and P(Test positive |
cancer) is called the “model”
Calculating P(Test positive) is called
“prediction”
Test
positive
Calculating P(Cancer | test positive) is
called “diagnostic reasoning”
2
Bayes Network
 We just encountered our first Bayes
network:
Cancer
Cancer
versus
Test
positive
Test
positive
3
Independence
 Independence
P(C, TP) = P(C)× P(TP)
Cancer
 What does this mean
for our test?
 Don’t take it!
Test
positive
4
Independence
 Two variables are independent if:
 This says that their joint distribution factors into a product two
simpler distributions
 This implies:
 We write:
 Independence is a simplifying modeling assumption
 Empirical joint distributions: at best “close” to independent
5
Example: Independence
 N fair, independent coin flips:
h
0.5
h
0.5
h
0.5
t
0.5
t
0.5
t
0.5
6
Example: Independence?
T
P
warm
0.5
cold
0.5
T
W
P
T
W
P
warm
sun
0.4
warm
sun
0.3
warm
rain
0.1
warm
rain
0.2
cold
sun
0.2
cold
sun
0.3
cold
rain
0.3
cold
rain
0.2
W
P
sun
0.6
rain
0.4
7
Conditional Independence

P(Toothache, Cavity, Catch)

If I have a Toothache, a dental probe might be more likely to catch

But: if I have a cavity, the probability that the probe catches doesn't depend
on whether I have a toothache:
 P(+catch | +toothache, +cavity) = P(+catch | +cavity)

The same independence holds if I don’t have a cavity:

Catch is conditionally independent of Toothache given Cavity:
 P(+catch | +toothache, cavity) = P(+catch| cavity)
 P(Catch | Toothache, Cavity) = P(Catch | Cavity)

Equivalent conditional independence statements:
 P(Toothache | Catch , Cavity) = P(Toothache | Cavity)
 P(Toothache, Catch | Cavity) = P(Toothache | Cavity) P(Catch | Cavity)
 One can be derived from the other easily
 We write:
8
Bayes Network Representation
P(cavity)
Cavity
P(catch | cavity)
1 parameter
P(toothache | cavity)
2 parameters
2 parameters
Catch
Toothache
Versus: 23-1 = 7 parameters
9
A More Realistic Bayes Network
10
Example Bayes Network: Car
11
Graphical Model Notation
 Nodes: variables (with domains)
 Can be assigned (observed) or
unassigned (unobserved)
 Arcs: interactions
 Indicate “direct influence” between
variables
 Formally: encode conditional
independence (more later)
 For now: imagine that arrows
mean direct causation
(they may not!)
12
Example: Coin Flips
 N independent coin flips
X1
X2
Xn
 No interactions between variables:
absolute independence
13
Example: Traffic
 Variables:
 R: It rains
 T: There is traffic
R
 Model 1: independence
T
 Model 2: rain causes traffic
 Why is an agent using model 2 better?
14
Example: Alarm Network
 Variables





B: Burglary
A: Alarm goes off
M: Mary calls
J: John calls
E: Earthquake!
Earthquake
Burglary
Alarm
John
calls
Mary
calls
15
Bayes Net Semantics
 A set of nodes, one per variable X
 A directed, acyclic graph
A1
An
 A conditional distribution for each node
 A collection of distributions over X, one for
each combination of parents’ values
X
 CPT: conditional probability table
 Description of a noisy “causal” process
A Bayes net = Topology (graph) + Local Conditional Probabilities
16
Probabilities in BNs
 Bayes nets implicitly encode joint distributions
 As a product of local conditional distributions
 To see what probability a BN gives to a full assignment, multiply
all the relevant conditionals together:
 Example:
 This lets us reconstruct any entry of the full joint
 Not every BN can represent every joint distribution
 The topology enforces certain conditional independencies
17
Example: Coin Flips
X1
X2
Xn
h
0.5
h
0.5
h
0.5
t
0.5
t
0.5
t
0.5
Only distributions whose variables are absolutely independent
18
can be represented by a Bayes’ net with no arcs.
Example: Traffic
R
+r
T
r
+r
1/4
r
3/4
+t
3/4
t
1/4
+t
1/2
t
1/2
R
T
joint
+r
+t
3/16
+r
-t
1/16
-r
+t
3/8
-r
-t
3/8
19
Example: Alarm Network
1
Burglary
Alarm
John
calls
1
Earthqk
2
How many parameters?
4
Mary
calls
10
2
Example: Alarm Network
B
P(B)
+b
0.001
b
0.999
Burglary
Earthqk
E
P(E)
+e
0.002
e
0.998
B
E
A
P(A|B,E)
+b
+e
+a
0.95
+b
+e
a
0.05
+b
e
+a
0.94
Alarm
John
calls
Mary
calls
A
J
P(J|A)
A
M
P(M|A)
+b
e
a
0.06
+a
+j
0.9
+a
+m
0.7
b
+e
+a
0.29
+a
j
0.1
+a
m
0.3
b
+e
a
0.71
a
+j
0.05
a
+m
0.01
b
e
+a
0.001
a
j
0.95
a
m
0.99
b
e
a
0.999
Example: Alarm Network
Earthquake
Burglary
Alarm
John
calls
Mary
calls
Bayes’ Nets
 A Bayes’ net is an
efficient encoding
of a probabilistic
model of a domain
 Questions we can ask:
 Inference: given a fixed BN, what is P(X | e)?
 Representation: given a BN graph, what kinds of
distributions can it encode?
 Modeling: what BN is most appropriate for a given
domain?
23
Remainder of this Class
 Find Conditional (In)Dependencies
 Concept of “d-separation”
24
Causal Chains
 This configuration is a “causal chain”
X: Low pressure
X
Y
Z
Y: Rain
Z: Traffic
 Is X independent of Z given Y?
Yes!
 Evidence along the chain “blocks” the influence
25
Common Cause
 Another basic configuration: two
effects of the same cause
Y
 Are X and Z independent?
 Are X and Z independent given Y?
X
Z
Y: Alarm
X: John calls
Z: Mary calls
Yes!
 Observing the cause blocks
influence between effects.
26
Common Effect
 Last configuration: two causes of
one effect (v-structures)
 Are X and Z independent?
 Yes: the ballgame and the rain cause traffic,
but they are not correlated
 Still need to prove they must be (try it!)
 Are X and Z independent given Y?
 No: seeing traffic puts the rain and the
ballgame in competition as explanation?
 This is backwards from the other cases
X
Z
Y
X: Raining
Z: Ballgame
Y: Traffic
 Observing an effect activates influence
between possible causes.
27
The General Case
 Any complex example can be analyzed using
these three canonical cases
 General question: in a given BN, are two
variables independent (given evidence)?
 Solution: analyze the graph
28
Reachability
 Recipe: shade evidence nodes
L
 Attempt 1: Remove shaded nodes.
If two nodes are still connected by
an undirected path, they are not
conditionally independent
R
B
 Almost works, but not quite
 Where does it break?
 Answer: the v-structure at T doesn’t
count as a link in a path unless
“active”
D
T
29
Reachability (D-Separation)
 Question: Are X and Y
conditionally independent
given evidence vars {Z}?
 Yes, if X and Y “separated” by Z
 Look for active paths from X to Y
 No active paths = independence!
 A path is active if each triple
is active:
 Causal chain A  B  C where B
is unobserved (either direction)
 Common cause A  B  C
where B is unobserved
 Common effect (aka v-structure)
A  B  C where B or one of its
descendents is observed
 All it takes to block a path is
a single inactive segment
Active Triples
Inactive Triples
Example
Yes
R
B
T
T’
31
Example
L
Yes
R
Yes
D
B
T
Yes
T’
32
Example
 Variables:




R: Raining
T: Traffic
D: Roof drips
S: I’m sad
R
T
 Questions:
D
S
Yes
33
A Common BN
Unobservable cause
A
T1
T2
T3
…
TN
Diagnostic Reasoning:
P(A | T1,T2,T3,...,TN )
Tests
time
P(TN | A,T1....TN-1 ) P(A | T1....TN -1 )
P(A | T1....TN ) =
P(TN | T1....TN -1 )
=
1
P(TN | A) P(A | T1....TN-1 )
P(TN | T1....TN-1 )
µ P(TN | A) P(A | T1....TN-1 )
N
µ P(A) Õ P(Tn | A)
n=1
34
A Common BN
Unobservable cause
A
T1
T2
T3
…
TN
Diagnostic Reasoning:
P(A | T1,T2,T3,...,TN )
Tests
time
N
a + ¬ P(A) Õ P(Tn | A)
n=1
N
a - ¬ P(ØA) Õ P(Tn | ØA)
P(A | T1...TN ) = ha+
P(ØA | T1...TN ) = ha-
n=1
1
h¬
a+ + a-
35
A Common BN
Unobservable cause
A
T1
T2
T3
…
TN
Diagnostic Reasoning:
P(A | T1,T2,T3,...,TN )
Tests
time
N
b+ ¬ log P(A) + å log P(Tn | A)
n=1
N
b- ¬ log P(ØA) + å log P(Tn |ØA)
P(A | T1...TN ) = h exp b+
P(ØA | T1...TN ) = h exp b-
n=1
1
h¬
exp b+ + exp b-
36
A Common BN
Unobservable cause
A
T1
T2
T3
…
TN
Diagnostic Reasoning:
P(A | T1,T2,T3,...,TN )
Tests
time
b = log
P(A | T1... TN )
P(A | T1... TN )
= log
P(ØA | T1... TN )
1- P(A | T1... TN )
N
b ¬ log P(A) - log P(ØA) + å log P(Tn | A) - log P(Tn |ØA)
n=1
P(A | T1... TN ) =1-
1
1+ exp b
37
Causality?
 When Bayes’ nets reflect the true causal patterns:
 Often simpler (nodes have fewer parents)
 Often easier to think about
 Often easier to elicit from experts
 BNs need not actually be causal
 Sometimes no causal net exists over the domain
 End up with arrows that reflect correlation, not causation
 What do the arrows really mean?
 Topology may happen to encode causal structure
 Topology only guaranteed to encode conditional independence
38
Summary
 Bayes network:
 Graphical representation of joint distributions
 Efficiently encode conditional independencies
 Reduce number of parameters from exponential
to linear (in many cases)
39