Select Evidence Variables
Cloudy
Sprinkler
Rainy
Wet Grass

P(C)

+c 0.5
-c 0.5

P(S | C)

+c +s 0.1
-s 0.9
-c +s 0.5
-s 0.5

P(R | C)

+c +r 0.8
-r 0.2
-c +r 0.2
-r 0.8

P(W | S,R)

+s +r +w 0.99
-w 0.01
-r +w 0.9
-w 0.1
-s +r +w 0.9
-w 0.1
-r +w 0.99
-w 0.01

Code Snippet

def likelihood_sampling(graph):

for num sample:

for X in [Cloudy,Sprinkler,Rain,Wet Grass]:

if Xi is an evidence variable:

w = w * P(Xi | Parents(Xi))

else:

sample xi from P(Xi | Parents(Xi))

record (x1,x2,x3,x4),w

Cloudy Sprinkler Rain Wet Grass Count
N(C,S,R,W)
Weight Approximate
P(+c,S,-r,W)
Exact
P(C,S,R,W)
+c +s +r +w 0 0 0 0
+c +s +r -w 0 0 0 0
+c +s -r +w 0 0 0 0
+c +s -r -w 0 0 0 0
+c -s +r +w 0 0 0 0
+c -s +r -w 0 0 0 0
+c -s -r +w 0 0 0 0
+c -s -r -w 0 0 0 0
-c +s +r +w 0 0 0 0
-c +s +r -w 0 0 0 0
-c +s -r +w 0 0 0 0
-c +s -r -w 0 0 0 0
-c -s +r +w 0 0 0 0
-c -s +r -w 0 0 0 0
-c -s -r +w 0 0 0 0
-c -s -r -w 0 0 0 0
Local Variables
Current Sample (?,?,?,?)
Current Node None
Current Weight 1
Number of Samples 0
Cloudy Sprinkler Rain Wet Grass Count
N(C,S,R,W)
Number of Samples Approximate Prob of Sample Exact Prob of Sample Weight Approximate Prob of Joint Exact Prob of Joint
+c +s +r +w 0 0 0 0 0 0 0
+c +s +r -w 0 0 0 0 0 0 0
+c +s -r +w 0 0 0 0 0 0 0
+c +s -r -w 0 0 0 0 0 0 0
+c -s +r +w 0 0 0 0 0 0 0
+c -s +r -w 0 0 0 0 0 0 0
+c -s -r +w 0 0 0 0 0 0 0
+c -s -r -w 0 0 0 0 0 0 0
-c +s +r +w 0 0 0 0 0 0 0
-c +s +r -w 0 0 0 0 0 0 0
-c +s -r +w 0 0 0 0 0 0 0
-c +s -r -w 0 0 0 0 0 0 0
-c -s +r +w 0 0 0 0 0 0 0
-c -s +r -w 0 0 0 0 0 0 0
-c -s -r +w 0 0 0 0 0 0 0
-c -s -r -w 0 0 0 0 0 0 0