Search

Search papers and lessons

Trajectory Prediction

Level 3 · 12 min read

Trajectory prediction forecasts where moving agents such as cars and pedestrians will be next, and good models answer with a set of possible futures, each with a probability.

On this page

  • Colour = topic mix
  • Probability
  • Linear algebra
  • Calculus
  • Discrete math
  • Neural network basics
  • Losses & regularization
  • ReadReady to readNot yet

TL;DR

Trajectory prediction estimates where a moving agent, such as a car, a cyclist or a pedestrian, will be over the next few seconds, using its recent positions and the scene around it. Because an agent can go straight, turn or stop, good models do not return a single path. They return several possible futures, each with a probability, so that a planner can prepare for the likely ones.

Builds on: Time Series Forecasting, Recurrent Neural Network, Mixture Density Network · Leads to: VectorNet: Encoding HD Maps and Agent Dynamics from Vectorized Representation

Where it's used

Self-driving cars. A planner has to know what nearby vehicles and pedestrians will do in the next few seconds before it picks its own path. The Argoverse motion forecasting benchmark, released in 2019 by Argo AI with university partners, gives each model two seconds of past positions sampled ten times per second and asks for the next three seconds, for many agents in each city scene.

Crowds. Stations, malls and sidewalks are full of people who avoid each other. The ETH and UCY benchmarks hold pedestrian tracks from five outdoor and indoor scenes. The standard protocol gives a model 3.2 seconds of history and asks it to predict 4.8 seconds ahead. Crowd models must learn that a pedestrian ahead will step aside, not only that the pedestrian keeps walking.

Robots that share space. A warehouse robot in an aisle with people, or a drone avoiding a moving object, uses the same forecasts to slow down before a conflict forms rather than after it. The forecast is only useful if it arrives early enough for the robot to change course.

How it works

Follow one agent that moves to the right. Positions are in metres and time steps are one second apart.

  1. Input. The model sees three past positions: at time 1 the agent is at (0, 0), at time 2 at (1, 0), at time 3 at (2, 0). Check: each step moves the agent by (1, 0), so its speed is 1 metre per second and it has not turned.
  2. Encode the history. A recurrent network reads the positions one at a time and keeps a hidden state that is updated at each step. After reading the third position the hidden state summarises "moving right at about 1 metre per second, no turn yet". Check: if the agent had stopped, the same network would store a different summary, which is why the state must depend on the whole history.
  3. Decode the future as a mixture. From the hidden state, the model outputs a small set of components. Each component has a weight, a mean position and a spread. For the next position (time 4) the model says: with weight 0.8 the agent continues straight, centred at (3, 0); with weight 0.2 it turns up, centred at (3, 1). Check: the two weights sum to 1, so they are probabilities.
  4. Score the outcome. Training asks how likely the true next position was under the mixture. If the agent really went to (3, 0), the straight component gives that point most of the probability, so the loss is small. If it went to (3, 1), the turn component gives it some probability, so the loss is larger but not infinite.
  5. Roll it out. For a forecast, the model repeats steps 2 to 4 for every future step, or outputs all future steps at once. The result is a bundle of plausible paths rather than one line, and each path can be given to the planner with its probability.
flowchart LR
  A[Past positions] --> B[Recurrent encoder]
  B --> C[Decoder outputs weights, means, spreads]
  C --> D[Mixture of Gaussians over each future step]
  D --> E[Sample or rank several futures]

The plot below is a one-dimensional version of a two-component mixture, with its own numbers rather than the ones from the walkthrough. The two dashed bumps are the components, and the solid curve is their weighted sum. The next position is most likely near 0 but still has a chance near 4.

−2024600.10.20.30.40.5next position along xdensity
  • 0.6 component at 0
  • 0.4 component at 4
  • mixture
A two-component mixture: most of the mass sits at the straight-ahead mode, but the turn mode keeps a real chance.

The math

Definition: Mixture density forecast

Given past positions x1,…,xTx_1, \dots, x_T in R2\mathbb{R}^2, a mixture density forecast is a probability density over the future positions yT+1,…,yT+Fy_{T+1}, \dots, y_{T+F} of the form p(ys∣x1,…,xT)=∑k=1Kπk N(ys;μk,Σk)p(y_s \mid x_1, \dots, x_T) = \sum_{k=1}^{K} \pi_k \, \mathcal{N}(y_s; \mu_k, \Sigma_k), a weighted sum of Gaussians. Here πk≥0\pi_k \geq 0 are weights that sum to 1, each μk\mu_k is a mean position, and each Σk\Sigma_k is a covariance matrix. The index ss runs over future steps and KK is the number of modes.

Step 1 in symbols: the history

Write the position at time tt as xt=(ptx,pty)x_t = (p_t^{x}, p_t^{y}) and the velocity as vt=xt−xt−1v_t = x_t - x_{t-1}. In the example, x1=(0,0)x_1 = (0, 0), x2=(1,0)x_2 = (1, 0) and x3=(2,0)x_3 = (2, 0), so v3=(1,0)v_3 = (1, 0).

Step 2 in symbols: the hidden state

A simple recurrent encoder computes ht=tanh⁡(Wxt+Uht−1+b)h_t = \tanh(W x_t + U h_{t-1} + b) for each tt, with learned matrices WW, UU and a bias bb. The final state hTh_T is the summary that the decoder reads. (See Recurrent Neural Network and Long Short-Term Memory for gated versions.)

Step 3 in symbols: the mixture weights

The decoder produces raw scores zkz_k for each component and turns them into weights with the Softmax, πk=exp⁡(zk)/∑jexp⁡(zj)\pi_k = \exp(z_k) / \sum_{j} \exp(z_j), so that the weights are positive and sum to 1. The example uses π=(0.8,0.2)\pi = (0.8, 0.2) for the straight and turn modes.

Step 4 in symbols: the training loss

Training minimises the negative log-likelihood of the observed future, L=−∑slog⁡∑k=1Kπk N(ys;μk,Σk)\mathcal{L} = -\sum_{s} \log \sum_{k=1}^{K} \pi_k \, \mathcal{N}(y_s; \mu_k, \Sigma_k). Maximising the likelihood of the data is the principle behind Maximum Likelihood Estimation.

Step 5 in symbols: the error measures

Let y^s\hat{y}_s be the forecast for step ss and ysy_s the truth, with FF future steps. The average displacement error is ADE=1F∑s=1F∥y^s−ys∥2\mathrm{ADE} = \frac{1}{F} \sum_{s=1}^{F} \lVert \hat{y}_s - y_s \rVert_2, and the final displacement error is FDE=∥y^F−yF∥2\mathrm{FDE} = \lVert \hat{y}_F - y_F \rVert_2. When a model returns KK sampled futures, minADE keeps the best of the KK at each example, which rewards a model for putting one good guess among its samples.

Worked examples

Example
1. Tiny: a constant-velocity baseline

Observed positions are x1=(0,0)x_1 = (0, 0), x2=(1,0)x_2 = (1, 0), x3=(2,0)x_3 = (2, 0). The true future is y4=(3,0)y_4 = (3, 0) and y5=(4,1)y_5 = (4, 1).

  1. Velocity: v=x3−x2=(1,0)v = x_3 - x_2 = (1, 0).
  2. Forecast for time 4: y^4=x3+v=(3,0)\hat{y}_4 = x_3 + v = (3, 0).
  3. Forecast for time 5: y^5=x3+2v=(4,0)\hat{y}_5 = x_3 + 2v = (4, 0).
  4. Error at time 4: ∥(3,0)−(3,0)∥=0\lVert (3, 0) - (3, 0) \rVert = 0.
  5. Error at time 5: ∥(4,0)−(4,1)∥=1\lVert (4, 0) - (4, 1) \rVert = 1.
  6. ADE =(0+1)/2=0.5= (0 + 1) / 2 = 0.5. FDE =1= 1.

Interpretation: a baseline that assumes no turning is right until the agent turns, and its error appears at the far end of the forecast, which is why FDE is reported next to ADE.

Example
2. Standard: evaluating a mixture at two points

Use a one-dimensional mixture with π=(0.6,0.4)\pi = (0.6, 0.4), means μ=(0,4)\mu = (0, 4) and spreads σ=(1,1)\sigma = (1, 1). Let φ(z)=e−z2/2/2π\varphi(z) = e^{-z^2/2} / \sqrt{2\pi}, so φ(0)=0.3989\varphi(0) = 0.3989 and φ(4)=0.000134\varphi(4) = 0.000134.

  1. Density at y=0y = 0: 0.6⋅φ(0)+0.4⋅φ(4)=0.2394+0.0001≈0.23940.6 \cdot \varphi(0) + 0.4 \cdot \varphi(4) = 0.2394 + 0.0001 \approx 0.2394.
  2. Negative log-likelihood at y=0y = 0: −ln⁡(0.2394)≈1.43-\ln(0.2394) \approx 1.43.
  3. Density at y=4y = 4: 0.6⋅φ(4)+0.4⋅φ(0)=0.0001+0.1596≈0.15970.6 \cdot \varphi(4) + 0.4 \cdot \varphi(0) = 0.0001 + 0.1596 \approx 0.1597.
  4. Negative log-likelihood at y=4y = 4: −ln⁡(0.1597)≈1.83-\ln(0.1597) \approx 1.83.

Interpretation: the outcome near the likely mode costs less. The turn outcome at 4 is not ruled out; it costs more, but the loss stays finite, which is what lets a mixture learn that both outcomes happen.

Example
3. Realistic: a car approaching a driveway

A car moves at 12 metres per second and the forecast horizon is 3 seconds. The straight mode puts the car at (36, 0) metres ahead of its present position with weight 0.7. The turn mode puts it at (30, 8), into a driveway on the left, with weight 0.3. The car turns.

  1. Distance covered at constant speed: 12×3=3612 \times 3 = 36 metres, the straight endpoint.
  2. Single straight forecast, endpoint error: ∥(36,0)−(30,8)∥=36+64=10\lVert (36, 0) - (30, 8) \rVert = \sqrt{36 + 64} = 10 metres, so FDE =10= 10.
  3. Two-mode forecast, the turn mode is one of the guesses and matches the truth exactly, so minFDE =min⁡(10,0)=0= \min(10, 0) = 0.
  4. Interpretation: the single-mode forecast fails by 10 metres at the moment the planner most needs the answer. Keeping the turn mode, even at weight 0.3, lets the planner brake for the driveway.
  5. Try it: a pedestrian walks at 1.4 metres per second and the horizon is 4 seconds. How far from the current position is the constant-velocity forecast at the end of the horizon? Answer: 1.4×4=5.61.4 \times 4 = 5.6 metres.

Common mistakes and tradeoffs

It is tempting to think that a forecast should be one best path. In fact the future of an agent is multimodal, because a driver can turn or not turn, and a single averaged path lands between the modes where no agent goes. A single mean, trained with squared error, lands between the modes, because the average of the two outcomes is the answer that minimises squared error.

It is tempting to think that a lower average error means a better model. In fact ADE can hide a model that misses the rare turn, which is the case a planner must not miss. Report minADE or minFDE over a set of guesses together with the miss rate, not only the mean error.

It is tempting to think that a learned model always beats physics. In fact, over a short horizon, a constant-velocity or constant-acceleration model with a Kalman filter is hard to beat and costs almost nothing. Learned models pay off when the horizon is longer and the agents react to each other or to the road.

It is tempting to think that more input is always better. In fact anything recorded after the prediction time, such as the agent's full future route, leaks the answer into the input. Results look excellent and then fall apart in deployment, because the information is not available when the car needs it.

When to use it. Several agents interact, the horizon is seconds long, and what an agent intends matters, as on roads, in crowds and around robots.

When not to use it. Single agents on short horizons, or when a physics model is already accurate enough.

OptionStrengthWeakness
Constant velocity with a Kalman filterCheap, strong for short horizonsCannot represent turns or interaction
Recurrent encoder with a mixture headMultimodal, simple to trainSees only the agent, unless extended
Transformer with scene contextUses maps and neighbours togetherNeeds more data and compute

History

Before learned models, tracking systems predicted motion with linear filters. Rudolf Kalman's 1960 paper on linear filtering and prediction gave the standard constant-velocity tool that many systems still use as a baseline.

Neural networks with a probabilistic output head came from Christopher Bishop's 1994 work on mixture density networks, which made a network output the parameters of a mixture. Alex Graves used the same idea in 2013 to generate handwriting from a recurrent network, which showed that a mixture head could model smooth sequences with sudden changes.

Social LSTM (Alahi et al., 2016) brought the idea to crowds. Each pedestrian had its own recurrent network, and a pooling step shared the hidden states of nearby pedestrians, so that one person's plan could depend on the people around them. Benchmarks such as ETH and UCY and later Argoverse made the comparison of methods concrete, and models that encode maps and neighbours together became the common approach for driving.

Recap

  • The goal is a distribution over future positions, not one path.
  • A recurrent encoder turns the observed history into a hidden state that summarises it.
  • A mixture of Gaussians head turns that state into weights, means and spreads for each future step.
  • Training uses the negative log-likelihood of the true future; evaluation uses ADE, FDE and minADE over several guesses.
  • Read next: VectorNet: Encoding HD Maps and Agent Dynamics from Vectorized Representation, which encodes the map and the agents as vectors, and Attention Mechanism for how modern models let agents attend to one another.

Check yourself

QuestionRecall: what do ADE and FDE each measure, and which one emphasises the far end of the forecast?Show answer

ADE is the average Euclidean distance between forecast and truth over all future steps. FDE is the distance at the last step only. FDE emphasises the far end of the forecast because it ignores the earlier steps, where errors are usually small.

QuestionAn agent is last seen at (5, 5) metres and moves (2, 1) metres per step. Using constant velocity, where is the forecast three steps later?Show answer

Constant velocity adds three copies of the velocity to the last position: (5,5)+3⋅(2,1)=(5+6,5+3)=(11,8)(5, 5) + 3 \cdot (2, 1) = (5 + 6, 5 + 3) = (11, 8). The forecast is at (11, 8) metres.

QuestionWhy does a mixture of Gaussians fit trajectories better than a single Gaussian?Show answer

A single Gaussian has one peak, so it places its mass between two distinct outcomes, such as going straight and turning, where neither outcome happens. A mixture can put separate peaks on each outcome and give each a weight, so the likely futures are represented without averaging them into an impossible middle.

QuestionA forecaster gives straight weight 0.9 and turn weight 0.1. The car turns. Is the forecast useless for planning?Show answer

Not necessarily. The forecast assigned a real probability to the turn, so the planner can keep a turn candidate in its plan and react early when the car starts to turn. The forecast is poorly calibrated if the car turns often, which is a reason to check calibration on data, not a reason to discard the mixture.

Sources

  • Alahi et al., "Social LSTM: Human Trajectory Prediction in Crowded Spaces", CVPR 2016.
  • Graves, "Generating Sequences With Recurrent Neural Networks", 2013.
  • Argoverse, 2019 (motion forecasting benchmark).