solutions homework #2 - eth z · pdf file1 solutions homework #2 carlos cotrini october 27,...

84
1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilisc foundaons of arficial intelligence

Upload: hatu

Post on 10-Mar-2018

219 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

1

Solutions homework #2Carlos Cotrini

October 27, 2017

Probabilistic foundations of artificial intelligence

Page 2: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos 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?

Page 3: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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

Page 4: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

4

1. Bayesian Networks: d-separation● Recap on active trails. Case 1. (Mountain)

Observed variable

Hidden variable

Observed orhidden variable

Inactive!

Page 5: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

5

1. Bayesian Networks: d-separation● Recap on active trails. Case 2a. (Downhill)

Inactive!

Page 6: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

6

1. Bayesian Networks: d-separation● Recap on active trails. Case 2b. (Uphill)

Inactive!

Page 7: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

7

1. Bayesian Networks: d-separation● Recap on active trails. Case 3. (Valley)

Inactive!

trail

Page 8: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

8

1. Bayesian Networks: d-separation● Recap on active trails. Case 3.

Inactive!

trail

Page 9: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

9

1. Bayesian Networks: d-separation● Recap on active trails. Case 3.

Inactive!

trail

Page 10: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

10

1. Bayesian Networks: d-separation● Recap on active trails. Case 3.

Inactive!

trail

Page 11: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

11

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

Page 12: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

12

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

A indep. F?

Page 13: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

13

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

A indep. F?

Page 14: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

14

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

A indep. F?

Page 15: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

15

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

A indep. F?

INCONCLUSIVE

Page 16: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

16

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

A indep. G?

Page 17: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

17

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

A indep. G?

Page 18: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

18

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

A indep. G?

Page 19: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

19

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

A indep. G?

YES!

Page 20: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

20

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

B indep. I given F?

Page 21: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

21

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

B indep. I given F?

Page 22: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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

Page 23: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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?

Page 24: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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?

Page 25: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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?

Page 26: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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!

Page 27: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

27

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

I indep. B given H?

Page 28: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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!

Page 29: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

29

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

D indep. J?

Page 30: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

30

1. Bayesian Networks: d-separation● Solutions task 1

A

B

C

D

F

E

G

H

I

J

D indep. J?

INCONCLUSIVE

Page 31: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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?

Page 32: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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

Page 33: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

33

Be careful with the direction of the arrows!

B

A

C

D

B indep from C ?

Page 34: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

34

Be careful with the direction of the arrows!

B

A

C

D

A indep from D ?

Page 35: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

35

2. Variable elimination● Compute

P(J = j)

AB

C

D

F

E

G

H

I

J

Page 36: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

36

2. Variable elimination● Compute

P(J = j)

AB

C

D

F

E

G

H

I

J

Page 37: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

37

2. Variable elimination● Compute

P(J = j)

AB

C

D

F

E

G

H

I

J

Page 38: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

38

2. Variable elimination● Compute

P(J = j)

AB

C

D

F

E

G

H

I

J

Page 39: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

39

2. Variable elimination● Compute

P(J = j)

AB

C

D

F

E

G

H

I

J

Page 40: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

40

2. Variable elimination● Compute

P(J = j)

AB

C

D

F

E

G

H

I

J

Page 41: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

41

2. Variable elimination● Compute

P(J = j)

AB

C

D

F

E

G

H

I

J

Page 42: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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.

Page 43: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

2

3. Algorithm for d-separation

W

S

U

X

I

A

P

Q

EB

R

K

XXXX

Page 44: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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

Page 45: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

4

3. Algorithm for d-separation

W

S

U

X

I

A

P

Q

EB

R

K

XXXX

Page 46: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

5

3. Algorithm for d-separation

W

S

U

X

I

A

P

Q

EB

R

K

XXXX

Page 47: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

6

3. Algorithm for d-separation

Key insight: Subtrails of active trails are also active!

Page 48: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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.

Page 49: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

8

3. Algorithm for d-separation

W

S

U

Y

I

A

P

Q

EB

R

KtoVisit = [X]

X

d-reachable = {}

Page 50: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

9

3. Algorithm for d-separation

W

S

U

Y

I

A

P

Q

EB

R

KtoVisit = []

X

d-reachable = {X}

Page 51: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

10

3. Algorithm for d-separation

W

S

U

Y

I

A

P

Q

EB

R

KtoVisit = [A]

X

d-reachable = {X}

Page 52: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

11

3. Algorithm for d-separation

W

S

U

Y

I

A

P

Q

EB

R

KtoVisit = [S, A]

X

d-reachable = {X}

Page 53: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

12

3. Algorithm for d-separation

W

S

U

Y

I

A

P

Q

EB

R

KtoVisit = [I, S, A]

X

d-reachable = {X}

Page 54: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

13

3. Algorithm for d-separation

W

S

U

Y

I

A

P

Q

EB

R

KtoVisit = [S, A]

YX

d-reachable = {X}

Page 55: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

14

3. Algorithm for d-separation

W

S

U

Y

I

A

P

Q

EB

R

KtoVisit = [S, A]

YX

d-reachable = {X}

Page 56: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

15

3. Algorithm for d-separation

W

S

U

I

A

P

Q

B

R

KtoVisit = [A]

Y

E

YX

d-reachable = {X, S}

Page 57: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 58: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 59: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 60: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 61: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 62: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 63: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

22

3. Algorithm for d-separation

W

S

U

I

A

P

Q

B

R

KtoVisit = [A]

E

YYX

d-reachable = {X, S, U}

Page 64: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 65: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 66: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 67: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 68: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 69: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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}

Page 70: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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

Page 71: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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

Page 72: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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...

Page 73: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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?

Page 74: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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?

Page 75: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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)

Page 76: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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)

Page 77: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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)

Page 78: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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

Page 79: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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

Page 80: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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

Page 81: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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

Page 82: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

41

for Y an unvisited neighbor of V:● If dir == <-- :

● If dir == --> :

Page 83: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

42

for Y an unvisited neighbor of V:● If dir == <-- :

● If dir == --> :– If V --> Y:

– If V <-- Y:●

Page 84: Solutions homework #2 - ETH Z · PDF file1 Solutions homework #2 Carlos Cotrini October 27, 2017 Probabilistic foundations of artificial intelligence

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)