Chapter 6

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 [0,1)[0,1) 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 P(e)>0P(e)>0, the mean attempts needed for kk accepted samples is k/P(e)k/P(e). 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 M−1/2M^{-1/2}; reducing it by a factor of two needs four times as many draws. Use estimated p^\widehat p in place of unknown pp 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.

MethodEvidence handlingExact at finite work?Main bottleneck
EnumerationRestrict rows; sum hidden assignmentsYes, up to arithmeticFull assignment count
Variable eliminationRestrict factors; sum in chosen orderYes, up to arithmeticLargest intermediate scope
Prior samplingNo conditioning unless counts are filteredNoRare query/evidence events
Rejection samplingDiscard inconsistent samplesNoSmall P(e)P(e)
Likelihood weightingFix evidence; multiply likelihood weightsNoWeight concentration
Gibbs samplingFix evidence; local conditional updatesNoCorrelation, 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.

Revise offline: the whole Artificial Intelligence handbook as one PDF

37 pages · 1.8 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections