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
