Target and proposal
Suppose you want the expectation of a function under a density : With samples drawn from , the average of estimates this integral. Often there is no direct way to sample from , for example when is the posterior belief of a Bayes filter. Importance sampling draws the samples from another density , the proposal distribution. is the target distribution. must be positive wherever is positive, so that every value can produce can also be drawn from . Multiplying and dividing by gives The ratio is the importance weight. With samples , the estimate is Where , the proposal undersamples and the weight is above 1. Where , the weight is below 1. The example target has two modes, like a localization belief when two places match the robot’s observations: The proposal is a single wide Gaussian, . The mean of the target is .Self-normalized weights
In filtering, the target is known only up to a constant. Bayes’ rule gives the posterior as , and the normalizer is an integral over the state space that the filter does not compute. Write the target as , where can be evaluated and is unknown. Compute the weights from and divide by their sum: cancels between numerator and denominator. This self-normalized estimate is slightly biased for finite , and the bias vanishes as grows. Its error typically shrinks as , with a constant that depends on how similar is to (Thrun, Burgard and Fox, 2005, Section 4.2.2). The code below scales the target by an arbitrary factor, as if were unknown, and repeats the estimate 500 times for each sample size.Choosing the proposal
When is close to , the weights are nearly equal and every sample contributes. When puts little mass where is large, the few samples that land there get very large weights, and the estimate depends mostly on them. The effective sample size, computed with normalized weights, measures this. It equals when all weights are equal and 1 when a single sample holds all the weight. The code compares three proposals with samples each: the wide Gaussian used so far, a narrower Gaussian centered between the modes, and a Gaussian that covers only the right mode.Resampling
Some algorithms need an unweighted sample set, for example to pass the samples through another sampling step. Resampling produces one from the weighted set. Draw samples with replacement from the weighted set, each with probability equal to its normalized weight. Samples with large weights are copied several times and samples with small weights tend to disappear. The new set is approximately distributed according to , and every sample in it has the same weight.Importance ratios in policy optimization
PPO collects actions with an old policy and updates a new policy . The ratio in its objective is the importance weight that corrects for the samples coming from the old policy, and the clipping limits how large that weight can get.References
- Thrun, S., Burgard, W., and Fox, D. (2005). Probabilistic Robotics. MIT Press.
Found an error on this page? Report an issue.

