Seyed Masoud Hosseini · Overview · Study log · Weekly summaries · Ideas · Search · Transcript · RSS feed

Deep Reinforcement Learning · Lecture 42 of 99 · 23:49

Lecture 10, Part 3: Trajectory Optimization with the LQR

CS 285: Lecture 10, Part 3 on YouTube

Study guide

What this lecture covers

Building on the black-box planning methods from Part 2, this part of Lecture 10 turns to trajectory optimization methods that exploit derivatives of the dynamics and cost. It switches to optimal-control notation (x for state, u for action, cost instead of reward) and works toward deriving the linear quadratic regulator (LQR), a classic second-order shooting method.

After watching, you'll be able to explain why first-order gradient descent struggles on shooting-style trajectory objectives, distinguish shooting from co-location methods, and follow the backward-then-forward recursion that LQR uses to compute an optimal action sequence for linear dynamics with quadratic cost.

Key ideas

  • Optimal-control notation: x_t/u_t and cost replace the s_t/a_t and reward used elsewhere in the course; the underlying math is the same up to a sign.
  • Shooting methods: optimize only over actions, substituting the dynamics constraint directly into the objective; numerically unstable because early actions have an outsized effect on the final cost.
  • Co-location methods: optimize over both states and actions subject to dynamics constraints, which tends to be better conditioned but is more complex to set up.
  • Linear quadratic regulator (LQR): assumes linear dynamics (x_t = F_t [x_{t-1}; u_{t-1}] + f_t) and quadratic cost, and solves for the optimal action sequence in closed form.
  • Backward recursion: starting from the last time step and working backward, LQR expresses each optimal action as u_t = K_t x_t + k_t and each value function as a quadratic form in x_t.
  • Forward recursion: once K_t and k_t are known for every step, starting from the known initial state x_1, you compute u_1, then x_2 via the dynamics, then u_2, and so on to the end of the trajectory.
  • Q-function and value function: in this setting the Q-function is the total cost from a given state-action pair to the end of the trajectory, and the value function is the total cost from a given state under the optimal policy.

Walkthrough

Shooting vs. co-location (4:03)

The lecture reframes model-based planning as an unconstrained optimization by substituting the dynamics constraint directly into the cost. Applying first-order gradient descent to this directly tends to work poorly because chaining many Jacobians together produces vanishing or exploding gradients, so second-order methods are preferred. Shooting methods optimize only actions and are sensitive to the first action's outsized effect on the trajectory; co-location methods optimize over states and actions jointly with explicit dynamics constraints, giving better numerical conditioning at the cost of more complexity.

LQR problem setup (7:15)

LQR assumes deterministic linear dynamics and a quadratic cost function, with potentially different linear/quadratic coefficients at each time step. The derivation starts at the last time step: since the final action u_T only affects the cost at time T, you can solve for the u_T that minimizes a quadratic expression in u_T and x_T by setting its derivative to zero, giving u_T = K_T x_T + k_T.

Deriving the value function and recursing backward (12:00, from 7:15 section)

Substituting the optimal u_T back into the objective produces the value function V(x_T), a quadratic form in x_T alone. This value function then feeds into the Q-function for the preceding time step, t-1, through the linear dynamics that relate x_t to x_{t-1} and u_{t-1}. The same derivative-and-solve procedure yields u_{t-1} = K_{t-1} x_{t-1} + k_{t-1}, and the pattern repeats all the way back to t=1.

Solving the LQR recursion (20:11)

Once the backward pass has produced K_t and k_t for every time step, the algorithm switches direction. Since x_1 is known, you compute u_1 = K_1 x_1 + k_1, then use the dynamics to get x_2, then u_2, and so on through x_T. The lecture describes this as "unzipping" the problem going backward and "zipping it back up" going forward, producing a full optimal trajectory for the linear-quadratic case. This sets up the extension to nonlinear dynamics covered later in the lecture.

Before you watch

  • Watch Lecture 10, Part 2 first for the open-loop planning framing and why derivative-free methods have a dimensionality limit.
  • Be comfortable with basic matrix calculus (taking derivatives of quadratic forms) and the chain rule, since the LQR derivation relies on both.

Check your understanding

  1. Why does naive first-order gradient descent perform poorly on shooting-style trajectory optimization objectives?
  2. What distinguishes a shooting method from a co-location method in trajectory optimization?
  3. Why must the cost function be quadratic (not linear) for the LQR derivation to produce a useful solution?
  4. Explain why LQR is solved with a backward pass followed by a forward pass rather than in one direction.
  5. What do the matrix K_t and vector k_t represent in the LQR solution u_t = K_t x_t + k_t?

Vocabulary

trajectory optimization (phrase)
Finding the best sequence of states and actions using derivatives and optimization.
Trajectory optimization exploits gradients of the dynamics.
derivative (noun)
How much a function's output changes for a small change in its input.
This method exploits derivatives of the dynamics and cost.
shooting method (phrase)
An optimization approach that optimizes only over actions and lets states follow from the dynamics.
Shooting methods can be unstable because early actions matter most.
co-location method (phrase)
An optimization approach that treats states and actions as separate variables tied together by constraints.
Co-location methods are better conditioned but more complex.
Jacobian (noun)
A matrix of all the derivatives of a function's outputs with respect to its inputs.
Chaining many Jacobians causes vanishing or exploding gradients.
vanishing gradient (phrase)
A gradient that becomes extremely small, making learning very slow.
Long chains of derivatives can cause vanishing gradients.
exploding gradient (phrase)
A gradient that becomes extremely large, making training unstable.
Exploding gradients can also come from chained Jacobians.
linear quadratic regulator (LQR) (noun)
A classic control method that solves for the best actions when dynamics are linear and cost is quadratic.
LQR gives a closed-form solution for the optimal trajectory.
backward recursion (phrase)
Computing results starting from the last step and working toward the first.
LQR uses backward recursion to compute K and k.
forward recursion (phrase)
Computing results starting from the first step and moving toward the last.
The forward recursion produces the actual trajectory.
quadratic cost (phrase)
A cost function built from squared terms.
LQR assumes a quadratic cost function.
linear dynamics (phrase)
A system where the next state is a straight-line function of the current state and action.
LQR assumes linear dynamics between states.
conditioning (noun)
How sensitive a numerical problem is to small changes, affecting how stable it is to solve.
Co-location gives better numerical conditioning.
unzip (verb)
To informally describe working step by step through a chain in one direction.
The backward pass unzips the problem going backward.
solve for (phrase)
To find the value of an unknown by working through equations.
We solve for the optimal action at the last time step.
cost-to-go (phrase)
The total expected cost remaining from a given point onward.
The Q-function here represents the cost-to-go from a state-action pair.
notation (noun)
The symbols and conventions used to write mathematical ideas.
Optimal-control notation swaps reward for cost.
outsized (adjective)
Larger than expected or usual.
Early actions have an outsized effect on the final cost.
set derivative to zero (phrase)
A calculus technique for finding the minimum or maximum of a function.
We set the derivative to zero to find the optimal action.
substitute back (phrase)
To plug a found value back into an earlier expression.
Substituting the optimal action back gives the value function.

Chapters

← Lecture 10, Part 2: Stochastic Optimization for Planning · Lecture 10, Part 4: Extending LQR to Stochastic and Nonlinear Systems →