Select Evidence Variables | |||
---|---|---|---|
Cloudy | |||
Sprinkler | |||
Rainy | |||
Wet Grass | |||
K value for Gibbs Sampling |
+c | 0.5 |
-c | 0.5 |
+c | +s | 0.1 |
-s | 0.9 | |
-c | +s | 0.5 |
-s | 0.5 |
+c | +r | 0.8 |
-r | 0.2 | |
-c | +r | 0.2 |
-r | 0.8 |
+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 |
? | +c | ? |
-c | ? |
? | +s | ? |
-s | ? |
? | +r | ? |
-r | ? |
? | +w | ? |
-w | ? |
def gibbs_sampling(graph,N):
for n in range(N):
randomly initialize the sample
for gibbs_iter in range(k):
set Xi to a random non-evidence node
sample Xi from P(Xi | all nodes)
record (x1,x2,x3,x4)
Cloudy | Sprinkler | Rain | Wet Grass | Count N(C,S,R,W) |
Approximate P(S,W|+c,-r) |
Exact P(S,W|+c,-r) |
---|---|---|---|---|---|---|
+c | +s | +r | +w | 0 | 0 | 0 |
+c | +s | +r | -w | 0 | 0 | 0 |
+c | +s | -r | +w | 0 | 0 | 0 |
+c | +s | -r | -w | 0 | 0 | 0 |
+c | -s | +r | +w | 0 | 0 | 0 |
+c | -s | +r | -w | 0 | 0 | 0 |
+c | -s | -r | +w | 0 | 0 | 0 |
+c | -s | -r | -w | 0 | 0 | 0 |
-c | +s | +r | +w | 0 | 0 | 0 |
-c | +s | +r | -w | 0 | 0 | 0 |
-c | +s | -r | +w | 0 | 0 | 0 |
-c | +s | -r | -w | 0 | 0 | 0 |
-c | -s | +r | +w | 0 | 0 | 0 |
-c | -s | +r | -w | 0 | 0 | 0 |
-c | -s | -r | +w | 0 | 0 | 0 |
-c | -s | -r | -w | 0 | 0 | 0 |
Local Variables | |
---|---|
Current Sample | (?,?,?,?) |
Current Node | None |
Current Iteration (gibbs_iter) | 0 |
Sample Number (n) | 0 |
Cloudy | Sprinkler | Rain | Wet Grass | Count N(C,S,R,W) |
Number of Samples | Less Cycles Gibbs Probability (gibbs_iter = 5) |
Approximate Prob of Sample | Exact Prob of Sample |
---|---|---|---|---|---|---|---|---|
+c | +s | +r | +w | 0 | 0 | 0 | 0 | 0 |
+c | +s | +r | -w | 0 | 0 | 0 | 0 | 0 |
+c | +s | -r | +w | 0 | 0 | 0 | 0 | 0 |
+c | +s | -r | -w | 0 | 0 | 0 | 0 | 0 |
+c | -s | +r | +w | 0 | 0 | 0 | 0 | 0 |
+c | -s | +r | -w | 0 | 0 | 0 | 0 | 0 |
+c | -s | -r | +w | 0 | 0 | 0 | 0 | 0 |
+c | -s | -r | -w | 0 | 0 | 0 | 0 | 0 |
-c | +s | +r | +w | 0 | 0 | 0 | 0 | 0 |
-c | +s | +r | -w | 0 | 0 | 0 | 0 | 0 |
-c | +s | -r | +w | 0 | 0 | 0 | 0 | 0 |
-c | +s | -r | -w | 0 | 0 | 0 | 0 | 0 |
-c | -s | +r | +w | 0 | 0 | 0 | 0 | 0 |
-c | -s | +r | -w | 0 | 0 | 0 | 0 | 0 |
-c | -s | -r | +w | 0 | 0 | 0 | 0 | 0 |
-c | -s | -r | -w | 0 | 0 | 0 | 0 | 0 |