∑GATE DA Atlas

Approximate Inference — Sampling

Monte Carlo estimation of posteriors in Bayesian networks — prior (direct) sampling, rejection sampling and its waste when evidence is unlikely, likelihood weighting with sample weights, and Markov chain Monte Carlo with Gibbs sampling over Markov blankets — plus consistency, error rates and when to use which method.

Section 710 practice questions

Why sample?

Exact inference is NP-hard in general. Monte Carlo methods instead generate random samples and estimate probabilities as frequencies. They are consistent — estimates converge to the right answer as the number of samples N→∞N \to \infty — and the error shrinks like 1/N1/\sqrt N, independent of the network size.

Prior (direct) sampling

Sample each variable in topological order from P(Xi∣parents(Xi))P(X_i\mid\text{parents}(X_i)), using the values already chosen for the parents. A complete event (x1,…,xn)(x_1, \dots, x_n) is generated with probability

SPS(x1,…,xn)=∏iP(xi∣parents(Xi))=P(x1,…,xn),S_{PS}(x_1, \dots, x_n) = \prod_i P(x_i\mid\text{parents}(X_i)) = P(x_1, \dots, x_n),

so the fraction of samples matching an event estimates its probability: P^(x)=N(x)/N\hat P(\mathbf x) = N(\mathbf x)/N. Prior sampling answers queries with no evidence.

Cloudy Sprinkler Rain WetGrass sample order: C, S, R, W S, R sampled given CW given S, R
The sprinkler network: sample in topological order.

Rejection sampling

To estimate P(X∣e)P(X\mid\mathbf e): generate prior samples, discard every sample inconsistent with e\mathbf e, and count XX among the rest:

P^(X=x∣e)=N(x,e)N(e).\hat P(X = x\mid\mathbf e) = \frac{N(x, \mathbf e)}{N(\mathbf e)}.

It is consistent, but wasteful: only a fraction P(e)P(\mathbf e) of samples survive, and P(e)P(\mathbf e) drops exponentially with the number of evidence variables.

Likelihood weighting

Avoid rejection by fixing the evidence variables and sampling only the others (in topological order). Each sample carries a weight — the likelihood of the evidence given its sampled parents:

w=∏Ej∈EP(ej∣parents(Ej)).w = \prod_{E_j\in\mathbf E}P(e_j\mid\text{parents}(E_j)).

The estimate is the normalised total weight: P^(x∣e)=α∑samples with X=xw\hat P(x\mid\mathbf e) = \alpha\sum_{\text{samples with } X = x}w.

Likelihood weighting is consistent and uses every sample, but non-evidence variables are sampled ignoring downstream evidence. With evidence near the leaves, most samples are implausible and get tiny weights, so a few samples dominate and accuracy suffers as evidence grows.

Gibbs sampling (MCMC)

Markov chain Monte Carlo makes a random walk through complete states instead of generating each sample from scratch.

  1. Fix the evidence; initialise the other variables arbitrarily.
  2. Repeatedly pick a non-evidence variable XiX_i and resample it from P(Xi∣mb(Xi))P(X_i\mid\text{mb}(X_i)) given the current values of its Markov blanket:
P(xi∣mb(Xi))∝P(xi∣parents(Xi))∏Yj∈children(Xi)P(yj∣parents(Yj)).P(x_i\mid\text{mb}(X_i)) \propto P(x_i\mid\text{parents}(X_i))\prod_{Y_j\in\text{children}(X_i)}P(y_j\mid\text{parents}(Y_j)).
  1. Count how often each value of the query variable occurs (after discarding an initial burn-in).

The states form a Markov chain whose stationary distribution is the posterior P(X∣e)P(\mathbf X\mid\mathbf e), so the long-run fraction of time spent in each state converges to its posterior probability. Successive samples are correlated, and mixing can be slow with near-deterministic CPTs.

Comparison

MethodHandles evidence byWeakness
Prior sampling— (no evidence)cannot condition
Rejection samplingdiscarding inconsistent sampleswastes 1−P(e)1 - P(\mathbf e) of samples
Likelihood weightingfixing evidence, weighting samplesweights degenerate when evidence is downstream
Gibbs samplingfixing evidence, resampling from Markov blanketscorrelated samples, burn-in, slow mixing

Quick revision

Practice questions

GATE-style questions: 5 one-mark and 5 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.

Q1NAT2 marks

Sprinkler network. Cloudy CC is a parent of Sprinkler SS and Rain RR; SS and RR are the parents of WetGrass WW. P(C)=0.5P(C) = 0.5; P(S∣C)=0.1P(S\mid C) = 0.1, P(S∣¬C)=0.5P(S\mid\neg C) = 0.5; P(R∣C)=0.8P(R\mid C) = 0.8, P(R∣¬C)=0.2P(R\mid\neg C) = 0.2; P(W∣S,R)=0.99P(W\mid S,R) = 0.99, P(W∣S,¬R)=0.90P(W\mid S,\neg R) = 0.90, P(W∣¬S,R)=0.90P(W\mid\neg S,R) = 0.90, P(W∣¬S,¬R)=0P(W\mid\neg S,\neg R) = 0.

Prior sampling in topological order generates one complete sample. The probability that it is (C,¬S,R,W)(C, \neg S, R, W) — i.e. CC true, SS false, RR true, WW true — is ______ (round to three decimals).

Q2NAT2 marks

Sprinkler network. Cloudy CC is a parent of Sprinkler SS and Rain RR; SS and RR are the parents of WetGrass WW. P(C)=0.5P(C) = 0.5; P(S∣C)=0.1P(S\mid C) = 0.1, P(S∣¬C)=0.5P(S\mid\neg C) = 0.5; P(R∣C)=0.8P(R\mid C) = 0.8, P(R∣¬C)=0.2P(R\mid\neg C) = 0.2; P(W∣S,R)=0.99P(W\mid S,R) = 0.99, P(W∣S,¬R)=0.90P(W\mid S,\neg R) = 0.90, P(W∣¬S,R)=0.90P(W\mid\neg S,R) = 0.90, P(W∣¬S,¬R)=0P(W\mid\neg S,\neg R) = 0.

Likelihood weighting is used with evidence S=trueS = \text{true}, W=trueW = \text{true}. In one run the sampled non-evidence values are C=trueC = \text{true} and R=trueR = \text{true}. The weight of this sample is ______ (round to three decimals).

Q3NAT1 mark

Rejection sampling generates 1000 samples from the prior. 250 of them agree with the evidence e\mathbf e, and 100 of those 250 have X=trueX = \text{true}. The estimate of P(X=true∣e)P(X = \text{true}\mid\mathbf e) is ______.

Q4NAT1 mark

The evidence has probability P(e)=0.002P(\mathbf e) = 0.002. Out of N=50 000N = 50\,000 prior samples, the expected number that rejection sampling keeps is ______.

Q5NAT2 marks

Likelihood weighting produces five samples. The three with X=trueX = \text{true} have weights 0.3, 0.2 and 0.1; the two with X=falseX = \text{false} have weights 0.2 and 0.2. The estimate of P(X=true∣e)P(X = \text{true}\mid\mathbf e) is ______ (round to two decimals).

Q6MCQ1 mark

In Gibbs sampling for a Bayesian network, each non-evidence variable XiX_i is resampled from

Q7NAT2 marks

Chain A→B→CA \to B \to C with P(B∣A)=0.8P(B\mid A) = 0.8, P(B∣¬A)=0.1P(B\mid\neg A) = 0.1, P(C∣B)=0.6P(C\mid B) = 0.6, P(C∣¬B)=0.2P(C\mid\neg B) = 0.2. During Gibbs sampling the current state has A=trueA = \text{true} and C=trueC = \text{true}. The probability that BB is resampled as true is ______ (round to two decimals).

Q8MSQ2 marks

Which statements about sampling methods are correct?

One or more options are correct.

Q9NAT1 mark

The standard error of a Monte Carlo estimate falls as 1/N1/\sqrt N. To halve the error, the number of samples must be multiplied by ______.

Q10MCQ1 mark

Prior (direct) sampling of a Bayesian network samples the variables