Importance Sampling
Importance sampling is a powerful and pervasive technique in statistics, machine learning, and randomized algorithms.
Basics
Importance sampling is a technique for estimating the expectation of a random variable under distribution from samples of a different distribution
The key observation is that can be expressed as the expectation of a different random variable under
Technical condition: must have support everywhere does, Without this condition, the equation is biased! Note: can support things that doesn't.
Terminology: The quantity is often referred to as the importance weight or importance correction. We often refer to as the target density and as the proposal density.
Now, given samples from we can use the Monte Carlo estimate, as an unbiased estimator of
Remarks
There are a few reasons we might want to use importance sampling:
- Convenience: It might be trickier to sample directly from
- Bias-correction: Suppose we're developing an algorithm that requires samples to satisfy some safety condition (e.g., a minimum support threshold) and be unbiased. Importance sampling can be used to remove bias while satisfying the condition.
- Variance reduction: It might be the case that sampling directly from would require more samples to estimate Check out these great notes for more.
- Off-policy evaluation and learning: We might want to collect some exploratory data from and evaluate different policies (e.g., to pick the best one). Here's a link to a future post on off-policy evaluation and counterfactual reasoning and some cool papers: counterfactual reasoning, reinforcement learning, contextual bandits, domain adaptation.
There are a few common cases for worth separate consideration:
- Control over : This is the case in experimental design, variance reduction, active learning, and reinforcement learning. It's often difficult to design which results in an estimator with reasonable variance. A very difficult case is in off-policy evaluation because it (essentially) requires a good exploratory distribution for every possible policy. (I have much more to say on this topic.)
- Little to no control over : For example, you're given some dataset (e.g., new articles), and you want to estimate performance on a different dataset (e.g., Twitter).
- Unknown : In this case, we want to estimate (typically referred to as the propensity score) and use it in the importance sampling estimator. As far as I can tell, this technique is widely used to remove selection bias when estimating the effects of different treatments.
Drawbacks: The main drawback of importance sampling is variance. A few bad samples with large weights can drastically throw off the estimator. Thus, it's often the case that a biased estimator is preferred, e.g., estimating the partition function, clipping weights, indirect importance sampling. A secondary drawback is that both densities must be normalized, which is often intractable.
What's next? I plan to cover variance reduction and off-policy evaluation in more detail in future posts.