liveBook · Manning

Importance sampling

Importance sampling is a statistical technique that estimates expectations under a target distribution by reweighting samples drawn from another distribution.

How 3 Manning books explain it

Reinforcement Learning from Human Feedback

Importance sampling is a method for estimating an expectation under one probability distribution using samples drawn from another distribution and probability weights.

How it is used
Corrects distribution mismatch so policy gradients can reuse rollouts from older policies or separate sampling systems.
How deep it goes
Derives the expectation identity and policy ratios, then compares clipping, sequence-level ratios, and truncated weights with implementation details.
Examples
Uses old-policy rollout reuse, rare reasoning tokens, sequence-level GSPO ratios, and learner-versus-sampler TIS code.
What you can do after
Apply it via PPO, GSPO, or TIS ratios to correct rollout and sampler-learner distribution mismatches.

Read how Reinforcement Learning from Human Feedback explains importance sampling →

Machine Learning Algorithms in Depth

Importance sampling is a Monte Carlo technique that estimates expectations or integrals under a target distribution by weighting samples drawn from a proposal distribution.

How it is used
Estimates target-distribution expectations and integrals by sampling an easier proposal distribution.
How deep it goes
Derives weighted Monte Carlo estimation and implements sampling, filtering, density evaluation, and averaging, while deferring further normalization details.
Examples
Uses a sinusoidal integrand, an unnormalized chi target, a scaled Gaussian proposal, positive filtering, and numerical ground truth.
What you can do after
Build it from scratch by coding a proposal sampler, importance weights, filtered samples, and a weighted Monte Carlo estimate.

Read how Machine Learning Algorithms in Depth explains importance sampling →

Causal AI

Importance sampling estimates expectations under a target distribution using samples from another distribution and likelihood-based weights.

How it is used
Supports probabilistic inference when conditioning would discard many generated samples.
How deep it goes
Demonstrates weighted Monte Carlo inference and a Pyro workflow, but defers broader inference algorithms and causal applications.
Examples
Uses a Pyro transportation model to estimate education probabilities for train riders.
What you can do after
Apply it via Pyro to condition a model, sample an empirical marginal, and estimate target probabilities.

Read how Causal AI explains importance sampling →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.