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 | Brief introduction to deep learning | The basics for what comes next |
| 7 | Value function approximation | Value estimation with function approximation |
| 8 | Deep Q-learning | Q-learning with neural networks |
| 9 | Policy gradients | Direct optimization of the policy |
| 10 | Actor-critic algorithms | Improved policy gradients via value functions |
| 11 | Advanced algorithms (Part I): From policy gradient to PPO | The PG route to modern RL algorithms |
| 12 | Advanced algorithms (Part II): From \(Q\)-learning to Soft Actor-Critic | The AC route to modern RL algorithms |
| 13 | Exploration | |
| Model-Based Control | ||
| Advanced Topics |
Instead of maximizing over \(Q\), we introduce a function \(a = \mu_\phi(s)\) such that \(Q^*(s, \mu_\phi(s)) \approx \max_{a} Q^*(s, a)\).
Challenges:
\[ \nablaphi L_\pi(\phi) = \Expsub{\sum_{t=0}^{T-1} \nablaphi \log\piphi\agivenb{a_t}{s_t}\cbracket{\sum_{t'=t}^{T-1}r_{t'}}}{\tau\sim p_\phi(\tau)} \approx \textcolor{blue}{\frac{1}{N} \sum_{i=1}^N \cbracket{\sum_{t'=t}^{T-1} \nablaphi \log\,\piphi\agivenb{a_{i,t}}{s_{i,t}}\cbracket{\sum_{t'=t}^{T-1} r_{i,t'} }}}. \]
\[\nabla_\phi L_\pi(\phi) = \Expsub{\sum_{t=0}^{T-1} \nablaphi \log \piphi\agivenb{a_t}{s_t} A_\theta(s_t, a_t)}{\tau\sim p_\phi(\tau)} \approx \textcolor{blue}{\frac{1}{N} \sum_{i=1}^N \cbracket{\sum_{t=0}^{T-1} \nablaphi \log\,\piphi\agivenb{a_{i,t}}{s_{i,t}} A_\theta(s_{i,t},a_{i,t})} }. \]
Approach: Find a more sample-efficient and off-policy capable version \(\Rightarrow\) deterministic policy!
đź’ˇ In contrast to the on-policy case (see the Actor-Critic lecture), here it is not possible to formulate a recursive formula which would allow us to find a closed-form statement for \(\nablaphi\Qpiphi(s,a)\) via \(\nablaphi\Vpiphi(s)\). This only works in the on-policy setting!
\[ \nablaphi\Vpiphi \approx \sum_{s\in\Ac} \rho_\beta(s) \sum_{a\in\Ac} \nablaphi\piphi\agivenb{a}{s} \Qpiphi(s,a) = \Expsub{\sum_{a\in\Ac} \nablaphi\piphi\agivenb{a}{s} \Qpiphi(s,a)}{s\sim\rho_\beta}. \]
\[\begin{equation}\begin{aligned} \nablaphi L_\pi(\phi) &= \nablaphi\rbracket{\int_\Sc \rho_{\beta}(s) Q^{\mu_\phi}(s,\mu_\phi(s)) \dint{s}} = \int_\Sc \rho_{\beta}(s) \nablaa Q^{\mu_\phi}(s,\mu_\phi(s)) \big|_{a=\mu_\phi(s)} \nablaphi \mu_\phi(s) \dint{s} \\ &= \Expsub{\nablaa Q^{\mu_\phi}(s,\mu_\phi(s)) \big|_{a=\mu_\phi(s)} \nablaphi \mu_\phi(s)}{s\sim\rho_{\beta}}. \end{aligned} \label{eq:Adv2_dpg} \end{equation}\]
Approximate version: off-policy (\(\rho_{\beta} \neq \rho_{\mu_\phi}\), and we use the same simplification as earlier, i.e., \(\cancel{\mu_\phi\agivenb{a}{s} \nablaa Q^{\mu_\phi}(s,a)}\))
\[\begin{equation} \nablaphi L_\pi(\phi) \approx \Expsub{\nablaa Q^{\mu_\phi}(s,\mu_\phi(s)) \big|_{a=\mu_\phi(s)} \nablaphi \mu_\phi(s)}{s\sim\rho_{\beta}}.\label{eq:Adv2_dpg_approx} \end{equation}\]
đź’ˇ \(\eqref{eq:Adv2_dpg}\) is the limit case of the stochastic policy gradient theorem (i.e., \(\Var{\pi}\to 0\)) (Silver et al. 2014, Theorem 2).
The simplest algorithm we can derive from this: SARSA-type on-policy Actor-Critic:
To update a deterministic policy off-policy, your algorithm does this for a batch of states from the replay buffer:
addresses these by importing techniques from Deep Q-Networks (DQN).
DDPG works on many tasks, but is highly sensitive to hyperparameters as well as other randomness (e.g., the sampling).
\(\Rightarrow\) In TD3 (Fujimoto, Hoof, and Meger 2018), three main issues were identified and addressed:
\(~\Rightarrow\) Update actor (\(\phi\)) and targets (\(\bar{\phi}\), \(\bar{\theta}_1\), \(\bar{\theta}_2\)) less frequently than critics (\(\theta_1\), \(\theta_2\)), e.g., every \(n_\mathsf{up}=2\) steps.
\(~\Rightarrow\) TD3 adds a small amount of clipped noise (clipping constant \(c\)) to the target action before feeding it into the target critic: \[\tilde{a} = \mu_{\bar{\phi}}(s) + \epsilon, \quad \epsilon \sim \mathsf{clip}(\mathcal{N}(0, \tilde{\sigma}^2), -c, c).\]
Perform next steps only every \(n_\mathsf{up}\) steps: (đź’ˇ the Delayed):
Half Cheetah from the MuJoCo library.
\[L_\pi(\phi) = \Expsub{\log\cbracket{\piphi\agivenb{a}{s}} - \frac{Q^\pi(s, a)}{\alpha} + \log\cbracket{Z^\pi(s)}}{s\sim \rho, a\sim\piphi}.\]
If we define: \[\subnew{\pi} = \arg\min_{\pi'} \KLdiv{ \pi'\agivenb{\cdot}{s}}{\frac{\exp\left(\frac{Q^{\subold{\pi}}\agivenb{\cdot}{s}}{\alpha}\right)}{Z^{\subold{\pi}}(s)}},\] then the soft \(Q\)-value of the new policy is guaranteed to be monotonically greater than or equal to the old one for all \((s,a)\): \[Q^{\subnew{\pi}}(s, a) \geq Q^{\subold{\pi}}(s, a) \quad \forall (s,a).\]
đź’ˇ Because we pass the Gaussian sample through a \(\tanh\) function, the log-likelihood must be corrected using the Jacobian of the transformation: \(\log \pi_\theta\agivenb{a}{s} = \log \mu\agivenb{u}{s} - \sum_{i=1}^{m} \log(1 - \tanh^2(u_i))\), where \(u\) is the pre-tanh action value.
Half Cheetah from the MuJoCo library.
đź’ˇ Trained models from StableBaselines3.
Notes
| Feature | DDPG | TD3 | SAC |
|---|---|---|---|
| Policy Type | Deterministic | Deterministic | Stochastic |
| Exploration | Additive Noise (e.g., OU Noise) | Additive Noise (Gaussian) | Intrinsic (Entropy Maximization) |
| Q-Overestimation Cure | None | Clipped Double-Q | Clipped Double-Q |
| Sensitivity to Hyperparameters | Extremely High | High | Low (Very Stable) |
| Sample Efficiency | Moderate | Good | Excellent |