Safe Interactive Model-Based Learning (SiMBL) aims to control a deterministic dynamical system:
where x is the state and y are the measurements, in this case assumed equivalent. The system (1) is sampled with a known constant time dt and it is subject to closed and bounded, possibly non-convex, operational constraints on the state and input:
The stability of (1) is studied using discrete time systems analysis. In particular, tools from discrete-time control Lyapunov functions (Blanchini & Miani, 2007; Khalil, 2014) will be used to compute policies that can keep the system safe.
Safety. In this work, safety is defined as the capability of a system to remain within a subset of the operational constraints and to return asymptotically to the equilibrium state from anywhere in
. A feedback control policy,
, is certified as safe if it can provide safety with high probability. In this work, safety is verified with a statistical method that extends Bobiti (2017).
Safe learning. The proposed framework aims at learning a policy, K(x), and Lyapunov function, V (x), by means of simulated trajectories from an uncertain forward model and an initial policy , used to collect data. The model, the policy, and the Lyapunov function are iteratively refined while safely collecting more data through a Safe Model Predictive Controller (SafeMPC). Figure 1 illustrates the approach.
Summary of contribution. This work presents the algorithms for: 1) Iteratively learning a novel Bayesian RNN model with a large posterior over unseen states and inputs; 2) Learning a safe set and the associated controller with neural networks from the model trajectories; 3) Safe exploration with MPC. For 1) and 2), we propose to re-
tain the model from scratch using a consistency prior to include knowledge of the previous uncertainty and then to recompute the safe set. The safe set increase as more data becomes available and the safety of the exploration strategy are demonstrated on an inverted pendulum simulation with limited control torque and stability region. Their final integration for continuous model and controller refinement with data from safe exploration (see Figure 1) is left for future work.
A discrete-time stochastic forward model of system (1) is formulated as a Bayesian RNN. A grey-box approach is used, where available prior knowledge is integrated into the network in a differentiable way (for instance, the known relation between an observation and its derivative). The model provides an estimate of the next states distribution that is large (up to a defined value) where there is no available data. This is inspired by recent work on Noise Contrastive Priors (NCP) (Hafner et al., 2018b). We extend the NCP approach to RNNs, and propose the Noise Contrastive Prior Bayesian RNN (NCP-BRNN), with full state information, which follows the discrete-time update:
where denote the state and measurement estimated from the model at time t, and
is drawn from the distribution model, where
are computed from neural networks, sharing some initial layers. In particular,
combines an MLP with some physics prior while the final activation of
is a sigmoid which is then scaled by the hyperparameter
, namely, a finite maximum variance. The next state distribution depends on the current state estimate
, the input u, and a set of unknown constant parameters
, which are to be learned from the data. The estimated state
is for simplicity assumed to have the same physical meaning of the true system state x(t). The system state is measured with a Gaussian uncertainty with standard deviation
, which is also learned from data. During the control, the measurement noise is assumed to be negligible (
). Therefore, the control algorithms will need to be robust with respect to the model uncertainty. Extensions to partial state information and output noise robust control are also possible but are left for future work.
Towards reliable uncertainty estimates with RNNs The fundamental assumption for model-based safe learning algorithm is that the model predictions contain the actual system state transitions with high probability (Berkenkamp et al., 2017). This is difficult to meet in practice for most neural network models. To mitigate this risk, we train our Bayesian RNNs on sequences and include a Noise-Contrastive Prior (NCP) term (Hafner et al., 2018b). In the present work, the uncertainty is modelled as a point-wise Gaussian with mean and standard deviation that depend on the current state as well as on the input. The learned 1-step standard deviation, , is assumed to be a diagonal matrix. This assumption is limiting but it is common in variational neural networks for practicality reasons (Zhao et al., 2017; Chen et al., 2016). The NPC concept is illustrated in Figure 2. More complex uncertainty representations will be considered in future works.
The cost function used to train the model is:
where the first term is the expected negative log likelihood over the uncertainty distribution, evaluated over the training data. The second term is the KL-divergence which is evaluated in closed-form over predictions generated from a set of background initial states and input sequences,
and
. These are sampled from a uniform distribution for the first model and then, once a previous model is available and new data is collected, they are obtained using rejection sampling with PyMC (Salvatier et al., 2016) with acceptance condition:
. If a previous model is available, then the final term is used which is an uncertainty consistency prior which forces the uncertainty estimates over the training data to not increase with respect to the previous model. The loss (7) is optimised using stochastic backpropagation through truncated sequences. In order to have further consistency between model updates, it a previous model is available, we train from scratch but stop optimising once the final loss of the previous model is reached.
Figure 2: Variational neural networks with Noise Contrastive Priors (NCP). Predicting sine-wave data (redblack) with confidence bounds (blue area) using NAIS-Net (Ciccone et al., 2018) and NCP (Hafner et al., 2018b).
We approximate a chance-constrained stochastic control problem with a min-max robust control problem over a convex uncertainty set. This non-convex min-max control problem is then also approximated by computing the loss only at the vertices of the uncertainty set. To compensate for this approximation, (inspired by variational inference) the centre of the set is sampled from the uncertainty distribution itself (Figure 3). The procedure is detailed below.
omitted from the notation. The term represents the prior knowledge of the state constraints. In this work we use:
where is the Minkowski functional2 of a user-defined usual region of operation, namely:
Possible choices for the Minkowski functional include quadratic functions, norms or semi-norms (Blanchini & Miani, 2007; Horn & Johnson, 2012). Since V (x) must be positive definite, the hyperparameter is introduced 3. While other forms are possible as in Blanchini & Miani (2007), with (8) the activation function does not need to be invertible. The study of the generality of the proposed function is left for future consideration.
Safe set definition. Denote the candidate safe level set of V as:
where is the safe level. If, for
, the function V (x) satisfies the Lyapunov inequality over the system closed-loop trajectory with a control policy K, namely,
then set is safe, i.e., it satisfies the conditions of positive-invariance (Blanchini & Miani, 2007; Kerrigan, 2000). Note that the policy K(x) can be either a neural network or a model-based controller, for instance a Linear Quadratic Regulator (LQR, see Kalman (2001)) or a Model Predictive Controller (MPC, see Maciejowski (2000); Rawlings & Mayne (2009); Kouvaritakis & Cannon (2015); Rakovi´c & Levine (2019)). A stronger condition to eq. (12) is often used in the context of optimal control:
where is a positive semi-definite stage loss. In this paper, we focus on training policies with the quadratic loss used in LQR and MPC, where the origin is the target equilibrium, namely:
From chance constrained to min-max control Consider the problem of finding a controller K and a function V such that u(t) = K (x (t)) and:
where P represents a probability and . This is a chance-constrained non-convex optimal control problem (Kouvaritakis & Cannon, 2015). We truncate the distributions and approximate (15):
which is deterministic. A strategy to jointly learn (V, K) fulfilling (16) is presented next.
We wish to build a controller K, a function V , and a safe level given the state transition probability model,
, such that the condition in (13) is satisfied with high probability for the physical system generating the data. Denote the one-step prediction from the model in (3), in closed loop with K, as:
where represents the next state prediction and the time index t is omitted.
Approximating the high-confidence prediction set. A polytopic approximation of a high confi-dence region of the estimated uncertain set is obtained from the parameters of
and used for training (V, K). In this work, the uncertain set is taken as a hyper-diamond centered at x, scaled by the (diagonal) standard deviation matrix,
where is a hyper-parameter. This choice of set is inspired by the Unscented Kalman filter (Wan & Van Der Merwe, 2000). Since
is diagonal, the vertices are given by the columns of the matrix resulting from multiplying
with a mask M such that:
Learning the safe set. Assume that a controller K is given. Then, we wish to learn a V of the from of (8), such that the corresponding safe set is as big as possible, ideally as big as the state constraints X. In order to do so, the parameters of
are trained using a grid of initial states, a forward model to simulate the next state under the policy K, and an appropriate cost function. The cost for
and
is inspired by (Richards et al., 2018). It consists of a combination of two objectives: the first one penalises the deviation from the Lyapunov stability condition; the second one is a classification penalty that separates the stable points from the unstable ones by means of the decision boundary,
. The combined robust Lyapunov function cost is:
where trades off stability for volume. The robust Lyapunov decrease in (22) is evaluated by using sampling to account for uncertainty over the confidence interval W. Sampling of the set centre is performed as opposite of setting
, which didn’t seem to produce valid results. Let us omit
for ease of notation. We substitute
, which we define as:
Equations (22) and (23) require a maximisation of the non-convex function V (x) over the convex set W. For the considered case, a sampling technique or another optimisation (similar to adversarial learning) could be used for a better approximation of the max operator. The maximum over W is instead approximated by the maximum over its vertices:
This consists of a simple enumeration followed by a max over tensors that can be easily handled. Finally, during training (23) is implemented in a variational inference fashion by evaluating (24) at each epoch over a different sample of . This entails a variational posterior over the center of the uncertainty interval. The approach is depicted in Figure 3.
The proposed cost is inspired by Richards et al. (2018), with the difference that here there is no need for labelling the states as safe by means of a multi-step simulation. Moreover, in this work we train the Lyapunov function and controller together, while in (Richards et al., 2018) the latter was given.
Learning the safe policy. We alternate the minimisation of the Lyapunov loss (19) and the solution of the variational robust control problem:
Figure 3: Approximating the non-convex maximisation. Centre of the uncertain set is sampled and Lyapunov function is evaluated at its vertices.
subject to the forward model (3). In this work, (25) is solved using backpropagation through the policy, the model and V . The safety constraint, is relaxed through a log-barrier (Boyd & Vandenberghe, 2004). If a neural policy K(x) solves (25) and satisfies the safety constraint,
, then it is a candidate robust controller for keeping the system within the safe set
. Note that the expectation in (26) is once again treated as a variational approximation of the expectation over the center of the uncertainty interval.
Obtaining an exact solution to the control problem for all points is computationally impractical. In order to provide statistical guarantees of safety, probabilistic verification is used after V and K have been trained. This refines the safe level set and, if successful, provides a probabilistic safety certificate. If the verification is unsuccessful, then the learned
are not safe. The data collection continues with the previous safe controller until suitable
are found. Note that the number of training points used for the safe set and controller is in general lower than the ones used for verification. The alternate learning procedure for
and K is summarised in Algorithm 1. The use of 1-step predictions makes the procedure highly scalable through parallelisation on GPU.
Probabilistic safety verification. A probabilistic verification is used to numerically prove the physical system stability with high probability. The resulting certificate is of the form (15), where the decreases with increasing number of samples. Following the work of Bobiti (2017), the simulation is evaluated at a large set of points within the estimated safe set
. Monte Carlo rejection sampling is performed with PyMC (Salvatier et al., 2016).
In practical applications, several factors limit the
convergence of the trajectory to a neighborhood of the target (the ultimate bound, Blanchini & Miani (2007)). For instance, the policy structural bias, discount factors in RL methods or persistent uncertainty in the model, the state estimates, and the physical system itself. Therefore, we extended the verification algorithm of (Bobiti, 2017) to estimate the ultimate bound as well as the invariant set, as outlined in Algorithm 2. Given a maximum and minimum level, , we first sample initial states uniformly within these two levels and check for a robust decrease of V over the next state distribution. If this is verified, then we sample uniformly from inside the minimum level set
decrease) and check that V does not exceed the maximum level
over the next state distribution. The distribution is evaluated by means of uniform samples of w, independent of the current state, within
. These are then scaled using
from the model. We search for
with a step
Verification failed. Note that, in Algorithm 2, the uncertainty of the surrogate model is taken into account by sampling a single uncertainty realisation for the entire set of initial states. The values of w will be then scaled using in the forward model. This step is computationally convenient but breaks the assumption that variables are drawn from a uniform distribution. We leave this to future work. In this paper, independent Gaussian uncertainty models are used and stability is verified directly on the environment. Note that probabilistic verification is expensive but necessary, as pathological cases could result in the training loss (19) for the safe set could converging to a local minima with a very small set. If this is the case then usually the forward model is not accurate enough or the uncertainty hyperparameter
is too large. Note that Algorithm 2 is highly parallelizable.
Once a verified safe set is found the environment can be controlled by means of a 1-step MPC with probabilistic stability (see Appendix). Consider the constraint , where V and
come from Algorithm 1 and
from Algorithm 2. The Safe-MPC exploration strategy follows:
Safe-MPC for exploration. For collecting new data, solve the following MPC problem:
where exploration hyperparameter,
regulation or exploitation parameter and
is the info-gain from the model, similar to (Hafner et al., 2018b):
The full derivation of the problem and a probabilistic safety result are discussed in Appendix.
Alternate min-max optimization. Problem (27) is approximated using alternate descent. In particular, the maximization in the loss function over the uncertain future state with respect to
given the current control candidate u, is alternated with the minimization with respect to u, given the current candidate
. Adam (Kingma & Ba, 2014) is used for both steps.
The approach is demonstrated on an inverted pendulum, where the input is the angular torque and the states/outputs are the angular position and velocity of the pendulum. The aim is to collect data safely around the unstable equilibrium point (the origin). The system has a torque constraint that limits the controllable region. In particular, if the initial angle is greater than 60 degrees, then the torque is not sufficient to swing up the pendulum. In order to compare to the LQR, we choose a linear policy with a tanh activation, meeting the torque constraints while preserving differentiability.
Safe set with known environment, comparison to LQR. We first test the safe-net algorithm on the nominal pendulum model and compare the policy and the safe set with those from a standard LQR policy. Figure 4 shows the safe set at different stages of the algorithm, approaching the LQR.
Figure 4: Inverted Pendulum. Safe set and controller with proposed method for known environment model. Initial set (i = 0) is based on a unit circle plus the constraint . Contours show the function levels. Control gain gets closer to the LQR solution as iterations progress until circa i = 50, where the minimum of the Lyapunov loss (19) is achieved. The set and controller at iteration 50 are closest to the LQR solution, which is optimal around the equilibrium in the unconstrained case. In order to maximise the chances of verification the optimal parameters are selected with a early stopping, namely when the Lyapunov loss reaches its minimum, resulting in
Safe set with Bayesian model. In order to test the proposed algorithms, the forward model is fitted on sequences of length 10 for an increasing amount of data points (10k to 100k). Data is collected in closed loop with the initial controller, , with different initial states. In particular, we perturb the initial state and control values with a random noise with standard deviations starting from, respectively, 0.1 and 0.01 and doubling each 10k points. The only prior used is that the velocity is the derivative of the angular position (normalized to
). The uncertainty bound was fixed to
0.01. The architecture was cross-validated from 60k datapoints with a 70-30 split. The model with the best validation predictions as well as the largest safe set was used to generate the results in Figure 6.
The results demonstrate that the size of the safe set can improve with more data, provided that the model uncertainty decreases and the predictions have comparable accuracy. This motivates for exploration.
Verification on the environment. The candidate Lyapunov function, safe level set, and robust control policy are formally verified through probabilistic sampling of the system state, according to Algorithm 2, where the simulation is used directly. The results for 5k samples are shown in Figure 5. In particular, the computed level sets verify at the first attempt and no further search for sub-levels or ultimate bounds is needed.
Figure 6: Inverted pendulum safe set with Bayesian model. Surrogates are obtained with increasing amount of data. The initial state and input perturbation from the safe policy are drawn from Gaussians with standard deviation that doubles each 10k points. Top: Mean predictions and uncertainty contours for the NCP-BRNN model. After 90k points no further improvement is noticed. Bottom: Comparison of safe sets with surrogates and environment. Reducing the model uncertainty while maintaining a similar prediction accuracy leads to an increase in the safe set. After 90k points no further benefits are noticed on the set which is consistent with the uncertainty estimates.
Safe exploration. Safe exploration is performed using the min-max approach in Section 5. For comparison, a semi-random exploration strategy is also used: if inside the safe set, the action magnitude is set to maximum torque and its sign is given by a random uniform variable once the safe policy K is used. This does not provide any formal guarantees of safety as the value of V (x) could exceed the safe level, especially for very fast systems and large input signals. This is repeated for several trials in order to estimate the maximum reachable set within the safe set. The results are shown in Figure 7, where the semi-random strategy is used as a baseline and is compared to a
single trial of the proposed safe-exploration algorithm. The area covered by our algorithm in a single trial of 50k steps is about 67% of that of the semi-random baseline over 50 trials of 1k steps. Extending the length of the trials did not significantly improve the baseline results. Despite being more conservative, our algorithm continues to explore safely indefinitely.
Preliminary results show that the SiMBL produces a Lyapunov function and a safe set using neural networks that are comparable with that of standard optimal control (LQR) and can account for state-dependant additive model uncertainty. A Bayesian RNN surrogate with NCP was proposed and trained for an inverted pendulum simulation. An alternate descent method was presented to jointly learn a Lyapunov function, a safe level set, and a stabilising control policy for the surrogate model with back-propagation. We demonstrated that adding data-points to the training set can increase the safe-set size provided that the model improves and its uncertainty decreases. To this end, an uncertainty prior from the previous model was added to the framework. The safe set was then formally verified through a novel probabilistic algorithm for ultimate bounds and used for safe data collection (exploration). A one-step safe MPC was proposed where the Lyapunov function provides the terminal cost and constraint to mimic an infinite horizon with high probability of recursive feasibility. Results show that the proposed safe-exploration strategy has better coverage than a naive policy which switches between random inputs and the safe policy.
Akametalu, A. K., Fisac, J. F., Gillula, J. H., Kaynama, S., Zeilinger, M. N., & Tomlin, C. J. (2014). Reachability-based safe learning with gaussian processes. In 53rd IEEE Conference on Decision and Control. IEEE. URL https://doi.org/10.1109/cdc.2014.7039601
Bemporad, A., Borrelli, F., & Morari, M. (2003). Min-max control of constrained uncertain discrete- time linear systems. Automatic Control, IEEE Transactions on, 48, 1600 – 1606.
Ben-Tal, A., Ghaoui, L. E., & Nemirovski, A. (2009). Robust Optimization (Princeton Series in Applied Mathematics). Princeton University Press.
Berkenkamp, F., Turchetta, M., Schoellig, A. P., & Krause, A. (2017). Safe Model-based Reinforce- ment Learning with Stability Guarantees. arXiv:1705.08551 [cs, stat]. ArXiv: 1705.08551. URL http://arxiv.org/abs/1705.08551
Blanchini, F., & Miani, S. (2007). Set-Theoretic Methods in Control (Systems & Control: Foundations & Applications). Birkhäuser.
Bobiti, R., & Lazar, M. (2016). Sampling-based verification of Lyapunov’s inequality for piecewise continuous nonlinear systems. arXiv:1609.00302 [cs]. ArXiv: 1609.00302. URL http://arxiv.org/abs/1609.00302
Bobiti, R. V. (2017). Sampling driven stability domains computation and predictive control of constrained nonlinear systems. Ph.D. thesis. URL https://pure.tue.nl/ws/files/78458403/20171025_Bobiti.pdf
Borrelli, F., Bemporad, A., & Morari, M. (2017). Predictive Control for Linear and Hybrid Systems. Cambridge University Press.
Boyd, S., & Vandenberghe, L. (2004). Convex Optimization. New York, NY, USA: Cambridge University Press.
Camacho, E. F., & Bordons, C. (2007). Model Predictive control. Springer London.
Carron, A., Arcari, E., Wermelinger, M., Hewing, L., Hutter, M., & Zeilinger, M. N. (2019). Data- driven model predictive control for trajectory tracking with a robotic arm. URL http://hdl.handle.net/20.500.11850/363021
Chen, X., Kingma, D. P., Salimans, T., Duan, Y., Dhariwal, P., Schulman, J., Sutskever, I., & Abbeel, P. (2016). Variational Lossy Autoencoder. arXiv:1611.02731 [cs, stat]. ArXiv: 1611.02731. URL http://arxiv.org/abs/1611.02731
Cheng, R., Orosz, G., Murray, R. M., & Burdick, J. W. (2019). End-to-End Safe Reinforcement Learn- ing through Barrier Functions for Safety-Critical Continuous Control Tasks. arXiv:1903.08792 [cs, stat]. ArXiv: 1903.08792. URL http://arxiv.org/abs/1903.08792
Chow, Y., Nachum, O., Duenez-Guzman, E., & Ghavamzadeh, M. (2018). A Lyapunov-based Approach to Safe Reinforcement Learning. arXiv:1805.07708 [cs, stat]. ArXiv: 1805.07708. URL http://arxiv.org/abs/1805.07708
Chow, Y., Nachum, O., Faust, A., Duenez-Guzman, E., & Ghavamzadeh, M. (2019). Lyapunov- based Safe Policy Optimization for Continuous Control. arXiv:1901.10031 [cs, stat]. ArXiv: 1901.10031. URL http://arxiv.org/abs/1901.10031
Chua, K., Calandra, R., McAllister, R., & Levine, S. (2018). Deep Reinforcement Learning in a Handful of Trials using Probabilistic Dynamics Models. arXiv:1805.12114 [cs, stat]. ArXiv: 1805.12114. URL http://arxiv.org/abs/1805.12114
Ciccone, M., Gallieri, M., Masci, J., Osendorfer, C., & Gomez, F. (2018). Nais-net: Stable deep networks from non-autonomous differential equations. In NeurIPS.
Deisenroth, M., & Rasmussen, C. (2011). Pilco: A model-based and data-efficient approach to policy search. In Proceedings of the 28th International Conference on Machine Learning, ICML 2011, (pp. 465–472). Omnipress.
Deisenroth, M. P., Fox, D., & Rasmussen, C. E. (2015). Gaussian Processes for Data-Efficient Learning in Robotics and Control. IEEE Transactions on Pattern Analysis and Machine Intelligence, 37(2), 408–423. ArXiv: 1502.02860. URL http://arxiv.org/abs/1502.02860
Depeweg, S., Hernández-Lobato, J. M., Doshi-Velez, F., & Udluft, S. (2016). Learning and Policy Search in Stochastic Dynamical Systems with Bayesian Neural Networks. arXiv:1605.07127 [cs, stat]. ArXiv: 1605.07127. URL http://arxiv.org/abs/1605.07127
Frigola, R., Chen, Y., & Rasmussen, C. E. (2014). Variational gaussian process state-space models. In NIPS.
Gal, Y., McAllister, R., & Rasmussen, C. E. (2016). Improving PILCO with Bayesian neural network dynamics models. In Data-Efficient Machine Learning workshop, ICML.
Gallieri, M. (2016). Lasso-MPC – Predictive Control with -Regularised Least Squares. Springer International Publishing. URL https://doi.org/10.1007/978-3-319-27963-3
Gros, S., & Zanon, M. (2019). Towards Safe Reinforcement Learning Using NMPC and Policy Gradients: Part II - Deterministic Case. arXiv:1906.04034 [cs]. ArXiv: 1906.04034. URL http://arxiv.org/abs/1906.04034
Hafner, D., Lillicrap, T., Fischer, I., Villegas, R., Ha, D., Lee, H., & Davidson, J. (2018a). Learning Latent Dynamics for Planning from Pixels. arXiv:1811.04551 [cs, stat]. ArXiv: 1811.04551. URL http://arxiv.org/abs/1811.04551
Hafner, D., Tran, D., Irpan, A., Lillicrap, T., & Davidson, J. (2018b). Reliable Uncertainty Estimates in Deep Neural Networks using Noise Contrastive Priors. arXiv:1807.09289 [cs, stat]. ArXiv: 1807.09289. URL http://arxiv.org/abs/1807.09289
Hewing, L., Kabzan, J., & Zeilinger, M. N. (2017). Cautious Model Predictive Control using Gaussian Process Regression. arXiv:1705.10702 [cs, math]. ArXiv: 1705.10702. URL http://arxiv.org/abs/1705.10702
Horn, R. A., & Johnson, C. R. (2012). Matrix Analysis. New York, NY, USA: Cambridge University Press, 2nd ed.
Kalman, R. (2001). Contribution to the theory of optimal control. Bol. Soc. Mat. Mexicana, 5.
Kerrigan, E. (2000). Robust constraint satisfaction: Invariant sets and predictive control. Tech. rep. URL http://hdl.handle.net/10044/1/4346
Kerrigan, E. C., & Maciejowski, J. M. (2004). Feedback min-max model predictive control using a single linear program: robust stability and the explicit solution. International Journal of Robust and Nonlinear Control, 14(4), 395–413. URL https://doi.org/10.1002/rnc.889
Khalil, H. K. (2014). Nonlinear Control. Pearson.
Kingma, D. P., & Ba, J. (2014). Adam: A Method for Stochastic Optimization. arXiv:1412.6980 [cs]. ArXiv: 1412.6980. URL http://arxiv.org/abs/1412.6980
Koller, T., Berkenkamp, F., Turchetta, M., & Krause, A. (2018). Learning-based Model Predictive Control for Safe Exploration and Reinforcement Learning. arXiv:1803.08287 [cs]. ArXiv: 1803.08287. URL http://arxiv.org/abs/1803.08287
Kouvaritakis, B., & Cannon, M. (2015). Model Predictive Control: Classical, Robust and Stochastic. Advanced Textbooks in Control and Signal Processing, Springer, London.
Kurutach, T., Clavera, I., Duan, Y., Tamar, A., & Abbeel, P. (2018). Model-Ensemble Trust-Region Policy Optimization. arXiv:1802.10592 [cs]. ArXiv: 1802.10592. URL http://arxiv.org/abs/1802.10592
Limon, D., Calliess, J., & Maciejowski, J. (2017). Learning-based nonlinear model predictive control. IFAC-PapersOnLine, 50(1), 7769–7776. URL https://doi.org/10.1016/j.ifacol.2017.08.1050
Lorenzen, M., Cannon, M., & Allgower, F. (2019). Robust MPC with recursive model update. Automatica, 103, 467–471. URL https://ora.ox.ac.uk/objects/pubs:965898
Lowrey, K., Rajeswaran, A., Kakade, S., Todorov, E., & Mordatch, I. (2018). Plan Online, Learn Offline: Efficient Learning and Exploration via Model-Based Control. arXiv:1811.01848 [cs, stat]. ArXiv: 1811.01848. URL http://arxiv.org/abs/1811.01848
Maciejowski, J. (2000). Predictive Control with Constraints. Prentice Hall.
Mayne, D. Q., Rawlings, J. B., Rao, C. V., & Scokaert, P. O. M. (2000). Constrained model predictive control: Stability and optimality.
Papini, M., Battistello, A., Restelli, M., & Battistello, A. (2018). Safely exploring policy gradient.
Pozzoli, S. (2019). State Estimation and Recurrent Neural Networks for Model Predictive Control. Politecnico di Milano, MS thesis, supervisors: R. Scattolini, M. Gallieri, E. Terzi, M. Farina.
Pozzoli, S., Gallieri, M., & Scattolini, R. (2019). Tustin neural networks: a class of recurrent nets for adaptive MPC of mechanical systems. arXiv:1911.01310 [cs, eess]. ArXiv: 1911.01310. URL http://arxiv.org/abs/1911.01310
Raimondo, D., Limon, D., Lazar, M., Magni, L., & Camacho, E. (2009). Min-max model predictive control of nonlinear systems: A unifying overview on stability. European Journal of Control, 15.
Rakovi´c, S. V., Kouvaritakis, B., Findeisen, R., & Cannon, M. (2012). Homothetic tube model predictive control. Automatica, 48, 1631–1638.
Rakovi´c, S. V., & Levine, W. S. (Eds.) (2019). Handbook of Model Predictive Control. Springer International Publishing. URL https://doi.org/10.1007/978-3-319-77489-3
Rawlings, J. B., & Mayne, D. Q. (2009). Model Predictive Control Theory and Design. Nob Hill Pub, Llc.
Richards, A. G. (2004). Robust Constrained Model Predictive Control ,. Ph.D. thesis, MIT.
Richards, S. M., Berkenkamp, F., & Krause, A. (2018). The Lyapunov Neural Network: Adaptive Stability Certification for Safe Learning of Dynamical Systems. arXiv:1808.00924 [cs]. ArXiv: 1808.00924. URL http://arxiv.org/abs/1808.00924
Salimans, T., Ho, J., Chen, X., Sidor, S., & Sutskever, I. (2017). Evolution strategies as a scalable alternative to reinforcement learning. arXiv preprint arXiv:1703.03864.
Salvatier, J., Wiecki, T. V., & Fonnesbeck, C. (2016). Probabilistic programming in python using PyMC3. PeerJ Computer Science, 2, e55. URL https://doi.org/10.7717/peerj-cs.55
Shyam, P., Jaskowski, W., & Gomez, F. (2018). Model-based active exploration. CoRR, abs/1810.12162. URL http://arxiv.org/abs/1810.12162
Stanley, K. O., & Miikkulainen, R. (2002). Evolving neural networks through augmenting topologies. Evolutionary computation, 10(2), 99–127.
Taylor, A. J., Dorobantu, V. D., Le, H. M., Yue, Y., & Ames, A. D. (2019). Episodic Learning with Control Lyapunov Functions for Uncertain Robotic Systems. arXiv:1903.01577 [cs]. ArXiv: 1903.01577. URL http://arxiv.org/abs/1903.01577
Thananjeyan, B., Balakrishna, A., Rosolia, U., Li, F., McAllister, R., Gonzalez, J. E., Levine, S., Borrelli, F., & Goldberg, K. (2019). Safety Augmented Value Estimation from Demonstrations (SAVED): Safe Deep Model-Based RL for Sparse Cost Robotic Tasks. arXiv:1905.13402 [cs, stat]. ArXiv: 1905.13402. URL http://arxiv.org/abs/1905.13402
Verdier, C. F., & M. Mazo, J. (2017). Formal Controller Synthesis via Genetic Programming. IFACPapersOnLine, 50(1), 7205–7210. URL https://doi.org/10.1016/j.ifacol.2017.08.1362
Vinogradska, J. (2017). Gaussian Processes in Reinforcement Learning: Stability Analysis and Efficient Value Propagation. URL http://tuprints.ulb.tu-darmstadt.de/7286/1/GPs_in_RL_Stability_ Analysis_and_Efficient_Value_Propagation_Version1.pdf
Wabersich, K. P., Hewing, L., Carron, A., & Zeilinger, M. N. (2019). Probabilistic model predictive safety certification for learning-based control. arXiv:1906.10417 [cs, eess]. ArXiv: 1906.10417. URL http://arxiv.org/abs/1906.10417
Wan, E., & Van Der Merwe, R. (2000). The unscented kalman filter for nonlinear estimation. (pp. 153–158).
Williams, G., Wagener, N., Goldfain, B., Drews, P., Rehg, J. M., Boots, B., & Theodorou, E. A. (2017). Information theoretic MPC for model-based reinforcement learning. In 2017 IEEE International Conference on Robotics and Automation (ICRA). IEEE. URL https://doi.org/10.1109/icra.2017.7989202
Yan, S., Goulart, P., & Cannon, M. (2018). Stochastic Model Predictive Control with Discounted Probabilistic Constraints. ArXiv: 1807.07465. URL http://arxiv.org/abs/1807.07465
Yang, X., & Maciejowski, J. (2015a). Risk-sensitive model predictive control with gaussian process models. IFAC-PapersOnLine, 48(28), 374–379. URL https://doi.org/10.1016/j.ifacol.2015.12.156
Yang, X., & Maciejowski, J. M. (2015b). Fault tolerant control using gaussian processes and model predictive control. International Journal of Applied Mathematics and Computer Science, 25(1), 133–148. URL https://doi.org/10.1515/amcs-2015-0010
Zhao, S., Song, J., & Ermon, S. (2017). InfoVAE: Information Maximizing Variational Autoencoders. arXiv:1706.02262 [cs, stat]. ArXiv: 1706.02262. URL http://arxiv.org/abs/1706.02262
Further detail is provided regarding robust and chance constrained control.
Chance-constrained and robust control. Consider the problem of finding a controller K and a function V such that u(t) = K (x (t)) and:
where is given by the forward model (3), P represents a probability and
. This is a chance-constrained control problem (Kouvaritakis & Cannon, 2015; Yan et al., 2018). Since finding K and V that satisfy (29) requires solving a non-convex and also stochastic optimization, we approximate (29) with a min-max condition over a high-confidence interval, in the form of a convex set
, as follows:
This is a robust control problem, which is still non-convex but deterministic. In the convex case, (30) can be satisfied by means of robust optimization (Ben-Tal et al., 2009; Rawlings & Mayne, 2009). By following this consideration, we frame the control problem as a non-convex min-max optimization.
Links to optimal control and intrinsic robustness. To link our approach with optimal control and reinforcement learning, note that if the condition in (13) is met with equality, then the controller K and the Lyapunov function V satisfy the Bellman equation (Rawlings & Mayne, 2009). Therefore, u = K(x) is optimal and V (x) is the value-function of the infinite horizon optimal control problem with stage loss . In practice, this condition is not met with exact equality. Nevertheless, the inequality in (13) guarantees by definition that the system controlled by K(x) is asymptotically stable (converges to x = 0) and it has a degree of tolerance to uncertainty in the safe set
(i.e. if the system is locally Lipschitz) (Rawlings & Mayne, 2009). Vice versa, infinite horizon optimal control with the considered cost produces a value function which is also a Lyapunov function and provides an intrinsic degree of robustness (Rawlings & Mayne, 2009).
Once a robust Lyapunov function and invariant set are found, the environment can be controlled by means of a one-step MPC with probabilistic safety guarantees.
One-step robust MPC. Start by considering the following min-max 1-step MPC problem:
This is a non-convex min-max optimisation problem with hard non-convex constraints. Solving (31) is difficult, especially in real-time, but is in general possible if the constraints are feasible. This is true with a probability that depends from the verification procedure, the confidence level used in the procedures, as well as the probability of the model being correct.
Relaxed problem. Solutions of (31) can be computed in real-time, to a degree of accuracy, by iterative convexification of the problem and the use of fast convex solvers. This is described in Appendix. For the purpose of this paper, we will consider the soft-constrained or relaxed problem:
once again subject to (3). It is assumed that a scalar, , exists such that the constraint can be enforced. For the sake of simplicity, problem (32) will be addressed using backpropagation, at the price of losing real-time guarantees.
Safe exploration. For collecting new data, we modify the robust MPC problem as follows:
where exploration hyperparameter,
regulation or exploitation parameter and
is the info-gain from the model, similar to (Hafner et al., 2018b):
Probabilistic Safety. We study the feasibility and stability of the proposed scheme, following the framework of Mayne et al. (2000); Rawlings & Mayne (2009). In particular, if the MPC (31) is always feasible, and the terminal cost and terminal set satisfy (15) with probability 1, then the MPC (31) enjoys some intrinsic robustness properties. In other words, we should be able to control the physical system and come back to a neighborhood of the initial equilibrium point for any state in the size of this neighborhood depending on the model accuracy. We assume a perfect solver is used and that the relaxed problems enforce the constraints exactly for a given
For the exploration MPC to be safe, we wish to be able to find a satisfying the terminal constraint:
starting from the stochastic system:
We aim at a probabilistic result. First, recall that we truncate the distribution of, w, to a high confidence level z-score, . Once again, we switch to a set-valued uncertainty representation as it is most convenient and provide a result that depends on the z-score
. Assume known the probability of our model to be able to perform one step predictions, given the model M, such that the real state increments are within the given confidence interval,
, and define it as:
. This probability can be estimated and improved using crossvalidation, for instance by fine-tuning
. It can also be increased with
after the model training. This can however make the control search more challenging. Finally, since we use probabilistic verification, from (15) we have a probability of the terminal set to be invariant for the model with truncated distributions:
, where R is the one-step reachability set operator (Kerrigan, 2000) computed using the model in closed loop with K. Note that this probability is determined by the number of verification samples (Bobiti, 2017). Safety of the next state is determined by:
Theorem 1. Given , the probability of (31-33) to be feasible (safe) at the next time step is:
It must be noticed that, whilst is constant, the size of
will generally decrease for increasing
as well as
. The probability of any state to lead to safety in the next step is given by:
Theorem 2. Given x(t), the probability of (31-33) to be feasible (safe) at the next step is:
where C denotes the one-step robust controllable set for the model (Kerrigan, 2000). The size of the safe set is a key factor for a safe system. This depends also on the architecture of V and K as well as on the stage cost matrices Q and R. A stage cost is not explicitly needed for the proposed approach, however, Q can be beneficial in terms of additional robustness and R serves as a regularisation for K.
Forward Model Recall the NPC-BRNN definition:
Partition the state as , where the former represents the angular position and the latter the velocity. They are normalised, respectively, to a range of
. We consider a
of the form:
where fis a three-layer feed-forward neural network with 64 hidden units and tanh activations in the two hidden layers. The final layer is linear. The first layer of f
is shared with the standard deviation network,
, where it is then followed by one further hidden layer of 64 units before the final sigmoid layer. The parameter
is set to 0.01. The noise standard deviation,
is passed through a softplus layer in order to maintain it positive and was initialised at 0.01 by inverting the softplus. We used 1000 epochs for training, with a learning rate of 1E-4 and an horizon of 10. The sequences where all of 1000 samples, the number of sequences was increased by increments of 10 and the batch size adjusted to have sequences of length 10. The target loss was initilisized as
We point out that this architecture is quite general and has been positively tested on other applications, for instance a double pendulum or a joint-space robot model, with states partitioned accordingly.
Lyapunov function The Lyapunov net consists of three fully-connected hidden layers with 64 units and tanh activations which are then followed by a final linear layer with 200 outputs. These are then reshaped into a matrix, and is evaluated as:
where is a hyperparameter and
is a trainable scaling parameter which is passed through a softplus. The introduction of
noticeably improved results. The prior function
was set to keep
. We used 61 outer epochs for training and 10 inner epochs for the updates of V and K, with a with learning rate 1E-3. We used a uniform grid of 10k initial stastes as a single batch.
Exploration MPC For demonstrative purposes we solved the Safe-MPC using Adam with 3000 epochs for the minimisation step and SGD with 100 epochs for the maximisation step. The outer loop used 3 iterations. The learning rates were set to, respectively, 0.1 and 1E-4. The exploration factor, was set to 100 as well as the soft constraint factor,
. The exploitation factor,
, was set to 1.
Using neural networks present several advantages over other popular inference models: for instance, their scalability to high dimensional and to large amount of data, the ease of including physics-based priors and structure in the architecture and the possibility to learn over long sequences. At the same time, NNs require more data than other methods and no offer no formal guarantees. For the guarantees, we have considered a-posteriori probabilistic verification. For the larger amount of data, we have assumed that an initial controller exists (this is often the case) that can be used to safely collect as much data as we need.
Model refinement. A substantial difficulty was encountered while trying to incrementally improve the results of the neural network with increasing amount data. In particular, as more data is collected, larger or more batches must be used. This implies that either the gradient computation or the number of backward passes performed per epoch is different from the previous model training. Consequentely, if a model is retrained entirely from scratch, then the final loss and the network parameters can be substantially different from the ones obtained in the previous trial. This might result in having a larger uncertainty than before in certain regions of the state space. If this is the case, then stabilising the model can become more difficult and the resulting safe set might be smaller. We have observed this pathology initially and have mitigated it by employing these particular steps: first, we use a sigmoid layer to effectively limit the maximum uncertainty to a known hyperparameter; second, we added a consistency loss that encourages the new model to have uncertainty smaller than the previous one over the (new) training set; third, we used rejection sampling for the background based on the uncertainty of the previous model, so that the NCP does not penalise previously known datapoints; finally, we stop the training loop as soon as the final loss of the previous model is exceeded. These ingredients have proven successful in reducing this pathology and, together with having training data with increasing variance, have provided that the uncertainty and safe set improve up to 90k datapoints. After that, however, adding further datapoints has not improved the size of the safe set which has not reached its maximial possible size. We believe that closing the loop with exploration could improve on this result but are also going to investigate further alternatives.
Noticeably, Gal et al. (2016) remarked that improving their BNN model was not simple. They tried for instance to use a forgetting factor which was not successful and concluded that their best solution was to save only a fixed number of most recent trials. We believe this could not be sufficient for safe learning as the uncertain space needs to be explored. Future work will further address this topic, for instance, by retraining only part of the network, or possibly by exploring combinations of our approach with the ensemble approach used in Shyam et al. (2018). Initial trials of the former seemed encouraging for deterministic models.
Training NNs as robust controllers. In this paper, we have used a neural network policy for the computation of the safe controller. This choice was made fundamentally to compare the results with an LQR, which can successfully solve the example. Training policies with backpropagation is not an easy task in general. For more complex scenarios, we envisage two possible solutions: the first is to use evolutionary strategies (Stanley & Miikkulainen, 2002; Salimans et al., 2017) or other global optimisation methods to train the policy; the second is to use a robust MPC instead of a policy. Initial trials of the former seemed encouraging. The latter would result in a change of Algorithm 1, where the K would be not learned but just evaluated point-wise through an MPC solver. Future work is going to investigate these alternatives.
Robust and Stochastic MPC Robust MPC can be formulated using several methods, for instance: min-max optimisation (Bemporad et al., 2003; Kerrigan & Maciejowski, 2004; Raimondo et al., 2009), tube MPC (Rawlings & Mayne, 2009; Rakovi´c et al., 2012) or constraints restriction (Richards, 2004) provide robust recursive feasibility given a known bounded uncertainty set. In tube MPC as well as in constraints restriction, the nominal cost is optimized while the constraints are restricted according to the uncertainty set estimate. This method can be more conservative but it does not require the maximization step. For non-linear systems, computing the required control invariant sets is generally challenging. Stochastic MPC approaches the control problem in a probabilistic way, either using expected or probabilistic constraints. For a broad review of MPC methods and theory one can refer to Maciejowski (2000); Camacho & Bordons (2007); Rawlings & Mayne (2009); Kouvaritakis & Cannon (2015); Gallieri (2016); Borrelli et al. (2017); Rakovi´c & Levine (2019).
Adaptive MPC Lorenzen et al. (2019) presented an approach based on tube MPC for linear parameter varying systems using set membership estimation. In particular, the constraints and model parameter set estimates are updated in order to guarantee recursive feasibility. Pozzoli et al. (2019) used the Unscented Kalman Filter (UKF) to adapt online the last layer of a novel RNN architecture, the Tustin Net (TN), which was then used to successfully control a double pendulum though MPC. TN is a deterministic RNN which is related to the architecture used in this paper. A comparison of different network architectures, estimation and adaptation heuristics for neural MPC can be found, for instance, in Pozzoli (2019).
Stability certification Bobiti & Lazar (2016) proposed a grid-based deterministic verification method which relies on local Lipschitz bounds of the system dynamics. This approach requires knowledge of the model equations and it was extended to black-box simulations (Bobiti, 2017) using a probabilistic approach. We extend this framework by means of a check for ultimate boundedness and propose to use it with Bayesian models through uncertainty sampling.
MPC for Reinforcement Learning Williams et al. (2017) presented an information-theoretical framework to solve a non-linear MPC in real-time using a neural network model and performed model-based RL on a race car scale-model with non-convex constraints. Gros & Zanon (2019) used policy gradient methods to learn a classic robust MPC for linear systems.
Safe learning Yang & Maciejowski (2015a,b) looked, respectively, at using GPs for risk sensitive and fault-tolerant MPC. Vinogradska (2017) proposed a quadrature method for computing invariant sets, stabilising and unrolling GP models for use in RL. Berkenkamp et al. (2017) used the deterministic verification method of (Bobiti & Lazar, 2016) on GP models and embedded it into an RL framework using approximate dynamic programming. The resulting policy has a high probability of safety. Akametalu et al. (2014) studied the reachable sets of GP models and proposed an iterative procedure to refine the stabilisable (safe) set as more data is collected. Hewing et al. (2017) reviewed uncertainty propagation methods and formulated a chance-constrained MPC for grey-box GP models. The approach was demonstrated on an autonomous racing example with non-linear constraints. Limon et al. (2017) presented an approach to learn a non-linear robust model predictive controller based on worst case bounding functions and Holder constant estimates from a non-parametric method. In particular, they use both the trajectories from an initial offline model for recursive feasibility as well as of an online refined model to compute the optimal loss. Koller et al. (2018) provide high probability guarantees of feasibility for a GP-based MPC with Gaussian kernels. This is done using a closed-form exact Taylor expansion that results in the solution of a generalised eigenvalue problem per each step of the prediction horizon. Cheng et al. (2019) complemented model-free RL methods (TRPO and DDPG) with a GP model based approach using a barrier function safety loss, the GP being refined online. Chow et al. (2018) developed a safe Q-learning variant for constrained Markov decision processes based on a state-action Lyapunov function. The Lyapunov function is shown to be equal to the value function for a safety constraint function, defined over a finite horizon. This is constructed by means of a linear programme. Chow et al. (2019) extended this approach to policy gradient methods for continuous control. Two projection strategies have been proposed to map the policy into the space of functions that satisfy the Lyapunov stability condition. Papini et al. (2018) proposed a policy gradient method for exploration with a statistical guarantee of increase of the value function. Wabersich et al. (2019) formulated a probabilistically safe method to project the action resulting from a model-free RL algorithm into a safe manifold. Their algorithm is based on results from chance constrained tube-MPC and makes use of a linear surrogate model. Thananjeyan et al. (2019) approximated the model uncertainty using an ensemble of recurrent neural networks. Safety was approached by constraining the ensemble to be close to a set of successful demonstrations, for which a non-parametric distribution is trained. Thus, a stochastic constrained MPC is approximated by using a set of the ensemble models trajectories. The model rollouts are entirely independent. Under several assumptions the authors proved the system safety. These assumptions can be rarely met in practise, however, the authors demonstrated that the approach works practically on the control of a manipulator in non-convex constrained spaces with a low ensemble size.
Learning Lyapunov functions Verdier & M. Mazo (2017) used genetic programming to learn a polynomial control Lyapunov function for automatic synthesis of a continuous-time switching controller. Richards et al. (2018) proposed an architecture and a learning method to obtain a Lyapunov neural network from labelled sequences of state-action pairs. Our Lyapunov loss function is inspired by Richards et al. (2018) but does not make use of labels nor of sequences longer than one step. These approaches were all demonstrated on an inverted pendulum simulation. Taylor et al. (2019) developed an episodic learning method to iteratively refine the derivative of a continuous-time Lyapunov function and improve an existing controller solving a QP. Their approach exploits a factorisation of the Lyapunov function derivatives based on feedback linearisation of robotic system models. They test the approach on a segway simulation.
Planning and value functions POLO (Lowrey et al., 2018) consists of a combination of online planning (MPC) and offline value function learning. The value function is then used as the terminal cost for the MPC, mimicking an infinite horizon. The result is that, as the value function estimation improves, one can, in theory, shorten the planning horizon and have a near-optimal solution. The authors demonstrated the approach using exact simulation models. This work is related to SiMBL, with the difference that our terminal cost is a Lyapunov function that can be used to certify safety.
Uncertain models for RL PILCO (Deisenroth & Rasmussen, 2011; Deisenroth et al., 2015) used of GP models for model-based RL in an MPC framework that trades-off exploration and exploitation. Frigola et al. (2014) formulated a variational GP state-space model for time series. Gal et al. (2016) showed that variational NNs with dropout can significantly outperform GP models, when used within PILCO, both in terms of performance as well as computation and scalability. Chua et al. (2018) proposed the use of ensemble RNN models and an MPC-like strategy to distinguish between noise and model uncertainty. They plan over a finite horizon with each model and optimise the action using a cross-entropy method. Kurutach et al. (2018) used a similar forward model for trust-region policy optimisation and showed significant improvement in sample efficiency with respect to both single model (no uncertainty) as well as model-free methods. MAX (Shyam et al., 2018) used a similar ensemble of RNN models for efficient exploration, significantly outperforming baselines in terms of sample efficiency on a set of discrete and continuous control tasks. Depeweg et al. (2016) trained a Bayesian neural network using the -divergence and demonstrated that this can outperform both variational networks, MLP and GP models when used for stochastic policy search over a gas turbine example with partial observability and bi-modal distributions. Hafner et al. (2018a) proposed to use an RNN with both deterministic and stochastic transition components together with a multi-step variational inference objective. Their framework predicts rewards directly from pixels. This differs from our approach as we don’t have deterministic states and consider only full state information. Carron et al. (2019) tested the use of a nested control scheme based on an internal feedback linearisation and an external chance-constrained offset free MPC. The MPC is based on nominal linear models and uses both a sparse GP disturbance model as well as a piece-wise constant offset which is estimted online via the Extended Kalman Fitler (EKF). The GP uncertainty is propagated through a first order Taylor expansion. The approach was tested on a robotic arm.
The authors are grateful to Christian Osendorfer, Boyan Beronov, Simone Pozzoli, Giorgio Giannone, Vojtech Micka, Sebastian East, David Alvarez, Timon Wili, Pierluca D’Oro, Wojciech Ja´skowski, Pranav Shyam, Mark Cannon and Andrea Carron for constructive discussions. We are also grateful to Felix Berkenkamp for the support given while experimenting with their safe learning tools. All of the code used for this paper was implemented from scratch by the authors using PyTorch. Finally, we thank everyone at NNAISENSE for contributing to a successful and inspiring R&D environment.