Search

Search papers and lessons

Model Predictive Path Integral Control

Level 4 · 11 min read

Model predictive path integral (MPPI) control plans by sampling many noisy action sequences, scoring each rollout, and averaging them with exponential cost weights.

On this page

  • Colour = topic mix
  • Calculus
  • Probability
  • Linear algebra
  • Neural network basics
  • Reinforcement learning
  • Discrete math
  • Sign in to see your progress

TL;DR

Model predictive path integral (MPPI) control runs model predictive control without solving a gradient-based optimisation. At each step it samples many random perturbations of the current action plan, rolls each one out through a model, and scores each rollout by its total cost. The plan is then moved toward the perturbations that scored well, with each one weighted by an exponential of its cost. As in MPC, only the first action is applied, and the planner runs again at the next step.

Where you'll see it: real-time control of legged robots, drones and off-road vehicles, where the cost has jumps such as collisions and a GPU can roll out thousands of samples in parallel.

Intuition

A crowd of scouts in fog

Imagine a group of hikers lost in fog, trying to reach the lowest point of a valley. Nobody can see the slope, but each hiker can take a step and feel the ground there. The group sends many scouts off in slightly different random directions. Each scout reports the height it reached. The group then moves its centre toward the scouts who went lowest, and it gives the lowest scouts the most say. Repeat, and the group drifts downhill without ever computing a slope.

MPPI works the same way. The "scouts" are sampled action sequences, the "height" is the cost of the rollout, and the "centre" is the current plan. The "model" predicts where each sequence leads, so the scouts can be simulated rather than walked.

Why not just use gradients?

Ordinary MPC, covered in Model Predictive Control, needs the cost and the dynamics to be smooth enough to differentiate. Real robots break this. A contact changes the dynamics abruptly, a collision adds a cost that jumps from zero to a large value, and a black-box simulator may give no derivatives at all. Sampling needs only one thing: the ability to roll out a candidate plan and score it. The cost of that freedom is that the planner must draw many samples, and it has to average them sensibly.

The loop

flowchart LR
  A[Shift last plan forward] --> B[Sample K noisy action sequences]
  B --> C[Roll each one out through the model]
  C --> D[Score each rollout with its cost]
  D --> E[Weight by exp of minus cost over lambda]
  E --> F[Move the plan by the weighted average of the noise]
  F --> G[Apply the first action and wait for the next state]
  G --> A

The math

Use a discrete-time model xt+1=f(xt,ut)x_{t+1} = f(x_t, u_t), where xtx_t is the state at step tt and utu_t is the action. The planner keeps a nominal action sequence uˉ=(uˉ0,…,uˉH−1)\bar{u} = (\bar{u}_0, \dots, \bar{u}_{H-1}) over a horizon of HH steps. Let q(x)q(x) be a running cost, ϕ(x)\phi(x) a terminal cost, Σ\Sigma a noise covariance, and λ>0\lambda \gt 0 a temperature that sets how sharply the planner prefers low-cost samples.

Definition: MPPI rollout cost

Draw KK perturbation sequences εk=(ε0k,…,εH−1k)\varepsilon^k = (\varepsilon^k_0, \dots, \varepsilon^k_{H-1}) with each εtk∼N(0,Σ)\varepsilon^k_t \sim \mathcal{N}(0, \Sigma) independent. Roll out from the measured state x0x_0 using xt+1k=f(xtk,uˉt+εtk)x^k_{t+1} = f(x^k_t, \bar{u}_t + \varepsilon^k_t), then score the rollout

Sk=ϕ(xHk)+∑t=0H−1[q(xtk)+λ uˉt⊤Σ−1εtk].S^k = \phi(x^k_H) + \sum_{t=0}^{H-1} \Bigl[ q(x^k_t) + \lambda\, \bar{u}_t^\top \Sigma^{-1} \varepsilon^k_t \Bigr].

Here SkS^k is the total cost of sample kk. The last term in the sum is the control cost implied by the Gaussian noise model. It is what makes the weighting below match a KL penalty with the same λ\lambda.

Where the weighting comes from

The update rule looks like a heuristic, but it has a precise origin. Let pp be the distribution over perturbation sequences, which is the Gaussian noise the sampler draws from. Let qq be any other distribution over perturbations. Consider the objective

J(q)=Eq[S]+λ KL(q ∥ p).J(q) = \mathbb{E}_q[S] + \lambda\, \mathrm{KL}(q \,\|\, p).

It trades off a low expected cost against staying close to the noise model, where KL\mathrm{KL} is the KL divergence. The Gibbs Variational Principle says the minimiser is the exponentially tilted distribution

q⋆(ε)=1Z p(ε) exp⁡ ⁣(−S(ε)/λ),Z=Ep[exp⁡(−S/λ)].q^\star(\varepsilon) = \frac{1}{Z}\, p(\varepsilon)\, \exp\!\bigl(-S(\varepsilon)/\lambda\bigr), \qquad Z = \mathbb{E}_p\bigl[\exp(-S/\lambda)\bigr].

The planner wants the mean of q⋆q^\star, because adding that mean to the nominal plan moves the plan to where low-cost perturbations live. The mean is Eq⋆[ε]=Ep[ε e−S/λ]/Z\mathbb{E}_{q^\star}[\varepsilon] = \mathbb{E}_p[\varepsilon\, e^{-S/\lambda}] / Z. This is an expectation under pp of the perturbation weighted by e−S/λe^{-S/\lambda}, so it can be estimated from the KK samples. That is exactly Importance Sampling: draw from pp, reweight by the density ratio, which here is proportional to e−S/λe^{-S/\lambda}.

The update

With β=min⁡kSk\beta = \min_k S^k subtracted for numerical stability, the normalised weights are

wk=exp⁡(−(Sk−β)/λ)∑j=1Kexp⁡(−(Sj−β)/λ),uˉt←uˉt+∑k=1Kwkεtkfor each t.w^k = \frac{\exp\bigl(-(S^k - \beta)/\lambda\bigr)}{\sum_{j=1}^{K} \exp\bigl(-(S^j - \beta)/\lambda\bigr)}, \qquad \bar{u}_t \leftarrow \bar{u}_t + \sum_{k=1}^{K} w^k \varepsilon^k_t \quad \text{for each } t.

Subtracting β\beta does not change the weights, because it cancels in the normalisation. It only keeps the exponentials from underflowing when costs are large.

Algorithm
One MPPI step
  1. Shift the previous nominal sequence one step forward, and fill the last slot with a copy of its final action.
  2. Draw KK noise sequences εk\varepsilon^k from N(0,Σ)\mathcal{N}(0, \Sigma).
  3. From the measured state, roll out each uˉ+εk\bar{u} + \varepsilon^k through the model and compute SkS^k.
  4. Compute the weights wkw^k from SkS^k and λ\lambda.
  5. Update uˉt←uˉt+∑kwkεtk\bar{u}_t \leftarrow \bar{u}_t + \sum_k w^k \varepsilon^k_t for every tt.
  6. Apply the first action uˉ0\bar{u}_0 to the real system. Repeat at the next measurement.

Worked examples

Example
Three samples, one step, by hand

Take a one-dimensional system xt+1=xt+utx_{t+1} = x_t + u_t, with x0=1x_0 = 1, horizon H=1H = 1, Σ=1\Sigma = 1, λ=1\lambda = 1, and nominal uˉ0=0\bar{u}_0 = 0. The rollout cost is S=x12S = x_1^2, so the best action is u0=−1u_0 = -1, which reaches zero. Because the nominal is zero, the control term in SkS^k vanishes.

  1. Draw three perturbations: ε1=−1.0\varepsilon^1 = -1.0, ε2=0.5\varepsilon^2 = 0.5, ε3=−0.2\varepsilon^3 = -0.2.
  2. Roll out and score. S1=(1−1.0)2=0S^1 = (1 - 1.0)^2 = 0, S2=(1+0.5)2=2.25S^2 = (1 + 0.5)^2 = 2.25, S3=(1−0.2)2=0.64S^3 = (1 - 0.2)^2 = 0.64.
  3. Subtract β=0\beta = 0 and exponentiate. The raw weights are e0=1e^0 = 1, e−2.25=0.1054e^{-2.25} = 0.1054, e−0.64=0.5273e^{-0.64} = 0.5273, with sum 1.63271.6327.
  4. Normalise. The weights are 0.61250.6125, 0.06460.0646 and 0.32300.3230.
  5. Update the nominal action. uˉ0=0.6125(−1.0)+0.0646(0.5)+0.3230(−0.2)=−0.6448\bar{u}_0 = 0.6125(-1.0) + 0.0646(0.5) + 0.3230(-0.2) = -0.6448.
  6. Apply u0=−0.645u_0 = -0.645. The state becomes x1=0.355x_1 = 0.355.

Interpretation: with three samples the plan moved about 64 percent of the way to the optimum −1-1 in one step. The best sample carried most of the weight, but the other two still contributed. The effective sample size, one divided by the sum of squared normalised weights, is about 2.072.07 here, which is the number of samples that effectively count.

Example
What the temperature does to the same samples

Use the same three samples and costs as above, and change only λ\lambda.

  1. At λ=10\lambda = 10, the raw weights are e0=1e^{0} = 1, e−0.225=0.7985e^{-0.225} = 0.7985 and e−0.064=0.9380e^{-0.064} = 0.9380. The sum is 2.73652.7365.
  2. The normalised weights are 0.36540.3654, 0.29180.2918 and 0.34280.3428.
  3. The update is −0.3654+0.2918(0.5)+0.3428(−0.2)=−0.2881-0.3654 + 0.2918(0.5) + 0.3428(-0.2) = -0.2881.
  4. At λ=0.1\lambda = 0.1, the raw weights are 11, e−22.5≈0e^{-22.5} \approx 0 and e−6.4=0.00166e^{-6.4} = 0.00166. The normalised weights are 0.99830.9983, about 00 and 0.001660.00166.
  5. The update is −0.9983+0.00166(−0.2)=−0.9987-0.9983 + 0.00166(-0.2) = -0.9987.

Interpretation: a large λ\lambda averages the samples almost evenly, so the plan moves only a little toward the best one. A small λ\lambda makes the planner behave like a greedy pick of the single best sample. Tuning λ\lambda is the main decision in MPPI, and the plot shows why.

00.511.522.533.5400.20.40.60.81rollout cost minus best costunnormalised weight
  • lambda = 0.5
  • lambda = 1
  • lambda = 4
A rollout's weight falls exponentially with its cost. A small lambda makes the best rollout dominate; a large lambda keeps the weights close to equal.

Tradeoffs and failure modes

MPPI is flexible because it needs only forward simulation and a cost. It is costly because its estimate of the best action is only as good as the samples behind it.

SituationWhat goes wrongBetter choice
λ\lambda too smallOne sample takes almost all the weight, so the plan jumps between samples and the effective sample size collapsesRaise λ\lambda, or draw more samples
λ\lambda too largeThe weights are nearly equal and the plan barely moves toward low costLower λ\lambda
Too few samples for HH times the action dimensionThe estimate has high variance and the controller is erraticMore samples per step, a shorter horizon, or smoother noise
Noise Σ\Sigma too largeApplied actions are jerky and the plan wandersReduce Σ\Sigma, or correlate the noise across time
Smooth, differentiable dynamics and costSampling wastes compute on an estimate that gradients would give exactlyGradient-based Model Predictive Control
Collision or contact costs with jumpsGradients are undefined or misleadingMPPI, which only needs rollouts and scores

Sampling gives no finite-sample guarantee that the plan is optimal. Its quality depends on the samples and on the model. A learned model can be wrong far from its training data, and the planner will happily exploit that error if the sampled rollouts go there. This is the same failure mode as in Model-Based Reinforcement Learning, and it is handled the same way: check the effective sample size, keep the horizon no longer than the model is accurate, and penalise states the model has not seen.

History

The idea comes from a line of work connecting optimal control to probability. In the mid-2000s, Bert Kappen showed that for a restricted class of stochastic optimal control problems, the nonlinear Hamilton–Jacobi–Bellman equation (the continuous-time form of the Bellman Equation) becomes linear after a logarithmic change of variables. Its solution is then an exponential average over sampled trajectories, which he called path integral control. The name refers to the path integrals of physics, in which a quantity is an average over all paths weighted by an exponential of an action.

Around 2010, Evangelos Theodorou, Jonas Buchli and Stefan Schaal turned this into a practical sampling method for reinforcement learning and robot control. Their sampled trajectories were weighted by an exponential of their cost, and the controller was updated with the weighted average of the sampled noise.

Grady Williams, Andrew Aldrich and Evangelos Theodorou then made the method a receding-horizon controller. Their 2015 work used covariance-based variable importance sampling for model predictive control. In 2017, Williams and colleagues, including Paul Drews, Brian Goldfain, James Rehg and Theodorou, published the information-theoretic version used in this lesson, with a parallel implementation that ran many rollouts at once on a GPU. That made real-time sampling feasible for autonomous driving, and the method spread to other robots from there.

Check yourself

QuestionIn one sentence, what does the temperature lambda control in MPPI?Show answer

It controls how sharply the rollout weights favour low-cost samples. Weights are proportional to exp(-S/lambda), so a small lambda concentrates weight on the best sample and a large lambda spreads it almost evenly across the samples.

QuestionTwo rollouts have costs 1 and 3, and lambda = 2. Subtract the best cost first, then find the normalised weight of the cost-3 rollout.Show answer

Subtract beta = 1, which gives 0 and 2. The raw weights are exp(0) = 1 and exp(-2/2) = exp(-1) = 0.3679. The sum is 1.3679, so the cost-3 rollout has weight 0.3679 / 1.3679 = 0.2689.

QuestionWhy is the minimum cost subtracted before the exponentials are computed, if it does not change the weights?Show answer

The subtraction cancels in the normalisation, so the weights are unchanged. It keeps the exponentials from underflowing to zero when costs are large, so the weights stay numerically meaningful.

QuestionA robot's cost includes a large penalty whenever it touches an obstacle, which is a jump in the cost. Why might gradient-based MPC struggle here, and why can MPPI handle it?Show answer

The penalty has no useful gradient at the jump, so a gradient solver can stall or be misled near the obstacle. MPPI only needs to roll out each candidate and read its total cost, so the jump simply makes some samples score badly and gets them down-weighted.

QuestionAn MPPI controller has very jerky motion, and its effective sample size is near 1 at every step. What is the most likely cause, and what would you change first?Show answer

The weights have collapsed onto one sample, which usually means lambda is too small for the spread of the costs. Raise lambda first, then check whether more samples or a smaller noise covariance is needed. Adjusting lambda is the cheapest fix and usually addresses the jerkiness directly.

Sources