solutions homework #2 - eth z · pdf file1 solutions homework #2 carlos cotrini october 27,...
TRANSCRIPT
1
Solutions homework #2Carlos Cotrini
October 27, 2017
Probabilistic foundations of artificial intelligence
2
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
B indep. I given F?
3
Principle of d-separation● Given a set of observed variables, if there is no
active trail between two variables, then they are independent.
B
A
C
D
B
A
C
D
B indep from C | A Unclear if B indep from C | A, D
4
1. Bayesian Networks: d-separation● Recap on active trails. Case 1. (Mountain)
Observed variable
Hidden variable
Observed orhidden variable
Inactive!
5
1. Bayesian Networks: d-separation● Recap on active trails. Case 2a. (Downhill)
Inactive!
6
1. Bayesian Networks: d-separation● Recap on active trails. Case 2b. (Uphill)
Inactive!
7
1. Bayesian Networks: d-separation● Recap on active trails. Case 3. (Valley)
Inactive!
trail
8
1. Bayesian Networks: d-separation● Recap on active trails. Case 3.
Inactive!
trail
9
1. Bayesian Networks: d-separation● Recap on active trails. Case 3.
Inactive!
trail
10
1. Bayesian Networks: d-separation● Recap on active trails. Case 3.
Inactive!
trail
11
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
12
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
A indep. F?
13
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
A indep. F?
14
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
A indep. F?
15
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
A indep. F?
INCONCLUSIVE
16
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
A indep. G?
17
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
A indep. G?
18
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
A indep. G?
19
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
A indep. G?
YES!
20
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
B indep. I given F?
21
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
B indep. I given F?
22
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
B indep. I given F?
INCONCLUSIVE
23
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
D indep. J given G, H?
24
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
D indep. J given G, H?
25
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
D indep. J given G, H?
26
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
D indep. J given G, H?
YES!
27
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
I indep. B given H?
28
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
I indep. B given H?
YES!
29
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
D indep. J?
30
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
D indep. J?
INCONCLUSIVE
31
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
I indep. C given H, F?
32
1. Bayesian Networks: d-separation● Solutions task 1
A
B
C
D
F
E
G
H
I
J
I indep. C given H, F?
INCONCLUSIVE
33
Be careful with the direction of the arrows!
B
A
C
D
B indep from C ?
34
Be careful with the direction of the arrows!
B
A
C
D
A indep from D ?
35
2. Variable elimination● Compute
P(J = j)
AB
C
D
F
E
G
H
I
J
36
2. Variable elimination● Compute
P(J = j)
AB
C
D
F
E
G
H
I
J
37
2. Variable elimination● Compute
P(J = j)
AB
C
D
F
E
G
H
I
J
38
2. Variable elimination● Compute
P(J = j)
AB
C
D
F
E
G
H
I
J
39
2. Variable elimination● Compute
P(J = j)
AB
C
D
F
E
G
H
I
J
40
2. Variable elimination● Compute
P(J = j)
AB
C
D
F
E
G
H
I
J
41
2. Variable elimination● Compute
P(J = j)
AB
C
D
F
E
G
H
I
J
1
3. An algorithm for d-separation● Given a Bayesian Network, a variable X, and a
set of variables E with observed values e, compute all variables Z that are indep. from X given E.
2
3. Algorithm for d-separation
W
S
U
X
I
A
P
Q
EB
R
K
XXXX
3
3. Algorithm for d-separation
W
S
U
X
I
A
P
Q
EB
R
K
XXXX
D-reachable: if it can be reached with an active trail from X
d-reachable
4
3. Algorithm for d-separation
W
S
U
X
I
A
P
Q
EB
R
K
XXXX
5
3. Algorithm for d-separation
W
S
U
X
I
A
P
Q
EB
R
K
XXXX
6
3. Algorithm for d-separation
Key insight: Subtrails of active trails are also active!
7
3. Algorithm for d-separation
Key insight: Subtrails of active trails are also active!
Compute d-reachable variables with a depth-first (or breadth-first) search.
8
3. Algorithm for d-separation
W
S
U
Y
I
A
P
Q
EB
R
KtoVisit = [X]
X
d-reachable = {}
9
3. Algorithm for d-separation
W
S
U
Y
I
A
P
Q
EB
R
KtoVisit = []
X
d-reachable = {X}
10
3. Algorithm for d-separation
W
S
U
Y
I
A
P
Q
EB
R
KtoVisit = [A]
X
d-reachable = {X}
11
3. Algorithm for d-separation
W
S
U
Y
I
A
P
Q
EB
R
KtoVisit = [S, A]
X
d-reachable = {X}
12
3. Algorithm for d-separation
W
S
U
Y
I
A
P
Q
EB
R
KtoVisit = [I, S, A]
X
d-reachable = {X}
13
3. Algorithm for d-separation
W
S
U
Y
I
A
P
Q
EB
R
KtoVisit = [S, A]
YX
d-reachable = {X}
14
3. Algorithm for d-separation
W
S
U
Y
I
A
P
Q
EB
R
KtoVisit = [S, A]
YX
d-reachable = {X}
15
3. Algorithm for d-separation
W
S
U
I
A
P
Q
B
R
KtoVisit = [A]
Y
E
YX
d-reachable = {X, S}
16
3. Algorithm for d-separation
W
S
U
I
A
P
Q
B
R
KtoVisit = [W, A]
Y
E
YX
d-reachable = {X, S}
17
3. Algorithm for d-separation
W
S
U
I
A
P
Q
B
R
KtoVisit = [B, W, A]
Y
E
YX
d-reachable = {X, S}
18
3. Algorithm for d-separation
W
S
U
I
A
P
Q
B
R
KtoVisit = [U, B, W, A]
Y
E
YX
d-reachable = {X, S}
19
3. Algorithm for d-separation
W
S
U
I
A
P
Q
B
R
KtoVisit = [W, B, A]
E
YYX
d-reachable = {X, S, U}
20
3. Algorithm for d-separation
W
S
U
I
A
P
Q
B
R
KtoVisit = [B, A]
E
YYX
d-reachable = {X, S, U}
21
3. Algorithm for d-separation
W
S
U
I
A
P
Q
B
R
KtoVisit = [B, A]
E
YYX
d-reachable = {X, S, U}
22
3. Algorithm for d-separation
W
S
U
I
A
P
Q
B
R
KtoVisit = [A]
E
YYX
d-reachable = {X, S, U}
23
3. Algorithm for d-separation
W
S
U
I
A
P
Q
B
R
KtoVisit = [R, A]
E
YYX
d-reachable = {X, S, U}
24
3. Algorithm for d-separation
W
S
U
I
A
P
Q
B
R
KtoVisit = [A]
E
YYX
d-reachable = {X, S, U, R}
25
3. Algorithm for d-separation
W
S
U
E
I
A
P
Q
B
R
KtoVisit = []
E
YX
d-reachable = {X, S, U, R, A}
26
3. Algorithm for d-separation
W
S
U
E
I
A
P
Q
B
R
KtoVisit = []
E
YX
d-reachable = {X, S, U, R, A}
27
3. Algorithm for d-separation
W
S
U
E
I
A
P
Q
B
R
KtoVisit = [K]
E
YX
d-reachable = {X, S, U, R, A}
28
3. Algorithm for d-separation
W
S
U
E
I
A
P
Q
B
R
KtoVisit = []
E
YX
d-reachable = {X, S, U, R, A, K}
29
3. Algorithm for d-separation
def get_reachable(X, E):toVisit = [X], visited = {}
while toVisit != []:V = toVisit.pop()
“visit V”
add V to visited
for Y an unvisited neighbor of V:if …. then push Y
Loop’s invariant: Z is in toVisit iff there is an active trail from X to Z
30
3. Algorithm for d-separation
def get_reachable(X, E):toVisit = [X], visited = {}, reachable = {}
while toVisit != []:V = toVisit.pop()
if V is not obs then add V to reachable
add V to visited
for Y an unvisited neighbor of V:if …. then push Y
Loop’s invariant: Z is in toVisit iff there is an active trail from X to Z
31
What neighbors to append?● Let V be the node currently visited and Y be an
unvisited neighbor.● By our invariant, there is an active trail t from X
to V.● What we need to decide if t.append(Y) active...
32
What neighbors to append?● Let V be the node currently visited and Y be an
unvisited neighbor.● By our invariant, there is an active trail t from X
to V.● What we need to decide if t.append(Y) active...
– V - -> Y or V <- - Y?
33
What neighbors to append?● Let V be the node currently visited and Y be an
unvisited neighbor.● By our invariant, there is an active trail t from X
to V.● What we need to decide if t.append(Y) active...
– V - -> Y or V <- - Y?
– Is V or any of its descendants observed?
34
What neighbors to append?● Let V be the node currently visited and Y be an
unvisited neighbor.● By our invariant, there is an active trail t from X
to V.● What we need to decide if t.append(Y) active...
– V - -> Y or V <- - Y?
– Is V or any of its descendants observed?
– W - -> V or W <- - V? (W is V’s predecesor in t)
35
What neighbors to append?● Let V be the node currently visited and Y be an
unvisited neighbor.● By our invariant, there is an active trail t from X
to V.● What we need to decide if t.append(Y) active...
– V - -> Y or V <- - Y?
Easy to check
– Is V or any of its descendants observed?
– W - -> V or W <- - V? (W is V’s predecesor in t)
36
What neighbors to append?● Let V be the node currently visited and Y be an
unvisited neighbor.● By our invariant, there is an active trail t from X
to V.● What we need to decide if t.append(Y) active...
– V - -> Y or V <- - Y?
Easy to check
– Is V or any of its descendants observed?
Compute in advance the ancestors of all observed variables
– W - -> V or W <- - V? (W is V’s predecesor in t)
37
What neighbors to append?● Let V be the node currently visited and Y be an
unvisited neighbor.● By our invariant, there is an active trail t from X
to V.● What we need to decide if t.append(Y) active...
– V - -> Y or V <- - Y?
Easy to check
– Is V or any of its descendants observed?
Compute in advance the ancestors of all observed variables
– W - -> V or W <- - V? (W is V’s predecesor in t)
Keep track how you reached V
38
3. Algorithm for d-separation
def get_reachable(X, E):toVisit = [X], visited = {}, reachable = {}
while toVisit != []:V = toVisit.pop()
if V is not obs then add V to reachable
add V to visited
for Y an unvisited neighbor of V:if …. then push Y
Loop’s invariant: Z is in toVisit iff there is an active trail from X to Z
39
3. Algorithm for d-separation
def get_reachable(X, E):toVisit = [X], visited = {}, reachable = {}
ancestors_E = computeAncestors(E)
while toVisit != []:V = toVisit.pop()
if V is not obs then add V to reachable
add V to visited
for Y an unvisited neighbor of V:if …. then push Y
Loop’s invariant: Z is in toVisit iff there is an active trail from X to Z
40
3. Algorithm for d-separation
def get_reachable(X, E):toVisit = [(<--,X)], visited = {}, reachable = {}
ancestors_E = computeAncestors(E)
while toVisit != []:(dir, V) = toVisit.pop()
if V is not obs then add V to reachable
add V to visited
for Y an unvisited neighbor of V:if …. then push Y
Loop’s invariant: Z is in toVisit iff there is an active trail from X to Z
41
for Y an unvisited neighbor of V:● If dir == <-- :
● If dir == --> :
42
for Y an unvisited neighbor of V:● If dir == <-- :
–
● If dir == --> :– If V --> Y:
●
– If V <-- Y:●
43
for Y an unvisited neighbor of V:● If dir == <-- :
– If V is not observed, then push (dir’, Y)
● If dir == --> :– If V --> Y:
● If V is not observed, then push (-->, Y)
– If V <-- Y:● If V is in ancestors_E, then push (<--, Y)