AI Glossary / Generative AI and language / Intermediate

Importance sampling

Definition

Importance sampling is a Monte Carlo technique that estimates quantities under one probability distribution by drawing samples from another and correcting their contributions with weights. The distribution of interest is the target, and the sampling distribution is the proposal. The correction usually involves the target-to-proposal probability or density ratio. A well-chosen proposal can make estimation more efficient, but a poor proposal can produce unstable estimates or fail to cover important cases.

What it means

Sometimes the events that matter to a calculation are rare under ordinary sampling, or direct sampling from the target is difficult. Importance sampling deliberately changes where samples come from. That change must be accounted for: simply oversampling a rare event and treating the resulting frequency as its true probability would be wrong. The method's value comes from combining a useful sampling strategy with the correct mathematical adjustment, not from declaring some examples important by intuition alone.

How it works

To estimate an expectation of f under target p, draw samples x from proposal q and average f(x) times p(x)/q(x). The proposal must give positive probability wherever the target-weighted contribution is nonzero. When only an unnormalized target is available, a self-normalized estimator divides the weighted sum of f by the sum of weights; this ratio is generally biased at finite sample sizes, though it can be consistent under suitable conditions. Inspect weight concentration and uncertainty, because a few enormous weights can dominate the result.

Three practical examples

  • Rare-event simulation: sample important but uncommon scenarios more often and reweight them to estimate a quantity under the original scenario distribution.
  • Probabilistic inference: approximate expectations when a convenient proposal is available and the relevant probability ratios can be calculated.
  • Machine-learning computation: use carefully designed sampling estimators for expensive sums or training quantities, with corrections appropriate to the actual objective.

Think of it this way

Think of surveying a small but important customer group more heavily than its population share. To estimate a population-wide quantity, its survey responses cannot simply be counted as though the sample were proportionate. The analogy explains reweighting, but importance sampling requires a precise probability model and suitable coverage; ordinary survey weighting can involve additional design considerations.

Worked example

Suppose a toy target distribution has two outcomes: ordinary with probability 0.9 and unusual with probability 0.1. Their costs are 1 and 20, so the exact expected cost is 0.9 times 1 plus 0.1 times 20 = 2.9. Choose a proposal that samples each outcome with probability 0.5. The importance weights are 0.9 / 0.5 = 1.8 for ordinary and 0.1 / 0.5 = 0.2 for unusual. The weighted cost contributions are therefore 1.8 and 4.
In an illustrative ten-draw sample containing five of each, the importance-sampling estimate is (5 times 1.8 plus 5 times 4) / 10 = 2.9. The unweighted mean would be (5 times 1 plus 5 times 20) / 10 = 10.5, which estimates the proposal's mean cost rather than the target's. If the sample instead contains six ordinary and four unusual outcomes, the ordinary importance estimate is (10.8 + 16) / 10 = 2.68. Its variation reflects finite sampling. The self-normalized estimate for those same draws is 26.8 / (10.8 + 0.8), approximately 2.31, demonstrating that normalization defines a different estimator at finite sample size. The example uses known normalized probabilities so the distinction can be checked exactly.

Illustrative case study

A fictional simulation team studies service delays that occur infrequently but create substantial workload. It adjusts the simulator's scenario selection to produce more relevant delay cases and records the sampling probabilities. Before using the weighted estimate, it verifies the method on a small scenario table with a known exact answer. It also checks whether a handful of samples carry most of the weight. The team reports the target distribution and estimator explicitly so a reader does not mistake the simulation's oversampled frequency for observed real-world frequency.

Common misconceptions and mistakes

Importance sampling is not the same as selecting examples judged important and averaging them normally. The direction of the probability ratio matters: target divided by proposal is the standard correction in the stated expectation estimator. Missing proposal support cannot be repaired by more samples from that same proposal. A proposal that looks close to the target can still be poor for a particular function or tail behavior. Self-normalized weights do not make every finite-sample estimate unbiased, and a large raw sample count does not guarantee stability.

Business use

Use the method when the target, proposal, and weighting calculation are defensible and the quantity being estimated is clear. Record sampling probabilities and preserve enough information to audit the correction. Compare against exact small cases or ordinary Monte Carlo where possible. Report uncertainty and sensitivity to proposal choices. For business scenarios, separate uncertainty about the assumed target distribution from simulation error; accurate reweighting cannot make an unrealistic target model representative of the real world.

People also ask

Does importance sampling always reduce variance?

No. A poor proposal can increase variance substantially, including cases where it becomes infinite.

Can the proposal ignore unlikely target outcomes?

Only if they make no contribution to the particular expectation; otherwise missing support invalidates the estimator for that quantity.

Are importance weights probabilities?

Not generally. The ratios can exceed one, and only normalized weights in a self-normalized calculation sum to one across the sampled points.

Check your understanding

Why is the unweighted mean 10.5 wrong for the target mean in the example?

Answer: The sample was drawn with equal probabilities for ordinary and unusual outcomes, while the target assigns them probabilities 0.9 and 0.1. Reweighting corrects that deliberate change in sampling distribution.

Related terms

  • Proposal distribution
  • Variance
  • Effective sample size
  • Monte Carlo estimation
  • target distribution
  • likelihood ratio
  • self-normalized estimator
  • support
  • rare-event simulation
  • importance resampling

Learn next

Recalculate the two-outcome example using different sample counts and distinguish the ordinary weighted estimator from the self-normalized ratio. Then construct a proposal that assigns zero probability to a contributing outcome and explain why it fails. Study proposal design and weight diagnostics next, before applying the technique to large or high-dimensional models.

More in Generative AI and language

  • Hierarchical Language Model - A Hierarchical Language Model organizes some aspect of language modeling into multiple levels, such as word classes and words, characters and words, or...
  • Hilbert space - A Hilbert space is a vector space equipped with an inner product and complete in the distance induced by that inner product.
  • Implicit Language Model - An Implicit Language Model is language-pattern knowledge learned within a broader system without being supplied as a separate, explicitly integrated...
  • Inpainting - Inpainting is the process of filling, repairing, or replacing selected regions within an image using surrounding content and, in some systems, additional...
  • Language model - A language model is a model of patterns in language, commonly expressed through probabilities over tokens or token sequences.
  • Latent diffusion - Latent diffusion is a generative modeling approach that performs a diffusion process in a learned latent representation instead of directly in the original...

Sources

Art Owen, Monte Carlo theory, Importance sampling chapter: https://artowen.su.domains/mc/Ch-var-is.pdf Goodfellow, Bengio, and Courville, Deep Learning, Monte Carlo Methods: https://www.deeplearningbook.org/contents/monte_carlo.html

Previous: Implicit surface Next: Importance-weighted evidence lower bound

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer