liveBook · Manning

Accept/reject algorithm

As explained in Causal AI

An accept/reject algorithm repeatedly samples from a proposal process and retains only outcomes satisfying a specified condition or acceptance rule.

An accept/reject algorithm generates outcomes from a probabilistic process, keeps only those satisfying an acceptance rule, and uses the retained outcomes to represent a target distribution. section 2.2.5

To sample from P(Z | Y = 3):

  • Generate joint outcomes {X, Y, Z} from P(X, Y, Z). section 2.2.5
  • Discard every outcome whose Y value is not 3. section 2.2.5
  • Use the retained Z values as samples from P(Z | Y = 3), or estimate their conditional mean. section 2.2.5

Conditional estimation in Pyro

Generate 1,000 pairs with a Pyro random process, stack the Z values where Y equals 3, and compute their mean. The estimate varies across runs. section 2.2.5

z_given_y = torch.stack([z for z, y in generated_samples if y == 3])
print(z_given_y.mean())

The listing shows the operational filtering step that implements accept/reject sampling. section 2.2.5

How Causal AI covers it

How deep it goes
Explains the sampling and filtering procedure with Pyro code, but only briefly contrasts efficiency and alternative inference algorithms.
Examples
Demonstrates estimating E(Z | Y = 3) by filtering Pyro samples generated from gamma, Poisson, and Bernoulli distributions.
What it assumes
Assumes familiarity with generative sampling and probability notation while illustrating the procedure through a concrete model.
What you can do after
Apply it via Pyro to estimate conditional distributions or expectations from simulated samples.
How it connects
Connects probabilistic inference, generative models, conditional distributions, and Monte Carlo estimation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Causal AI. The section links point to the parts of the book it draws on.