Reinforcement Learning using Model Predictive Control#
If you have followed along, it is not difficult to see that the parametric MPC scheme that was discussed above is more than suitable for being used as a policy provider in the context of RL. This concept was first introduced and properly formulated in [5].
MPC as function approximation#
In fact, the MPC scheme naturally acts as a policy provider, so the definition of its policy in the context of RL follows naturally as
What’s more, as shown in [5], the MPC controller can also be employed to approximate the value functions as
and
The Bellman relationships also hold, with
However, approximating the policy and the value functions with some function approximation scheme is only half of the story. The other half is to understand how to adjust the parameters \(\theta\) of such paramatric approximation in order to improve the RL performance and minimize the incurred costs. This is where famous gradient-based RL algorithms come into play. Nevertheless, to apply these algorithms, the gradient of the MPC quantities w.r.t. the parameters \(\theta\) must be evaluated. To do so, [5] proposed to leverage nonlinear sensitivity analysis techniques [1] that exploit the KKT conditions to compute such sensitivities.
Q-learning with MPC#
Unsurprisingly, the Q-learning algorithm can be employed to tune the parameters of the MPC controller to improve its performance. The underlying idea of Q-learning is to approximate as best as possible the unknown optimal Q-function \(Q^\star\) by minimizing the Bellman residual, i.e.,
This can be (approximately) achieved with the famous update rule
where \(\alpha\) is the learning rate and \(\delta_k\) is the Temporal Difference (TD) error at time step \(k\). [3] improves upon the update above and embeds it with second order information, i.e., it includes not only the gradient of the approximation, but also an estimate of its hessian.
So far, these concepts are pretty standard to Q-learning. The real question is, how can we compute \(\nabla_\theta Q_\theta(s_k,a_k)\) when the action value function is provided by an MPC optimization scheme? It turns out that the answer is not very complex, and according to [1] we have that
where \(\mathcal{L}_\theta\) is the Lagrangian of the MPC optimization problem evaluated at the optimal primal-dual solution \(y^\star\) of the NLP problem.
Examples On-policy Q-learning and Off-policy Q-learning show how Q-learning can be used to tune the parameters of an MPC controller for a linear task both in a on-policy and off-policy fashion.
Deterministic Policy Gradient with MPC#
What if, instead of learning the optimal Q-function from data with the hope to inderectly recover the optimal policy from it, we directly learn the policy that minimizes the returns directly? This is the idea behind policy gradient methods, which attempt to estimate \(\nabla_\theta J(\pi_\theta)\) and use it to update the parametrization. In other words, the update rule is
In particular, [2] shows how to use the Deterministic Policy Gradient (DPG) algorithm. Estimation of the performance gradient is not trivial, but can be achieved as
The gradient of the policy function can be computed as
where \(y\) are all the primal-dual variables, and \(K\) is the KKT system of optimal conditions associated with the MPC optimization problem. The action-value function is instead approximated with the compatible form
with \(\Psi(s,a) = \nabla_\theta \pi_\theta(s) (a - \pi_\theta(s))\) and \(V_{\pi_\theta} \approx V_\nu = \Phi(s)^\top \nu\). \(\Phi(s)\) is a state feature vector. Hence, we get that
The unknown parameters \(\omega\) and \(\nu\) can be computed in a batch way via a least-squares regression problem.
As for Q-learning, example On-policy Deterministic Policy Gradient deploys DPG for a linear task in a on-policy fashion.