Bayesian Networks
So, consider a Bayesian network with Bernoulli random variables. This is all the information that was given. What else do you need?
Consider a BN network with Bernoulli random variables (i.e., binary random variables taking values in {0,1}), and the following structure and corresponding CPTs.
P(x=1) = 0.8
P(x=0) = 0.7
P(x=1 | x1=0, x2=0) = 0.3
P(x=1 | x1=0, x2=1) = 0.6
P(x=1 | x1=1, x2=0) = 0.8
P(x=0 | x1=0, x2=0) = 0.2
P(x=0 | x1=0, x2=1) = 0.7
P(x=0 | x1=1, x2=0) = 0.3
P(x=0 | x1=1, x2=1) = 0.6
P(x=1 | x1=1, x2=1) = 0.8
Let us now consider likelihood-weighting sampling, as implemented by function LIKELIHOOD-WEIGHTING in Figure 14.15, to estimate the same query P(x1=1).
Function LIKELIHOOD-WEIGHTING(bn) returns an estimate of P(x1 | x), where:
- x is the query variable
- e is observed values for variables
- bn is a Bayesian network specifying joint distribution P(x)
N is the total number of samples to be generated
W is a vector of weighted counts for each value of x, initially zero
For j=1 to N do:
- x <- WEIGHTED-SAMPLE(bn)
- W[x] <- W[x] + w
Where r is the value of x in x' and NORMALIZE(W) is a function that normalizes the weights.
Function WEIGHTED-SAMPLE(bn) returns an event with elements initialized from e:
- For each variable x in x1, x2, ..., xn do:
- If x is an evidence variable with value z, then:
- P(x | parents(x)) <- P(x | parents(x))
- Else:
- x <- a random sample from P(x | parents(x))
Figure 14.15: The likelihood-weighting algorithm for inference in Bayesian network. In WEIGHTED-SAMPLE, each non-evidence variable is sampled according to the conditional distribution given the values already sampled for the variable's parents, while a weight is accumulated based on the likelihood for each evidence variable.
Let us now consider likelihood-weighting sampling, as implemented by function LIKELIHOOD-WEIGHTING in Figure 14.15, to estimate the same query P(x1 | x=1).
1. Assume that you have access to a random number generator which would output a random number r, i.e., drawn uniformly at random from [0,1], from the sequence:
r=0.92, r=0.77, r=0.11, r=0.32, r=0.85
With exactly one random number output per call, and in that order. Provide the output of a call to WEIGHTED-SAMPLE, implemented in Figure 14.15, to obtain a weighted sample from the prior specified by the given BN as input. (Assume that the sampling order breaks ties using the sub-index, with lower values preferred.)