Approximate inference by sampling
Sampling replaces a full sum by repeated draws and weighted counts. The target is still the exact posterior, but a finite sample gives an approximation. Distinguish independent ancestral draws from correlated Gibbs draws, and evidence rejection from evidence weighting.
6.1 Ancestral sampling
Visit BN variables in a topological order. Sample each root from its prior, then each other variable from its CPT conditioned on the sampled parent values. Repeat using fresh randomness. The resulting complete assignment is distributed according to the BN joint, because its generation probability is the product of the CPT entries.
To sample a categorical row, partition into intervals of the row probabilities and select the interval containing a uniform draw. Do not sample a child before its parents or use a marginal in place of its parent-conditioned CPT.
6.2 Rejection sampling
Generate ancestral samples and retain only those matching all evidence. A sample can be rejected as soon as it conflicts with an evidence variable. Early rejection saves work but does not increase the probability of acceptance.
For independent attempts with , the mean attempts needed for accepted samples is . This is an expectation, not a guaranteed budget.
6.3 Likelihood weighting
Fix evidence variables at their observed values. Sample only non-evidence variables in topological order. Whenever an evidence node is reached, multiply the sample weight by the probability of its observed value given its current parents. A fixed evidence variable is not sampled from its CPT.
Evidence at a descendant does not directly alter how its ancestors are sampled. If only a few ancestral assignments make the evidence likely, nearly all weight can concentrate on a few samples. Avoid calling likelihood weighting “exact” merely because it never rejects evidence.
6.4 Gibbs sampling
Fix the evidence, initialise the remaining variables in a possible state, and repeatedly resample one non-evidence variable conditional on all current other values. Use a fixed sweep or a suitable random scan. Other variables keep their current values; an updated value is used by subsequent updates.
The posterior is a stationary distribution of each valid Gibbs update. Convergence from an arbitrary initial state also needs an ergodic chain on the posterior support; strict positivity in a finite model is a convenient sufficient condition. Deterministic constraints can split the support and trap single-variable updates. Adjacent samples are correlated. Burn-in reduces initialisation influence but no fixed burn-in length guarantees convergence in every model.
After burn-in, estimate a query probability by the fraction of retained chain states satisfying that query. Count either after each update or after each full sweep, using a consistent convention. Ergodicity makes this frequency consistent; the independent-sample variance formula does not apply directly.
6.5 Sampling precision and method choice
Independent-draw standard error scales as ; reducing it by a factor of two needs four times as many draws. Use estimated in place of unknown for a rough standard-error estimate. Near zero or one, this plug-in estimate can be misleading with few samples; zero observed successes does not establish zero probability.
| Method | Evidence handling | Exact at finite work? | Main bottleneck |
|---|---|---|---|
| Enumeration | Restrict rows; sum hidden assignments | Yes, up to arithmetic | Full assignment count |
| Variable elimination | Restrict factors; sum in chosen order | Yes, up to arithmetic | Largest intermediate scope |
| Prior sampling | No conditioning unless counts are filtered | No | Rare query/evidence events |
| Rejection sampling | Discard inconsistent samples | No | Small |
| Likelihood weighting | Fix evidence; multiply likelihood weights | No | Weight concentration |
| Gibbs sampling | Fix evidence; local conditional updates | No | Correlation, mixing and disconnected support |
Last-minute recall
- Ancestral samples follow the joint distribution when parents are sampled first.
- Rejection divides by evidence matches, not all attempted draws.
- Rare evidence makes rejection inefficient.
- Likelihood weighting fixes evidence and weights by its CPT terms.
- Do not multiply a sampled prior into a likelihood weight again.
- Gibbs resamples from a full conditional using the Markov blanket.
- Child likelihoods belong in the Gibbs update.
- Gibbs samples are correlated and deterministic constraints can prevent mixing.
- Variable elimination is exact; finite sampling estimates are approximate.
- More samples reduce random error, but do not repair an incorrect sampling rule.