Search

Search papers and lessons

Sequential Importance Sampling

Level 4 · 10 min read

Sequential importance sampling tracks many weighted guesses of a hidden state over time, extending each one by a step and reweighting it by how well it explains the new observation.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Linear algebra
  • Sampling
  • Discrete math
  • Architectures
  • Sign in to see your progress

TL;DR

A hidden system moves over time, and we see only noisy measurements of it. We want to know where it is now, or where it has been, given everything observed so far. Sequential importance sampling keeps a population of weighted guesses, called particles, each a full history of the hidden state. At every new measurement it extends each particle by one step and multiplies its weight by how well that particle explains the measurement. The weighted population then approximates the answer.

Where you'll see it: in tracking a vehicle from noisy radar, in estimating latent states of a state space model that is not linear or Gaussian, and in sampling from the posterior of a time series.

Intuition

Following many possible histories

Imagine tracking a drone that drifts unpredictably and is observed through a noisy camera. You do not know its path. Instead of computing the exact answer, you release a crowd of imaginary drones, each following its own random path that is consistent with the drift rules. At each frame, the camera reading tells you how plausible each imaginary drone is. Drones that match the reading gain weight. Drones that disagree lose it.

After the last frame, the weighted crowd is your estimate. The drone's probable position is wherever the heavy weights cluster. This is importance sampling, stretched across time: each step builds on the history of its particle, and the weights accumulate.

Why the weights get out of hand

There is a catch. Over many steps, the weights tend to concentrate on a few particles, and the rest become close to zero. After fifty frames, perhaps one particle carries nearly all the weight, and the estimate rests on that single history. Most of the computation is wasted on particles that no longer count.

The standard remedy is resampling: periodically duplicate the heavy particles and discard the light ones, then reset the weights to equal. The method then becomes a loop of propose, weight and resample, which is what gives the family its name, sequential Monte Carlo.

flowchart LR
  A[Particles at time t-1] --> B[Propose a new state for each particle]
  B --> C[Multiply each weight by the likelihood of the new observation]
  C --> D{Effective sample size too small?}
  D -->|yes| E[Resample: duplicate heavy particles, drop light ones]
  D -->|no| F[Keep weights]
  E --> G[Particles at time t]
  F --> G

The math

The model

Let xtx_t be the hidden state at time tt and yty_t the observation. The model has two parts:

  • The transition density f(xt∣xt−1)f(x_t \mid x_{t-1}), which says how the state moves.
  • The observation density g(yt∣xt)g(y_t \mid x_t), which says how the state appears in a measurement.

We want the posterior p(x1:t∣y1:t)p(x_{1:t} \mid y_{1:t}), the probability of the whole state history given all the observations up to tt. The subscript 1:t1:t means the sequence x1,…,xtx_1, \dots, x_t.

The xtx_t are not directly observed. ff and gg are known, which is the setting of a State Space Model. The model may be nonlinear and non-Gaussian, which is exactly where closed-form filters stop working.

The weighted sample

Choose a proposal density q(xt∣x1:t−1,y1:t)q(x_t \mid x_{1:t-1}, y_{1:t}) from which we can draw. Draw NN particles x1:t(i)x_{1:t}^{(i)} and give each a weight that corrects for using qq rather than the true distribution. The incremental weight of particle ii at time tt is

wt(i)∝wt−1(i) f(xt(i)∣xt−1(i)) g(yt∣xt(i))q(xt(i)∣x1:t−1(i),y1:t).w_t^{(i)} \propto w_{t-1}^{(i)} \, \frac{f\big(x_t^{(i)} \mid x_{t-1}^{(i)}\big)\, g\big(y_t \mid x_t^{(i)}\big)}{q\big(x_t^{(i)} \mid x_{1:t-1}^{(i)}, y_{1:t}\big)}.

This is the importance-sampling ratio from Importance Sampling, with a product that runs over time. Each factor is the transition times the observation likelihood, divided by the proposal. The weights are normalised to sum to one at each step, so ∑iwt(i)=1\sum_i w_t^{(i)} = 1.

The estimate of an expectation of a function φ\varphi of the history is

E^[φ(x1:t)∣y1:t]=∑i=1Nwt(i) φ(x1:t(i)).\hat{\mathbb{E}}[\varphi(x_{1:t})\mid y_{1:t}] = \sum_{i=1}^{N} w_t^{(i)} \, \varphi\big(x_{1:t}^{(i)}\big).

The bootstrap choice

The simplest proposal uses the transition itself, q=fq = f. Then the weight update reduces to

wt(i)∝wt−1(i) g(yt∣xt(i)).w_t^{(i)} \propto w_{t-1}^{(i)}\, g\big(y_t \mid x_t^{(i)}\big).

Particles are moved by the dynamics and weighted only by how well they match the new observation. This is the bootstrap filter, introduced by Gordon, Salmond and Smith in 1993. It is easy to implement, but the particles ignore the current measurement when they move, so a good proposal can do much better.

Degeneracy and the effective sample size

The variance of the weighted estimate grows as the weights become uneven. A useful diagnostic is the effective sample size,

Neff=1∑i(wt(i))2,N_{\text{eff}} = \frac{1}{\sum_i \big(w_t^{(i)}\big)^2},

where the weights are normalised to sum to 1. If all weights are equal, Neff=NN_{\text{eff}} = N. If one weight is 1 and the rest are 0, Neff=1N_{\text{eff}} = 1. When NeffN_{\text{eff}} drops below a threshold, such as N/2N/2, resample. Resampling draws NN new particles from the current weighted set and resets all weights to 1/N1/N.

Why resampling keeps the estimate valid

Resampling replaces particles with copies of heavy particles, which changes the population but keeps it a valid approximation of the posterior at time tt. The price is that copies share their past, so the diversity of the history falls. This is why methods use a resampling threshold rather than resampling at every step.

Worked examples

Example
Plain importance sampling on three points

Let the target be a distribution on {0,1,2}\{0, 1, 2\} with probabilities p=(0.2,0.5,0.3)p = (0.2, 0.5, 0.3), and let the function be φ(x)=x\varphi(x) = x. The true expectation is Ep[φ]=0⋅0.2+1⋅0.5+2⋅0.3=1.1\mathbb{E}_p[\varphi] = 0 \cdot 0.2 + 1 \cdot 0.5 + 2 \cdot 0.3 = 1.1.

The proposal is uniform, q=(1/3,1/3,1/3)q = (1/3, 1/3, 1/3). Use one draw of each value, x=0,1,2x = 0, 1, 2, which is a hand-chosen illustration rather than a random run.

  1. Weights w=p/q=(0.6, 1.5, 0.9)w = p / q = (0.6,\ 1.5,\ 0.9).
  2. Weighted estimate 13(0⋅0.6+1⋅1.5+2⋅0.9)=13×3.3=1.1\frac{1}{3}\left(0 \cdot 0.6 + 1 \cdot 1.5 + 2 \cdot 0.9\right) = \frac{1}{3} \times 3.3 = 1.1.
  3. The estimate matches the truth, because the three draws cover the support exactly once each.
  4. Effective sample size with normalised weights w/3=(0.2, 0.5, 0.3)w / 3 = (0.2,\ 0.5,\ 0.3): Neff=1/(0.04+0.25+0.09)=1/0.38≈2.63N_{\text{eff}} = 1 / (0.04 + 0.25 + 0.09) = 1 / 0.38 \approx 2.63.

Interpretation: the weights recover the target from a uniform proposal, and Neff≈2.6N_{\text{eff}} \approx 2.6 out of 3 shows the weights are fairly even. A proposal that put most mass on 0 would give much smaller NeffN_{\text{eff}}.

Example
Two time steps of a hidden two-state chain

The hidden state xt∈{0,1}x_t \in \{0, 1\} starts uniform, P(x1=0)=P(x1=1)=0.5P(x_1 = 0) = P(x_1 = 1) = 0.5. It stays the same with probability 0.8 and switches with probability 0.2. The observation yty_t is 1 with probability 0.9 when xt=1x_t = 1 and with probability 0.2 when xt=0x_t = 0. Both observations are y1=y2=1y_1 = y_2 = 1.

Exact posterior, by enumerating all four histories. Each history has joint weight P(x1) g(y1∣x1) P(x2∣x1) g(y2∣x2)P(x_1)\, g(y_1 \mid x_1)\, P(x_2 \mid x_1)\, g(y_2 \mid x_2):

  1. History (0,0)(0,0): 0.5×0.2×0.8×0.2=0.0160.5 \times 0.2 \times 0.8 \times 0.2 = 0.016.
  2. History (0,1)(0,1): 0.5×0.2×0.2×0.9=0.0180.5 \times 0.2 \times 0.2 \times 0.9 = 0.018.
  3. History (1,0)(1,0): 0.5×0.9×0.2×0.2=0.0180.5 \times 0.9 \times 0.2 \times 0.2 = 0.018.
  4. History (1,1)(1,1): 0.5×0.9×0.8×0.9=0.3240.5 \times 0.9 \times 0.8 \times 0.9 = 0.324.
  5. The total is 0.3760.376, so the exact probability that x2=1x_2 = 1 given the data is 0.342/0.376≈0.9100.342 / 0.376 \approx 0.910.

Now run the sampler with the bootstrap proposal on two particles, chosen by hand to show the weights: particle P is the history (1,1)(1,1) and particle Q is (0,0)(0,0).

  1. Step 1 weights: g(y1∣x1)g(y_1 \mid x_1) gives P 0.90.9 and Q 0.20.2.
  2. Step 2 weights: multiply by g(y2∣x2)g(y_2 \mid x_2), so P becomes 0.810.81 and Q becomes 0.040.04.
  3. Normalise: P has 0.81/0.85≈0.9530.81 / 0.85 \approx 0.953 and Q has 0.0470.047.
  4. The estimate of P(x2=1∣y)P(x_2 = 1 \mid y) is 0.9530.953, against the exact 0.9100.910. The gap here says nothing about the method's accuracy, because the two particles were hand-picked rather than drawn at random.
  5. Effective sample size: Neff=1/(0.9532+0.0472)≈1.10N_{\text{eff}} = 1 / (0.953^2 + 0.047^2) \approx 1.10, close to 1.

Interpretation: with two particles the weights are already lopsided, and the estimate is dominated by one history. With thousands of particles and many more steps, the same collapse happens, which is why resampling is needed. The example uses two particles only to make the numbers checkable.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
The bootstrap proposal ignores the current observationParticles drift away from the observation and most weights are near zeroA proposal that uses yty_t, such as the locally optimal proposal
Resampling never happensDegeneracy: one particle carries all the weightResample when NeffN_{\text{eff}} falls below N/2N/2
Resampling happens at every stepParticles lose their history diversity, so the smoothing estimate of early states gets poorResample on a threshold, and use a smoother for the past
The model is linear and GaussianSampling is wasteful when an exact answer existsUse the Kalman Filter
Too few particles for a long sequenceThe estimate has large variance even with resamplingIncrease NN, and check NeffN_{\text{eff}} over time

The method is consistent as the number of particles grows, but the error for a fixed NN tends to increase with the length of the sequence unless the proposal is good. Sequential methods are most useful when the model is nonlinear, the noise is non-Gaussian and the filter must run in real time.

History

Importance sampling was used as a variance-reduction tool in the early 1950s, long before the sequential version existed. The sequential idea was developed for tracking and signal problems. In 1993, Neil Gordon, David Salmond and Adrian Smith published the bootstrap filter in a paper on nonlinear and non-Gaussian state estimation, adding the resampling step that made the method practical. Pierre Del Moral formalised the general framework in the mid-1990s, and Jun Liu and Rong Chen (1998) helped popularise the name sequential Monte Carlo. Earlier, Rudolf Kalman (1960) had solved the linear-Gaussian version in closed form, which is the case where sampling is unnecessary.

Check yourself

QuestionRecall: what is the role of the proposal qq in sequential importance sampling?Show answer

The proposal is the distribution from which new particle states are drawn. Because draws come from qq and not the true posterior, each particle's weight is multiplied by the ratio of target to proposal, which corrects for the mismatch. A good qq puts draws where the posterior has mass, which keeps the weights even.

QuestionComputation: four particles have unnormalised weights 1, 1, 1 and 1. After one step they become 0.5, 0.5, 0.5 and 2. What is the effective sample size?Show answer

Normalise by the total 3.53.5, giving weights 0.5/3.5=1/70.5/3.5 = 1/7, 1/71/7, 1/71/7 and 2/3.5=4/72/3.5 = 4/7. Then ∑iwi2=3×(1/49)+16/49=19/49\sum_i w_i^2 = 3 \times (1/49) + 16/49 = 19/49, so Neff=49/19≈2.58N_{\text{eff}} = 49 / 19 \approx 2.58. A threshold of N/2=2N/2 = 2 is not triggered, but the weight is already concentrating on one particle.

QuestionWhy: why does resampling duplicate heavy particles, and why does that not bias the posterior estimate?Show answer

Heavy particles are the ones that explain the data well, so they represent more of the posterior. Resampling draws new particles in proportion to their weights, so after resampling each particle is equally weighted and a heavy particle appears several times. The resulting set approximates the same weighted distribution, so the estimate stays valid. The loss is that copies share their history, which reduces diversity.

QuestionApplied: you track a robot's position with a nonlinear range sensor and non-Gaussian wheel slip. Which method fits, and what would you monitor to know it is working?Show answer

A particle filter, which is sequential importance sampling with resampling, fits because the model is nonlinear and non-Gaussian. You would monitor the effective sample size over time and resample when it drops, and check that the estimate is stable when you increase the number of particles. If the effective sample size keeps collapsing, the proposal is poor, and a proposal that uses the latest sensor reading is the usual fix.

Sources