# 8.6.2 Forward Sampling in Belief Networks

Forward sampling is a way to generate a sample of every variable in a belief network so that each sample is generated in proportion to its probability. This enables us to estimate the prior probability of any variable.

Suppose $X_{1},\dots,X_{n}$ is a total ordering of the variables so that the parents of each variable come before the variable in the total order. Forward sampling draws a sample of all of the variables by drawing a sample of each variable $X_{1},\dots,X_{n}$ in order. First, it samples $X_{1}$ using the cumulative distribution, as described above. For each of the other variables, due to the total ordering of variables, when it comes time to sample $X_{i}$, it already has values for all of $X_{i}$’s parents. It now samples a value for $X_{i}$ from the distribution of $X_{i}$ given the values already assigned to the parents of $X_{i}$. Repeating this for every variable generates a sample containing values for all of the variables. The probability distribution of a query variable is estimated by considering the proportion of the samples that have assigned each value of the variable.

###### Example 8.40.

To create a set of samples for the belief network of Figure 8.3, suppose the variables are ordered: $Tampering$, $Fire$, $Alarm$, $Smoke$, $Leaving$, $Report$.

First the algorithm samples $Tampering$, using the cumulative distribution. Suppose it selects $Tampering{=}false$. Then it samples $Fire$ using the same method. Suppose it selects $Fire{=}true$. Then it samples a value for $Alarm$, using the distribution $P(Alarm\mid Tampering{=}false,Fire{=}true)$. Suppose it selects $Alarm{=}true$. Next, it samples a value for $Smoke$ using $P(Smoke\mid Fire{=}true)$. And so on for the other variables. It has thus selected a value for each variable and created the first sample of Figure 8.28. Notice that it has selected a very unlikely combination of values. This does not happen very often; it happens in proportion to how likely the sample is. It repeats this until it has enough samples. In Figure 8.28, it generated 1000 samples.

The probability that $Report{=}true$ is estimated from the proportion of the samples where the variable $Report$ has value $true$.