foundations of computational agents
Instead of creating a sample and then rejecting it, it is possible to mix sampling with inference to reason about the probability that a sample would be rejected. In importance sampling methods, each sample has a weight, and the sample average is computed using the weighted average of samples. Likelihood weighting is a form of importance sampling where the variables are sampled in the order defined by a belief network, and evidence is used to update the weights. The weights reflect the probability that a sample would not be rejected.
Consider the belief network of Figure 8.3. In this , and . Suppose is observed, and another descendant of is queried.
Starting with 1000 samples, approximately 10 will have , and the other 990 samples will have . In rejection sampling, of the 990 with , 1%, which is approximately 10, will have and so will not be rejected. The remaining 980 samples will be rejected. Of the 10 with , about 9 will not be rejected. Thus about 98% of the samples are rejected.
Instead of rejecting so many samples, the samples with are weighted by and the samples with are weighted with . This potentially give a much better estimate of any of the probabilities that use these samples.
Figure 8.30 shows the details of the likelihood weighting for computing for query variable and evidence . The loop (from line 15) creates a sample containing a value for all of the variables. Each observed variable changes the weight of the sample by multiplying by the probability of the observed value given the assignment of the parents in the sample. The variables not observed are sampled according the probability of the variable given its parents in the sample. Note that the variables are sampled in an order to ensure that the parents of a variable have been assigned in the sample before the variable is selected.
To extract the distribution of the query variable , the algorithm maintain an array , such that is the sum of the weights of the samples where . This algorithm can also be adapted to the case where the query is some complicated condition on the values; we just have to count the cases where the condition is true and those where the condition is false.
Suppose we want to use likelihood weighting to compute .
The following table gives a few samples. In this table, is the sample; is . The weight is , which is equal to , where the value for and are from the sample.
is estimated from the weighted proportion of the samples that have true.