Prof. Dr. Sebastian Peitz
Chair of Safe Autonomous Systems, TU Dortmund
| Chapter | Topic | Content |
|---|---|---|
| Basics & tabular methods | ||
| 1-5 | Bandits, MDPs, Dynamic Programming, Monte Carlo, TD Learning | RL basics in finite dimensions |
| Deep-learning-based methods | ||
| 6-13 | DQN, policy gradients, actor-critic, PPO/SAC, exploration | Deep RL from basics to modern algorithms |
| Model-Based Control | ||
| 14 | Optimal control & feedback control | How to do control when we know the model |
| Model-based reinforcement learning | ||
| Advanced Topics |
while (\(\Delta > \theta\)):
\(\quad\) \(\Delta \gets 0\)
\(\quad\) for \(s \in \Sc\):
\(\quad\quad\) \(V_{\mathsf{old}}(s) \gets V(s)\)
\(\quad\quad\) \(V(s) \gets \max_{a\in\Ac} \sum_{s'\in\Sc} \textcolor{red}{\psprimesa} \left[ r + \gamma V(s') \right]\)
\(\quad\quad\) \(\Delta \gets \max(\Delta, \abs{V_{\mathsf{old}}(s)-V(s)})\)
\(\textcolor{green}{\mathbf{+}\text{ No model knowledge required. All we need is access\\ ~~~~to the system / a black-box simulator.}}\)
\(\textcolor{green}{\mathbf{+}\text{ No bias due to inaccurate model.}}\)
\(\textcolor{green}{\mathbf{+}\text{ Easier to implement.}}\)
\(\textcolor{red}{\mathbf{-}\text{ Data-hungry! Can be very sample-inefficient.}}\) \(\textcolor{red}{\mathbf{-}\text{ Ignorant of prior knowledge.}}\)
We often know the dynamics:
Also, we can often learn the dynamics:
1. Probabilistic vs. deterministic
2. Known vs. unknown
💡 The case of learning a model is covered extensively in the next lecture.
\[ \pC{s_0,\ldots,s_T}{a_0,\ldots,a_{T-1}} = p(s_0)\prod_{t=0}^{T-1}\pC{s_{t+1}}{s_t,a_t}.\]
\[\begin{equation}\begin{aligned} &\min_{a_0,\ldots,a_{T-1}} \underbrace{\sum_{t=0}^T \ell(s_t,a_t)}_{= L(a)} \quad \text{subject to}\quad &s_{t+1}=f(s_t,a_t),~t=0,1,\ldots,T-1. \end{aligned}\tag{\ref{eq:OC_ocp}} \end{equation} \]
A very common approach to solve the OCP \(\eqref{eq:OC_ocp}\) is via single shooting, where assume that the states \(s_t\) are implicitly defined by choosing the actions \(a_t\).
💡 This holds for most systems of interest. The basis for this are existence-and-uniqueness theorems, e.g., by Picard-Lindelöf.
Initialize: Initial state \(s_0\), action sequence \(\iterate{a}{0}=\cbracket{\iteratesub{a}{0}{0},\ldots,\iteratesub{a}{0}{T-1}}\).
for \(j=0,1,2,\ldots\):
\(\quad\) simulate the system following \(\iterate{a}{j}\) to get \(\iterate{s}{j}=\cbracket{\iteratesub{s}{j}{1},\ldots,\iteratesub{s}{j}{T}}\)
\(\quad\) assess the performance by computing \(L\cbracket{\iterate{a}{j}}\)
\(\quad\) gradient descent to update our actions: \[\iterate{a}{j+1} = \iterate{a}{j} - \eta \nabla_a L\cbracket{\iterate{a}{j}} \]
How do we compute the gradient \[\nabla_a L\cbracket{\iterate{a}{j}}?\]
\[\begin{equation}\begin{aligned} &\min_{a_0,\ldots,a_{T-1}} \underbrace{\sum_{t=0}^T \ell(s_t,a_t)}_{= L(a)} \quad \text{subject to}\quad &s_{t+1}=f(s_t,a_t),~t=0,1,\ldots,T-1. \end{aligned}\tag{\ref{eq:OC_ocp}} \end{equation} \]
The procedure of computing the gradient is closely related to the backpropagation algorithm!
\[\Lc(s,a,\lambda) = \sum_{t=0}^T \ell(s_t,a_t) + \sum_{t=0}^{T-1} \lambda^\top_{t+1}\cbracket{f(s_t,a_t)- s_{t+1}}\]
Given: Initial state \(s_0\), action sequence \(a=\cbracket{a_0,\ldots,a_{T-1}}\).
| Shooting \(\eqref{eq:OC_ocp}\) | Full discretization \(\eqref{eq:OC_ocp_discretized}\) | |
|---|---|---|
| Sensitivity to initialization | Very sensitive to poor initial guesses \(\iterate{a}{0}\). | Because we initialize the entire state trajectory \(s\), the system doesn’t have to be dynamically feasible during early solver iterations \(\Rightarrow\) Significantly more stable for unstable dynamics. |
| Computational cost vs. convergence | Fast iterations (one forward and backward pass), but may take many iterations to converge. | Iterations more expensive, but standard Sequential Quadratic Programming (SQP) or Interior Point methods achieve quadratic convergence near the solution, requiring far fewer total iterations. |
| Constraint Handling | Handling state constraints requires challenging penalty functions or barrier methods. | Limits on states like \(s_{\mathsf{min}} \leq s_t \leq s_{\mathsf{max}}\) or actuations (\(a_{\mathsf{min}} \leq a_t \leq a_{\mathsf{max}}\)) can be handled easily. They are simply treated as bound constraints on elements of our vector \(x\). |
Let’s consider a special (yet very common) case
\[\begin{equation} \begin{aligned} \min_{s,a} &\cbracket{\sum_{t=0}^{T-1} s_t^\top Q s_t + a_t^\top R a_t} + s_T^\top Q_f s_T \\ \text{subject to}\quad s_{t+1}&=A s_t + B a_t,~t=0,1,\ldots,T-1. \end{aligned} \label{eq:OC_ocp_linear} \end{equation}\]
Let’s explicitly calculate \(s_1,s_2,\ldots\): \[\begin{align*} &s_1 = \textcolor{blue}{A s_0 + B a_0} \\ &s_2 = A s_1 + B a_1 \fragment{ = A (\textcolor{blue}{A s_0 + B a_0}) + B a_1 } \fragment{ = \textcolor{red}{A^2 s_0 + AB a_0 + B a_1} } \\ &s_3 = A s_2 + B a_2 \fragment{ = A (\textcolor{red}{A^2 s_0 + AB a_0 + B a_1}) + B a_2 }\fragment{ = A^3 s_0 + A^2B a_0 + ABa_1 + Ba_2 } \\ &\text{General rule:} \quad s_t = A^t s_0 + \sum_{i=0}^t A^{t-i-1}B a_i\\ &\text{Explicitly:} \quad \underbrace{\begin{bmatrix} s_0 \\ s_1 \\ s_2 \\ s_3 \\ \vdots \\ s_T \end{bmatrix}}_{\hat{s}\in\R^{(T+1)n}} = \underbrace{\begin{bmatrix} 0 & 0 & 0 & \ldots & B \\ 0 & 0 & 0 & \ldots & 0 \\ AB & B & 0 & \ldots & 0 \\ A^2B & AB & B & \ddots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ A^{T-1}B & A^{T-2}B & A^{T-3}B & \ldots & B \\ \end{bmatrix}}_{G\in\R^{(T+1)n\times Tm}} \underbrace{\begin{bmatrix} a_0 \\ a_1 \\ a_2 \\ a_3 \\ \vdots \\ a_{T-1} \end{bmatrix}}_{\hat{a}\in\R^{Tm}} + \underbrace{\begin{bmatrix} I \\ A \\ A^2 \\ A^3 \\ \vdots \\ A^T \end{bmatrix}}_{H\in\R^{(T+1)n}} s_0 \\ &\text{In short:}\quad \hat{s}=G\hat{a}+Hs_0 \end{align*}\]
\[\begin{align*} &\min_{\textcolor{red}{\hat{a}}} \cbracket{G\textcolor{red}{\hat{a}} + H\textcolor{blue}{s_0}}^\top \hat{Q} \cbracket{G\textcolor{red}{\hat{a}} + H\textcolor{blue}{s_0}} + \textcolor{red}{\hat{a}}^\top \hat{R} \textcolor{red}{\hat{a}} \\ =&\min_{\textcolor{red}{\hat{a}}} \cbracket{\textcolor{red}{\hat{a}}^\top G^\top + \textcolor{blue}{s_0}^\top H^\top} \hat{Q} \cbracket{G\textcolor{red}{\hat{a}} + H\textcolor{blue}{s_0}} + \textcolor{red}{\hat{a}}^\top \hat{R} \textcolor{red}{\hat{a}} \\ =&\min_{\textcolor{red}{\hat{a}}} \textcolor{red}{\hat{a}}^\top G^\top \hat{Q} G \textcolor{red}{\hat{a}} + 2 \textcolor{red}{\hat{a}}^\top G^\top \hat{Q} H \textcolor{blue}{s_0} + \textcolor{blue}{s_0}^\top H^\top \hat{Q} H \textcolor{blue}{s_0} + \textcolor{red}{\hat{a}}^\top \hat{R} \textcolor{red}{\hat{a}} \\ =&\min_{\textcolor{red}{\hat{a}}} \textcolor{red}{\hat{a}}^\top \cbracket{G^\top \hat{Q} G + \hat{R}} \textcolor{red}{\hat{a}} + 2 \textcolor{red}{\hat{a}}^\top G^\top \hat{Q} H \textcolor{blue}{s_0} + \textcolor{blue}{s_0}^\top H^\top \hat{Q} H \textcolor{blue}{s_0} \end{align*}\]
\[\begin{align*} (G\hat{a})^\top &= \hat{a}^\top G^\top\\ s_0^\top H^\top \hat{Q} G \hat{a} &= \hat{a}^\top G^\top \hat{Q} H s_0 \end{align*} \]
\[\begin{equation}\text{OCP:}\quad\min_{a_0,\ldots,a_{T-1}} \sum_{t=0}^T \ell(s_t,a_t) = \min_{a_0,\ldots,a_{T-1}} L(a) \quad \text{s.t.}\quad s_{t+1}=f(s_t,a_t),~t=0,1,\ldots,T-1. \tag{\ref{eq:OC_ocp}}\end{equation}\]
\(\textcolor{green}{\mathbf{+}\text{ Very robust.}}\)
\(\textcolor{green}{\mathbf{+}\text{ No offline learning phase (if model known).}}\)
\(\textcolor{green}{\mathbf{+}\text{ Easy to include state constraints.}}\)
\(\textcolor{green}{\mathbf{+}\text{ Lots of theory.}}\) (e.g., (Grüne and Pannek 2017))
\(\textcolor{red}{\mathbf{-}\text{ Real-time capability (in particular for nonlinear models).}}\) \(\textcolor{red}{\mathbf{-}\text{ Control performance depends on model quality.}}\)
We want to plan the trajectory of an autonomous vehicle from an initial position towards a terminal position.
\[\begin{align*} s&=\begin{bmatrix} x \\ y \\ \theta \\ v \end{bmatrix},~ a=\begin{bmatrix} \mathsf{acc} \\ \delta \end{bmatrix}, \\ \dot{s} &=\begin{bmatrix} s_4 \cos s_3 \\ s_4 \sin s_3 \\ \frac{s_4}{L} \tan a_2 \\ a_1 - \lambda s_4 \end{bmatrix}. \end{align*}\]

for \(t=0,1,2,\ldots\):
\(\quad\) Measure the current state \(\overline{s}_t,\overline{a}_t\)
\(\qquad\) of the real (nonlinear system).
\(\quad\) Linearize the system dynamics
\(\qquad\) around \(\overline{s}_t,\overline{a}_t\) \(\Rightarrow\) \(\eqref{eq:OC_MPC_linearized}\).
\(\quad\) Assemble matrices \(\hat{Q}_t\) / \(\hat{R}_t\) and \(G_t\) / \(H_t\).
\(\quad\) Solve linear problem \(\eqref{eq:OC_ocp_linear2}\).
\(\quad\) Apply first entry to real system.
\(\qquad\qquad\)New bottlenecks:\(\qquad\) \(\bullet\) The linearization around \(\overline{s}_t,\overline{a}_t\) \(\qquad\) \(\bullet\) Assembly of \(\hat{Q}_t\) / \(\hat{R}_t\) and \(G_t\) / \(H_t\).